import time
import Queue as queue
-from processor import Session, Dispatcher
+from processor import Session, Dispatcher, timestr
class TcpSession(Session):
def __init__(self, connection, address):
- self._connection = connection
- self.address = address
Session.__init__(self)
- print "New session", address
+ self._connection = connection
+ self.address = address[0]
+ self.name = "TCP session"
def connection(self):
if self.stopped():
def stop(self):
self._connection.close()
- print "Terminating connection:", self.address[0]
+ #print "Terminating connection:", self.address
with self.lock:
self._stopped = True
def send_response(self, response):
- raw_response = json.dumps(response)
+ data = json.dumps(response) + "\n"
# Possible race condition here by having session
# close connection?
# I assume Python connections are thread safe interfaces
try:
connection = self.connection()
- connection.send(raw_response + "\n")
+ while data:
+ l = connection.send(data)
+ data = data[l:]
except:
self.stop()
def receive(self):
try:
- return self.session.connection().recv(1024)
+ return self.session.connection().recv(2048)
except:
return ''
sock.listen(1)
while not self.shared.stopped():
session = TcpSession(*sock.accept())
- client_req = TcpClientRequestor(self.dispatcher, session)
- client_req.start()
self.dispatcher.add_session(session)
self.dispatcher.collect_garbage()
-
-
-
+ client_req = TcpClientRequestor(self.dispatcher, session)
+ client_req.start()