aboutsummaryrefslogtreecommitdiff
path: root/inputs
diff options
context:
space:
mode:
authorGravatar rcoh <rcoh@mit.edu>2011-01-28 16:24:21 -0500
committerGravatar rcoh <rcoh@mit.edu>2011-01-28 16:24:21 -0500
commitbd1119e82ff9f4bd8835ed6d3934f156a6da8b23 (patch)
treec97435c4e2ccf74610ba3875e277ca9f7cdea6d8 /inputs
parentef1abfa913498e02a4ece3be4be45d2f03e47d05 (diff)
Fixed TCPInput bug.
Diffstat (limited to 'inputs')
-rw-r--r--inputs/TCPInput.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/inputs/TCPInput.py b/inputs/TCPInput.py
index 17ea7e6..51a6677 100644
--- a/inputs/TCPInput.py
+++ b/inputs/TCPInput.py
@@ -4,6 +4,7 @@ from operationscore.Input import *
import socket, json, time
import logging as main_log
import string
+from select import select
class TCPInput(Input):
"""TCPInput is a input to receive input on a TCP port. In its current incarnation, it parses
@@ -20,9 +21,20 @@ class TCPInput(Input):
self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.sock.bind((self.HOST, self.PORT))
self.sock.listen(1)
- (self.conn, self.address) = self.sock.accept()
+
+ isreadable=select([self.sock],[],[], 0)[0]
+ self.conn = None
+ if isreadable:
+ (self.conn, self.address) = self.sock.accept()
def sensingLoop(self):
+ if self.conn == None:
+ isreadable=select([self.sock],[],[], 0)[0]
+ if isreadable:
+ (self.conn, self.address) = self.sock.accept()
+ else:
+ return
+
data = self.conn.recv(self.BUFFER_SIZE)
main_log.debug('Incoming data', data)