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

@ -162,21 +162,6 @@ def main():
if rpid:
raise Fatal('hostwatch exited unexpectedly: code 0x%04x\n' % 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] (fullness=%d/%d)...\n'
% (len(handlers), len(r), len(w), len(x),
mux.fullness, mux.too_full))
(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:
#debug2('check: %r: %r\n' % (s, s.socks & ready))
if list_contains_any(s.socks, ready):
s.callback()
ssnet.runonce(handlers, mux)
mux.check_fullness()
mux.callback()