From 5a6228e9790da915d59312f75fd28e72c9f0c4a3 Mon Sep 17 00:00:00 2001 From: Mike Purvis Date: Tue, 31 Jan 2017 14:39:10 -0500 Subject: [PATCH] In write_header() use poll if available. (#929) --- clients/rospy/src/rospy/impl/tcpros_base.py | 22 +++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/clients/rospy/src/rospy/impl/tcpros_base.py b/clients/rospy/src/rospy/impl/tcpros_base.py index 134af0a1b0..7cb08686f1 100644 --- a/clients/rospy/src/rospy/impl/tcpros_base.py +++ b/clients/rospy/src/rospy/impl/tcpros_base.py @@ -613,11 +613,29 @@ def write_header(self): return fileno = sock.fileno() ready = None - while not ready: - _, ready, _ = select.select([], [fileno], []) + poller = None + if hasattr(select, 'poll'): + poller = select.poll() + poller.register(fileno, select.POLLOUT) + while not ready: + events = poller.poll() + for _, flag in events: + if flag & select.POLLOUT: + ready = True + else: + while not ready: + try: + _, ready, _ = select.select([], [fileno], []) + except ValueError as e: + logger.error("[%s]: select fileno '%s': %s", self.name, str(fileno), str(e)) + raise + logger.debug("[%s]: writing header", self.name) sock.setblocking(1) self.stat_bytes += write_ros_handshake_header(sock, protocol.get_header_fields()) + if poller: + poller.unregister(fileno) + def read_header(self): """