summaryrefslogtreecommitdiff
path: root/Lib/asyncore.py
diff options
context:
space:
mode:
authorGiampaolo Rodola' <g.rodola@gmail.com>2012-03-22 16:19:45 +0100
committerGiampaolo Rodola' <g.rodola@gmail.com>2012-03-22 16:19:45 +0100
commit3539ef3d21a47beff871636bdf6cd5e40aa556e4 (patch)
tree60bb613c98035fd4d2acb6873f413479091d5c7d /Lib/asyncore.py
parentcc58031d6a800647b0e37c8fa812bbe1200eac22 (diff)
parent350c94b90067777457be0d13169e937730d70eb4 (diff)
downloadcpython-git-3539ef3d21a47beff871636bdf6cd5e40aa556e4.tar.gz
merge 79422b3684f1 in 3.3 branch (issue 10340)
Diffstat (limited to 'Lib/asyncore.py')
-rw-r--r--Lib/asyncore.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/Lib/asyncore.py b/Lib/asyncore.py
index d20609d361..2cac88b948 100644
--- a/Lib/asyncore.py
+++ b/Lib/asyncore.py
@@ -217,6 +217,7 @@ class dispatcher:
debug = False
connected = False
accepting = False
+ connecting = False
closing = False
addr = None
ignore_log_types = frozenset(['warning'])
@@ -240,7 +241,7 @@ class dispatcher:
try:
self.addr = sock.getpeername()
except socket.error as err:
- if err.args[0] == ENOTCONN:
+ if err.args[0] in (ENOTCONN, EINVAL):
# To handle the case where we got an unconnected
# socket.
self.connected = False
@@ -334,6 +335,7 @@ class dispatcher:
def connect(self, address):
self.connected = False
+ self.connecting = True
err = self.socket.connect_ex(address)
if err in (EINPROGRESS, EALREADY, EWOULDBLOCK) \
or err == EINVAL and os.name in ('nt', 'ce'):
@@ -393,6 +395,7 @@ class dispatcher:
def close(self):
self.connected = False
self.accepting = False
+ self.connecting = False
self.del_channel()
try:
self.socket.close()
@@ -431,7 +434,8 @@ class dispatcher:
# sockets that are connected
self.handle_accept()
elif not self.connected:
- self.handle_connect_event()
+ if self.connecting:
+ self.handle_connect_event()
self.handle_read()
else:
self.handle_read()
@@ -442,6 +446,7 @@ class dispatcher:
raise socket.error(err, _strerror(err))
self.handle_connect()
self.connected = True
+ self.connecting = False
def handle_write_event(self):
if self.accepting:
@@ -450,12 +455,8 @@ class dispatcher:
return
if not self.connected:
- #check for errors
- err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
- if err != 0:
- raise socket.error(err, _strerror(err))
-
- self.handle_connect_event()
+ if self.connecting:
+ self.handle_connect_event()
self.handle_write()
def handle_expt_event(self):