Skip to content

Commit add128a

Browse files
committed
fixes cherrypy#245
1 parent 7268068 commit add128a

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

cheroot/makefile.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,22 @@ def write(self, b):
3636
self._flush_unlocked()
3737
return len(b)
3838

39+
def _safe_call(self, is_reader, call, *args, **kwargs):
40+
"""Call the supplied callable with retries, as needed.
41+
42+
Method to be overridden in subclasses/mix-ins.
43+
"""
44+
return call(*args, **kwargs)
45+
3946
def _flush_unlocked(self):
4047
self._checkClosed('flush of closed file')
4148
while self._write_buf:
4249
try:
4350
# ssl sockets only except 'bytes', not bytearrays
4451
# so perhaps we should conditionally wrap this for perf?
45-
n = self.raw.write(bytes(self._write_buf))
52+
n = self._safe_call(
53+
False, self.raw.write, bytes(self._write_buf),
54+
)
4655
except io.BlockingIOError as e:
4756
n = e.characters_written
4857
del self._write_buf[:n]

cheroot/ssl/pyopenssl.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,24 @@ def readline(self, size=-1):
150150
size,
151151
)
152152

153-
def sendall(self, *args, **kwargs):
154-
"""Send whole message to the socket."""
153+
def read(self, *args, **kwargs):
154+
"""Read from the wrapped socket, with retry."""
155155
return self._safe_call(
156-
False,
157-
super(SSLFileobjectMixin, self).sendall,
156+
True,
157+
super(SSLFileobjectMixin, self).read,
158158
*args, **kwargs
159159
)
160160

161+
def sendall(self, *args, **kwargs):
162+
"""Send whole message to the socket. Unsupported, do not use."""
163+
# Not supported due to https://github.com/pyca/pyopenssl/issues/176.
164+
# Until that bug is fixed, sendall() may throw SSL.WantWriteError, but
165+
# there is no correct way to retry the call because we don't know how
166+
# many bytes were already transmitted. We could work around this by
167+
# reimplementing sendall() using send(), but we don't actually use
168+
# sendall() anywhere.
169+
raise NotImplementedError('sendall() is unsupported by pyOpenSSL')
170+
161171
def send(self, *args, **kwargs):
162172
"""Send some part of message to the socket."""
163173
return self._safe_call(

0 commit comments

Comments
 (0)