Permalink
Browse files

use hostnames and ports in warnings

instead of just file descriptor numbers. the address is stored on connect attempt, so even if the connect was unsuccessful we'll have the address of the attempted remote. compatible with at least AF_INET and AF_INET6
  • Loading branch information...
cpiro committed Jul 13, 2012
1 parent b5288cf commit 311a6540d7857dad0ed4041af1bc34226530a16d
Showing with 13 additions and 10 deletions.
  1. +13 −10 tornado/iostream.py
View
23 tornado/iostream.py 100644 → 100755
@@ -89,6 +89,7 @@ def __init__(self, socket, io_loop=None, max_buffer_size=104857600,
self.max_buffer_size = max_buffer_size
self.read_chunk_size = read_chunk_size
self.error = None
+ self.address = (None, 0)
self._read_buffer = collections.deque()
self._write_buffer = collections.deque()
self._read_buffer_size = 0
@@ -123,6 +124,7 @@ def connect(self, address, callback=None):
"""
self._connecting = True
try:
+ self.address = address
self.socket.connect(address)
except socket.error, e:
# In non-blocking mode we expect connect() to raise an
@@ -133,7 +135,8 @@ def connect(self, address, callback=None):
# localhost, so handle them the same way as an error
# reported later in _handle_connect.
if e.args[0] not in (errno.EINPROGRESS, errno.EWOULDBLOCK):
- logging.warning("Connect error on fd %d: %s",
+ logging.warning("Connect error to %s:%d (fd %d): %s",
+ self.address[0], self.address[1],
self.socket.fileno(), e)
self.close()
return
@@ -421,7 +424,8 @@ def _read_to_buffer(self):
chunk = self._read_from_socket()
except socket.error, e:
# ssl.SSLError is a subclass of socket.error
- logging.warning("Read error on %d: %s",
+ logging.warning("Read error to %s:%d (fd %d): %s",
+ self.address[0], self.address[1],
self.socket.fileno(), e)
self.close()
raise
@@ -503,7 +507,8 @@ def _handle_connect(self):
# an error state before the socket becomes writable, so
# in that case a connection failure would be handled by the
# error path in _handle_events instead of here.
- logging.warning("Connect error on fd %d: %s",
+ logging.warning("Connect error to %s:%d (fd %d): %s",
+ self.address[0], self.address[1],
self.socket.fileno(), errno.errorcode[err])
self.close()
return
@@ -543,7 +548,8 @@ def _handle_write(self):
self._write_buffer_frozen = True
break
else:
- logging.warning("Write error on %d: %s",
+ logging.warning("Write error to %s:%d (fd %d): %s",
+ self.address[0], self.address[1],
self.socket.fileno(), e)
self.close()
return
@@ -650,12 +656,9 @@ def _do_ssl_handshake(self):
ssl.SSL_ERROR_ZERO_RETURN):
return self.close()
elif err.args[0] == ssl.SSL_ERROR_SSL:
- try:
- peer = self.socket.getpeername()
- except:
- peer = '(not connected)'
- logging.warning("SSL Error on %d %s: %s",
- self.socket.fileno(), peer, err)
+ logging.warning("SSL Error to %s:%d (fd %d): %s",
+ self.address[0], self.address[1],
+ self.socket.fileno(), err)
return self.close()
raise
except socket.error, err:

0 comments on commit 311a654

Please sign in to comment.