Removed debug prints

This commit is contained in:
slush 2012-12-09 13:53:09 +00:00
parent f16ade99e0
commit 89f0ca3f7e
2 changed files with 12 additions and 12 deletions

View File

@ -31,7 +31,14 @@ class Transport(object):
self._write("##%s%s" % (header, ser)) self._write("##%s%s" % (header, ser))
def read(self): def read(self):
(msg_type, data) = self._read() if not self.ready_to_read():
return None
data = self._read()
if data == None:
return None
(msg_type, data) = data
inst = mapping.get_class(msg_type)() inst = mapping.get_class(msg_type)()
inst.ParseFromString(data) inst.ParseFromString(data)
return inst return inst

View File

@ -25,7 +25,6 @@ class SocketTransportClient(Transport):
super(SocketTransportClient, self).__init__(device, *args, **kwargs) super(SocketTransportClient, self).__init__(device, *args, **kwargs)
def _open(self): def _open(self):
print self.device
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.connect(self.device) self.socket.connect(self.device)
self.filelike = self.socket.makefile() self.filelike = self.socket.makefile()
@ -44,7 +43,6 @@ class SocketTransportClient(Transport):
def _read(self): def _read(self):
try: try:
print 'filelike', self.filelike
(msg_type, datalen) = self._read_headers(self.filelike) (msg_type, datalen) = self._read_headers(self.filelike)
return (msg_type, self.filelike.read(datalen)) return (msg_type, self.filelike.read(datalen))
except socket.error: except socket.error:
@ -66,14 +64,12 @@ class SocketTransport(Transport):
super(SocketTransport, self).__init__(device, *args, **kwargs) super(SocketTransport, self).__init__(device, *args, **kwargs)
def _open(self): def _open(self):
print self.device
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
#self.socket.setblocking(0) #self.socket.setblocking(0)
self.socket.bind(self.device) self.socket.bind(self.device)
self.socket.listen(1) self.socket.listen(5)
def _disconnect_client(self): def _disconnect_client(self):
if self.client != None: if self.client != None:
@ -94,8 +90,8 @@ class SocketTransport(Transport):
# Waiting for connection # Waiting for connection
rlist, _, _ = select([self.socket], [], [], 0) rlist, _, _ = select([self.socket], [], [], 0)
if len(rlist) > 0: if len(rlist) > 0:
(self.client, _) = self.socket.accept() (self.client, ipaddr) = self.socket.accept()
print "Connected", self.client print "Connected", ipaddr[0]
self.filelike = self.client.makefile()#FakeRead(self.client)#self.client.makefile() self.filelike = self.client.makefile()#FakeRead(self.client)#self.client.makefile()
return self.ready_to_read() return self.ready_to_read()
return False return False
@ -109,11 +105,8 @@ class SocketTransport(Transport):
def _read(self): def _read(self):
try: try:
print 'filelike', self.filelike
(msg_type, datalen) = self._read_headers(self.filelike) (msg_type, datalen) = self._read_headers(self.filelike)
x = (msg_type, self.filelike.read(datalen)) return (msg_type, self.filelike.read(datalen))
print x
return x
except socket.error: except socket.error:
print "Failed to read from device" print "Failed to read from device"
raise raise