Asyncore connect handling
- minor improvements in handling of connect events so that it's not processed twice
This commit is contained in:
parent
a9c0000c17
commit
e8d9a7f183
|
@ -1,3 +1,4 @@
|
||||||
|
import socket
|
||||||
import Queue
|
import Queue
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
@ -99,6 +100,13 @@ class AdvancedDispatcher(asyncore.dispatcher):
|
||||||
self.sentBytes += written
|
self.sentBytes += written
|
||||||
self.slice_write_buf(written)
|
self.slice_write_buf(written)
|
||||||
|
|
||||||
|
def handle_connect_event(self):
|
||||||
|
try:
|
||||||
|
asyncore.dispatcher.handle_connect_event(self)
|
||||||
|
except socket.error as e:
|
||||||
|
if e.args[0] not in asyncore._DISCONNECTED:
|
||||||
|
raise
|
||||||
|
|
||||||
def handle_connect(self):
|
def handle_connect(self):
|
||||||
self.lastTx = time.time()
|
self.lastTx = time.time()
|
||||||
self.process()
|
self.process()
|
||||||
|
|
|
@ -57,7 +57,7 @@ import warnings
|
||||||
import os
|
import os
|
||||||
from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, EINVAL, \
|
from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, EINVAL, \
|
||||||
ENOTCONN, ESHUTDOWN, EISCONN, EBADF, ECONNABORTED, EPIPE, EAGAIN, \
|
ENOTCONN, ESHUTDOWN, EISCONN, EBADF, ECONNABORTED, EPIPE, EAGAIN, \
|
||||||
ECONNREFUSED, EHOSTUNREACH, ENOTSOCK, \
|
ECONNREFUSED, EHOSTUNREACH, ENETUNREACH, ENOTSOCK, \
|
||||||
errorcode
|
errorcode
|
||||||
try:
|
try:
|
||||||
from errno import WSAEWOULDBLOCK
|
from errno import WSAEWOULDBLOCK
|
||||||
|
@ -71,7 +71,7 @@ except (ImportError, AttributeError):
|
||||||
from ssl import SSLError, SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE
|
from ssl import SSLError, SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE
|
||||||
|
|
||||||
_DISCONNECTED = frozenset((ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE,
|
_DISCONNECTED = frozenset((ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE,
|
||||||
EBADF, ECONNREFUSED, EHOSTUNREACH))
|
EBADF, ECONNREFUSED, EHOSTUNREACH, ENETUNREACH))
|
||||||
|
|
||||||
OP_READ = 1
|
OP_READ = 1
|
||||||
OP_WRITE = 2
|
OP_WRITE = 2
|
||||||
|
|
|
@ -147,9 +147,9 @@ class TCPConnection(BMProto, TLSDispatcher):
|
||||||
def sendBigInv(self):
|
def sendBigInv(self):
|
||||||
self.receiveQueue.put(("biginv", None))
|
self.receiveQueue.put(("biginv", None))
|
||||||
|
|
||||||
def handle_connect_event(self):
|
def handle_connect(self):
|
||||||
try:
|
try:
|
||||||
AdvancedDispatcher.handle_connect_event(self)
|
AdvancedDispatcher.handle_connect(self)
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
if e.errno in asyncore._DISCONNECTED:
|
if e.errno in asyncore._DISCONNECTED:
|
||||||
logger.debug("%s:%i: Connection failed: %s" % (self.destination.host, self.destination.port, str(e)))
|
logger.debug("%s:%i: Connection failed: %s" % (self.destination.host, self.destination.port, str(e)))
|
||||||
|
|
Reference in New Issue
Block a user