Because Ryu is based on Eventlet, GreenSocket is used by default and blocking flags is disabled. So MSG_WAITALL flag is not available.
This patch removes MSG_WAITALL flag, and fixes snortlib.py to check received buffer size in _recv_loop_nw_sock(). Signed-off-by: IWASE Yusuke <[email protected]> --- ryu/lib/snortlib.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/ryu/lib/snortlib.py b/ryu/lib/snortlib.py index 9cdabb6..f8f7e14 100644 --- a/ryu/lib/snortlib.py +++ b/ryu/lib/snortlib.py @@ -92,26 +92,21 @@ class SnortLib(app_manager.RyuApp): hub.spawn(self._recv_loop_nw_sock, conn, addr) def _recv_loop_nw_sock(self, conn, addr): - data = str() + buf = str() while True: - data += conn.recv(BUFSIZE, hub.socket.MSG_WAITALL) - - if len(data) == 0: + ret = conn.recv(BUFSIZE) + if len(ret) == 0: self.logger.info("Disconnected from %s", addr[0]) break - elif len(data) == BUFSIZE: + + buf += ret + while len(buf) >= BUFSIZE: + #self.logger.debug("Received buffer size: %d", len(buf)) + data = buf[:BUFSIZE] msg = alert.AlertPkt.parser(data) if msg: self.send_event_to_observers(EventAlert(msg)) - elif len(data) > BUFSIZE: - self.logger.debug("Over BUFSIZE data received: %d (>%d)", - len(data), BUFSIZE) - elif len(data) < BUFSIZE: - self.logger.debug("Short BUFSIZE data received: %d (<%d)", - len(data), BUFSIZE) - continue - - data = str() + buf = buf[BUFSIZE:] def _set_logger(self): """change log format.""" -- 1.9.1 ------------------------------------------------------------------------------ Dive into the World of Parallel Programming The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
