summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvery Pennarun <apenwarr@gmail.com>2010-10-01 14:23:27 -0700
committerAvery Pennarun <apenwarr@gmail.com>2010-10-01 14:38:08 -0700
commitc403a83ab83c36df6938d3b4cb883999b49f5eec (patch)
tree1e8080934b6e1011f983a5caf07c5f6b4d87cbf2
parentda774f3f460e1e3ef27a1ffbbf34c33d70c6659d (diff)
Don't use set() since it's not in python 2.3.
Just use a plain list instead. Technically probably slightly worse asymptotic behaviour, but it's not like we'll have a million sockets anyway.
-rw-r--r--client.py10
-rw-r--r--helpers.py7
-rw-r--r--server.py10
-rw-r--r--ssnet.py28
4 files changed, 34 insertions, 21 deletions
diff --git a/client.py b/client.py
index 5a0500d..0a4b2e5 100644
--- a/client.py
+++ b/client.py
@@ -176,9 +176,9 @@ def _main(listener, fw, use_server, remotename, python, seed_hosts, auto_nets):
if rv:
raise Fatal('server died with error code %d' % rv)
- r = set()
- w = set()
- x = set()
+ r = []
+ w = []
+ x = []
handlers = filter(lambda s: s.ok, handlers)
for s in handlers:
s.pre_select(r,w,x)
@@ -186,9 +186,9 @@ def _main(listener, fw, use_server, remotename, python, seed_hosts, auto_nets):
% (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 = set(r) | set(w) | set(x)
+ ready = r+w+x
for s in handlers:
- if s.socks & ready:
+ if list_contains_any(s.socks, ready):
s.callback()
if use_server:
mux.callback()
diff --git a/helpers.py b/helpers.py
index 8793417..18871a2 100644
--- a/helpers.py
+++ b/helpers.py
@@ -28,3 +28,10 @@ def debug3(s):
class Fatal(Exception):
pass
+
+
+def list_contains_any(l, sub):
+ for i in sub:
+ if i in l:
+ return True
+ return False
diff --git a/server.py b/server.py
index f285e2c..ad2d21d 100644
--- a/server.py
+++ b/server.py
@@ -158,9 +158,9 @@ def main():
if rpid:
raise Fatal('hostwatch exited unexpectedly: code 0x%04x\n' % rv)
- r = set()
- w = set()
- x = set()
+ r = []
+ w = []
+ x = []
handlers = filter(lambda s: s.ok, handlers)
for s in handlers:
s.pre_select(r,w,x)
@@ -169,10 +169,10 @@ def main():
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 = set(r) | set(w) | set(x)
+ ready = r+w+x
for s in handlers:
#debug2('check: %r: %r\n' % (s, s.socks & ready))
- if s.socks & ready:
+ if list_contains_any(s.socks, ready):
s.callback()
mux.check_fullness()
mux.callback()
diff --git a/ssnet.py b/ssnet.py
index 932fab4..7aebe25 100644
--- a/ssnet.py
+++ b/ssnet.py
@@ -31,6 +31,11 @@ cmd_to_name = {
+def _add(l, elem):
+ if not elem in l:
+ l.append(elem)
+
+
def _nb_clean(func, *args):
try:
return func(*args)
@@ -167,12 +172,13 @@ class SockWrapper:
class Handler:
def __init__(self, socks = None, callback = None):
self.ok = True
- self.socks = set(socks or [])
+ self.socks = socks or []
if callback:
self.callback = callback
def pre_select(self, r, w, x):
- r |= self.socks
+ for i in self.socks:
+ _add(r, i)
def callback(self):
log('--no callback defined-- %r\n' % self)
@@ -181,7 +187,7 @@ class Handler:
v = s.recv(4096)
if not v:
log('--closed-- %r\n' % self)
- self.socks = set()
+ self.socks = []
self.ok = False
@@ -194,20 +200,20 @@ class Proxy(Handler):
def pre_select(self, r, w, x):
if self.wrap1.connect_to:
- w.add(self.wrap1.rsock)
+ _add(w, self.wrap1.rsock)
elif self.wrap1.buf:
if not self.wrap2.too_full():
- w.add(self.wrap2.wsock)
+ _add(w, self.wrap2.wsock)
elif not self.wrap1.shut_read:
- r.add(self.wrap1.rsock)
+ _add(r, self.wrap1.rsock)
if self.wrap2.connect_to:
- w.add(self.wrap2.rsock)
+ _add(w, self.wrap2.rsock)
elif self.wrap2.buf:
if not self.wrap1.too_full():
- w.add(self.wrap1.wsock)
+ _add(w, self.wrap1.wsock)
elif not self.wrap2.shut_read:
- r.add(self.wrap2.rsock)
+ _add(r, self.wrap2.rsock)
def callback(self):
self.wrap1.try_connect()
@@ -349,9 +355,9 @@ class Mux(Handler):
break
def pre_select(self, r, w, x):
- r.add(self.rsock)
+ _add(r, self.rsock)
if self.outbuf:
- w.add(self.wsock)
+ _add(w, self.wsock)
def callback(self):
(r,w,x) = select.select([self.rsock], [self.wsock], [], 0)