Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle SSLWantReadError and SSLWantWriteErrors on recv and send. #100

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions SimpleWebSocketServer/SimpleWebSocketServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,11 @@ def _handleData(self):
# do the HTTP header and handshake
if self.handshaked is False:

data = self.client.recv(self.headertoread)
try:
data = self.client.recv(self.headertoread)
except (ssl.SSLWantReadError, ssl.SSLWantWriteError):
# SSL socket not ready to read yet, wait and try again
return
if not data:
raise Exception('remote socket closed')

Expand Down Expand Up @@ -283,7 +287,11 @@ def _handleData(self):

# else do normal data
else:
data = self.client.recv(16384)
try:
data = self.client.recv(16384)
except (ssl.SSLWantReadError, ssl.SSLWantWriteError):
# SSL socket not ready to read yet, wait and try again
return
if not data:
raise Exception("remote socket closed")

Expand Down Expand Up @@ -332,6 +340,12 @@ def _sendBuffer(self, buff, send_all = False):
already_sent += sent
tosend -= sent

except (ssl.SSLWantReadError, ssl.SSLWantWriteError):
# SSL socket not ready to send yet, wait and try again
if send_all:
continue
return buff[already_sent:]

except socket.error as e:
# if we have full buffers then wait for them to drain and try again
if e.errno in [errno.EAGAIN, errno.EWOULDBLOCK]:
Expand Down