jab committed c3776ac

close socket on disconnect

Comments (0)

Files changed (1)

 from eventlet import sleep, spawn, spawn_n
 from import socket
 from functools import partial, wraps
+from itertools import chain
 from simplejson import dumps, loads
 import random
 import string
 pstartpos = _generate_startpos()
 transforms = ('translateL', 'translateR', 'translateD', 'rotateCW', 'rotateCCW')
-moves = transforms + ('drop',)
+moves = frozenset(chain(transforms, ('drop',)))
 def translateL(pairs):
     return tuple((r, c-1) for (r, c) in pairs)
             return cls(loads(serialized))
         return cls()
-class AbstractConn:
+class BaseConn:
     def send(self, msg):
         self.writer.write(msg.serialize() + '\n')
         msg = self.reader.readline()
         return Message.froms(msg)
-class ClientConn(AbstractConn):
+class ClientConn(BaseConn):
     def __init__(self, clientid, server, connection):
         self.clientid = clientid
         self.server = server
         self.writer = connection.makefile('w')
     def recv(self):
-        msg = AbstractConn.recv(self)
+        msg = BaseConn.recv(self)
         msg['clientid'] = self.clientid
         return msg
         if clientid in self.ccons:
-class ServerConn(AbstractConn):
+class ServerConn(BaseConn):
     def __init__(self, client):
         self.client = client
         self.socket = socket.socket()
     def send_disconnect(self):
         msg = Message(event=e_disconnected)
+        self.socket.close() # TODO provide a way to connect to a new server XXX
+        self.socket = self.reader = self.writer = None
     def send_pause(self):
         msg = Message(event=e_pausetoggled)
         handler.func_name = event
         return handler
-    for name in moves + (e_nextp, e_tick):
+    for name in chain(moves, (e_nextp, e_tick)):
         locals()[name] = _handler_factory(name)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.