Skip to content

Commit

Permalink
Add TCP_INFO availability check
Browse files Browse the repository at this point in the history
  • Loading branch information
otamachan committed Dec 22, 2017
1 parent bc33f0c commit 9c2365d
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions tools/rosmaster/src/rosmaster/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,18 @@ def xmlrpcapi(uri):


def close_half_closed_sockets():
for proxy in _proxies.values():
transport = proxy("transport")
if transport._connection and transport._connection[1] is not None and transport._connection[1].sock is not None:
try:
state = transport._connection[1].sock.getsockopt(socket.SOL_TCP, socket.TCP_INFO)
except socket.error as e: # catch [Errno 92] Protocol not available
if e.args[0] is errno.ENOPROTOOPT:
return
raise
if state == 8: # CLOSE_WAIT
transport.close()
if hasattr(socket, 'TCP_INFO'):
for proxy in _proxies.values():
transport = proxy("transport")
if transport._connection and transport._connection[1] is not None and transport._connection[1].sock is not None:
try:
state = transport._connection[1].sock.getsockopt(socket.SOL_TCP, socket.TCP_INFO)
except socket.error as e: # catch [Errno 92] Protocol not available
if e.args[0] is errno.ENOPROTOOPT:
return
raise
if state == 8: # CLOSE_WAIT
transport.close()


def remove_server_proxy(uri):
Expand Down

0 comments on commit 9c2365d

Please sign in to comment.