Skip to content

Commit

Permalink
In write_header() use poll if available. (#929)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepurvis committed Feb 7, 2017
1 parent d546d4d commit b075cf2
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions clients/rospy/src/rospy/impl/tcpros_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit b075cf2

Please sign in to comment.