Skip to content

Commit

Permalink
fixes cherrypy#245
Browse files Browse the repository at this point in the history
  • Loading branch information
vashek committed Nov 2, 2020
1 parent 7268068 commit 4744cd1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 7 additions & 1 deletion cheroot/makefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ def write(self, b):
self._flush_unlocked()
return len(b)

def _safe_call(self, is_reader, call, *args, **kwargs): # noqa: C901
"""Method to be overridden in subclasses/mix-ins. Intended to call the
supplied callable with retries, as needed."""
return call(*args, **kwargs)

def _flush_unlocked(self):
self._checkClosed('flush of closed file')
while self._write_buf:
try:
# ssl sockets only except 'bytes', not bytearrays
# so perhaps we should conditionally wrap this for perf?
n = self.raw.write(bytes(self._write_buf))
n = self._safe_call(False, self.raw.write,
bytes(self._write_buf))
except io.BlockingIOError as e:
n = e.characters_written
del self._write_buf[:n]
Expand Down
14 changes: 10 additions & 4 deletions cheroot/ssl/pyopenssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,20 @@ def readline(self, size=-1):
size,
)

def sendall(self, *args, **kwargs):
"""Send whole message to the socket."""
def read(self, *args, **kwargs):
"""Read from the wrapped socket, with retry."""
return self._safe_call(
False,
super(SSLFileobjectMixin, self).sendall,
True,
super(SSLFileobjectMixin, self).read,
*args, **kwargs
)

def sendall(self, *args, **kwargs):
"""Send whole message to the socket - not supported due to
https://github.com/pyca/pyopenssl/issues/176."""
raise NotImplementedError("sendall() not supported on pyOpenSSL due "
"to issue #176")

def send(self, *args, **kwargs):
"""Send some part of message to the socket."""
return self._safe_call(
Expand Down

0 comments on commit 4744cd1

Please sign in to comment.