Asyncore update
- better error handling - bug fixes - remove some debug output
This commit is contained in:
parent
bafdd6a93a
commit
fa56ab3e6f
|
@ -57,6 +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, \
|
||||||
errorcode
|
errorcode
|
||||||
try:
|
try:
|
||||||
from errno import WSAEWOULDBLOCK
|
from errno import WSAEWOULDBLOCK
|
||||||
|
@ -65,7 +66,7 @@ except:
|
||||||
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))
|
EBADF, ECONNREFUSED))
|
||||||
|
|
||||||
OP_READ = 1
|
OP_READ = 1
|
||||||
OP_WRITE = 2
|
OP_WRITE = 2
|
||||||
|
@ -530,7 +531,7 @@ class dispatcher:
|
||||||
except TypeError:
|
except TypeError:
|
||||||
return None
|
return None
|
||||||
except socket.error as why:
|
except socket.error as why:
|
||||||
if why.args[0] in (EWOULDBLOCK, ECONNABORTED, EAGAIN):
|
if why.args[0] in (EWOULDBLOCK, ECONNABORTED, EAGAIN, ENOTCONN):
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
@ -547,11 +548,11 @@ class dispatcher:
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
except socket.error as why:
|
except socket.error as why:
|
||||||
if why.errno in (errno.EAGAIN, errno.EWOULDBLOCK) or \
|
if why.args[0] in (EAGAIN, EWOULDBLOCK) or \
|
||||||
(sys.platform.startswith('win') and \
|
(sys.platform.startswith('win') and \
|
||||||
err.errno == errno.WSAEWOULDBLOCK):
|
err.errno == WSAEWOULDBLOCK):
|
||||||
return 0
|
return 0
|
||||||
elif why.errno in _DISCONNECTED:
|
elif why.args[0] in _DISCONNECTED:
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
|
@ -574,11 +575,11 @@ class dispatcher:
|
||||||
raise
|
raise
|
||||||
except socket.error as why:
|
except socket.error as why:
|
||||||
# winsock sometimes raises ENOTCONN
|
# winsock sometimes raises ENOTCONN
|
||||||
if why.errno in (errno.EAGAIN, errno.EWOULDBLOCK) or \
|
if why.args[0] in (EAGAIN, EWOULDBLOCK) or \
|
||||||
(sys.platform.startswith('win') and \
|
(sys.platform.startswith('win') and \
|
||||||
err.errno == errno.WSAEWOULDBLOCK):
|
err.errno == WSAEWOULDBLOCK):
|
||||||
return b''
|
return b''
|
||||||
if why.errno in _DISCONNECTED:
|
if why.args[0] in _DISCONNECTED:
|
||||||
self.handle_close()
|
self.handle_close()
|
||||||
return b''
|
return b''
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -289,7 +289,7 @@ class BMConnection(TLSDispatcher, BMQueues):
|
||||||
# print "skipping getdata"
|
# print "skipping getdata"
|
||||||
# return True
|
# return True
|
||||||
for i in items:
|
for i in items:
|
||||||
print "received getdata request for item %s" % (hexlify(i))
|
#print "received getdata request for item %s" % (hexlify(i))
|
||||||
#logger.debug('received getdata request for item:' + hexlify(i))
|
#logger.debug('received getdata request for item:' + hexlify(i))
|
||||||
#if i in ObjUploadQueue.streamElems(1):
|
#if i in ObjUploadQueue.streamElems(1):
|
||||||
if False:
|
if False:
|
||||||
|
@ -309,7 +309,8 @@ class BMConnection(TLSDispatcher, BMQueues):
|
||||||
logger.error("Too many items in inv message!")
|
logger.error("Too many items in inv message!")
|
||||||
raise BMProtoExcessiveDataError()
|
raise BMProtoExcessiveDataError()
|
||||||
else:
|
else:
|
||||||
print "items in inv: %i" % (len(items))
|
pass
|
||||||
|
#print "items in inv: %i" % (len(items))
|
||||||
|
|
||||||
startTime = time.time()
|
startTime = time.time()
|
||||||
#advertisedSet = set()
|
#advertisedSet = set()
|
||||||
|
@ -609,7 +610,10 @@ class BMConnection(TLSDispatcher, BMQueues):
|
||||||
else:
|
else:
|
||||||
print "%s:%i: closing, %s" % (self.destination.host, self.destination.port, reason)
|
print "%s:%i: closing, %s" % (self.destination.host, self.destination.port, reason)
|
||||||
network.connectionpool.BMConnectionPool().removeConnection(self)
|
network.connectionpool.BMConnectionPool().removeConnection(self)
|
||||||
|
try:
|
||||||
asyncore.dispatcher.close(self)
|
asyncore.dispatcher.close(self)
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Socks5BMConnection(Socks5Connection, BMConnection):
|
class Socks5BMConnection(Socks5Connection, BMConnection):
|
||||||
|
|
|
@ -110,7 +110,7 @@ class TLSDispatcher(AdvancedDispatcher):
|
||||||
if not (self.want_write or self.want_read):
|
if not (self.want_write or self.want_read):
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
print "%s:%i: handshake success" % (self.destination.host, self.destination.port)
|
print "%s:%i: TLS handshake success%s" % (self.destination.host, self.destination.port, ", TLS protocol version: %s" % (self.sslSocket.version()) if sys.version_info >= (2, 7, 9) else "")
|
||||||
# The handshake has completed, so remove this channel and...
|
# The handshake has completed, so remove this channel and...
|
||||||
self.del_channel()
|
self.del_channel()
|
||||||
self.set_socket(self.sslSocket)
|
self.set_socket(self.sslSocket)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user