Factor out common mainloop code between client and server.

Also improve the socket message output a bit.
This commit is contained in:
Avery Pennarun
2010-10-01 17:36:09 -07:00
parent b0f061e204
commit 84376284db
3 changed files with 34 additions and 30 deletions

View File

@ -4,6 +4,7 @@ import helpers, ssnet, ssh
from ssnet import SockWrapper, Handler, Proxy, Mux, MuxWrapper
from helpers import *
def original_dst(sock):
try:
SO_ORIGINAL_DST = 80
@ -176,20 +177,7 @@ def _main(listener, fw, use_server, remotename, python, seed_hosts, auto_nets):
if rv:
raise Fatal('server died with error code %d' % rv)
r = []
w = []
x = []
handlers = filter(lambda s: s.ok, handlers)
for s in handlers:
s.pre_select(r,w,x)
debug2('Waiting: %d[%d,%d,%d]...\n'
% (len(handlers), len(r), len(w), len(x)))
(r,w,x) = select.select(r,w,x)
#log('r=%r w=%r x=%r\n' % (r,w,x))
ready = r+w+x
for s in handlers:
if list_contains_any(s.socks, ready):
s.callback()
ssnet.runonce(handlers, mux)
if use_server:
mux.callback()
mux.check_fullness()