Skip to content
This repository has been archived by the owner on Aug 18, 2018. It is now read-only.

Commit

Permalink
Simplify isconnected()
Browse files Browse the repository at this point in the history
  • Loading branch information
bassosimone committed Jan 21, 2016
1 parent 71fa500 commit 7d00c3f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions neubot_runtime/utils_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,28 +173,28 @@ def isconnected(endpoint, sock):

logging.debug('are we connected to %s?', format_epnt(endpoint))

exception, peername = None, None
exception = None
try:
peername = getpeername(sock)
sock.getpeername()
except socket.error as err:
exception = err

if not exception:
logging.debug('yes, we are connected')
return peername
return True

# MacOSX getpeername() fails with EINVAL
if exception.args[0] not in (errno.ENOTCONN, errno.EINVAL):
logging.error('connect failed (reason: %s)',
str(exception.args[0]))
return None
return False

try:
sock.recv(1024)
except socket.error as err:
logging.error('connect failed (reason: %s)',
str(err.args[1]))
return None
return False

raise RuntimeError('isconnected(): internal error')

Expand Down

0 comments on commit 7d00c3f

Please sign in to comment.