Skip to content

Commit

Permalink
Non-blocking connect() broke SSL wrap_socket() and backward compatibi…
Browse files Browse the repository at this point in the history
…lity fix
  • Loading branch information
jmptbl committed Jun 15, 2015
1 parent 76ceebf commit 00bfd39
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions puka/connection.py
Expand Up @@ -96,7 +96,6 @@ def _connect(self):
self.needs_write = self.needs_write_connect
self.on_write = self.on_write_connect
if self.ssl:
self.sd = self._wrap_socket(self.sd)
self.on_read = self.on_read_handshake
else:
self.on_read = self.on_read_nohandshake
Expand Down Expand Up @@ -235,11 +234,7 @@ def _send_frames(self, channel_number, frames):
for frame_type, payload in frames]) )

def needs_write_connect(self):
if self.ssl:
self.needs_write = self.needs_write_handshake
else:
self.needs_write = self.needs_write_nohandshake
return True
return not self.sd is None

def needs_write_handshake(self):
try:
Expand All @@ -248,10 +243,10 @@ def needs_write_handshake(self):
self.on_write = self.on_write_nohandshake
self.on_read = self.on_read_nohandshake
return self.needs_write()
except ssl.SSLWantReadError:
return False
except ssl.SSLWantWriteError:
return True
except ssl.SSLError, e:
if e.args[0] == ssl.SSL_ERROR_WANT_WRITE:
return True
return False

def needs_write_nohandshake(self):
return bool(self.send_buf)
Expand All @@ -263,8 +258,11 @@ def on_write_connect(self):
exceptions.ConnectionBroken()))
return
if self.ssl:
self.sd = self._wrap_socket(self.sd)
self.needs_write = self.needs_write_handshake
self.on_write = self.on_write_handshake
else:
self.needs_write = self.needs_write_nohandshake
self.on_write = self.on_write_nohandshake
self.on_write()

Expand Down

0 comments on commit 00bfd39

Please sign in to comment.