Skip to content

Commit

Permalink
fixed nonblocking ssl.write handling
Browse files Browse the repository at this point in the history
 large payloads may lead to SSLWantWriteError.
 in this case, try to retransmit the data
  • Loading branch information
tintinweb committed Mar 18, 2016
1 parent 2f1b7c5 commit 3e13009
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions striptls/striptls.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,20 @@ def recv_blocked(self, buflen=8*1024, timeout=None):
pass
force_first_loop_iteration = False

def send(self, data):
def send(self, data, retransmit_delay=0.1):
if self.socket_ssl:
self.socket_ssl.write(data)
last_exception = None
for _ in xrange(3):
try:
self.socket_ssl.write(data)
last_exception = None
break
except ssl.SSLWantWriteError,swwe:
logger.warning("TCPSockBuff: ssl.sock not yet ready, retransmit (%d) in %f seconds: %s"%(_,retransmit_delay,repr(swwe)))
last_exception = swwe
time.sleep(retransmit_delay)
if last_exception:
raise last_exception
else:
self.socket.send(data)
self.sndbuf = data
Expand Down

0 comments on commit 3e13009

Please sign in to comment.