Skip to content

Commit 92a2ef9

Browse files
vashekwebknjaz
authored andcommitted
fixes #245
1 parent 0dcf6a1 commit 92a2ef9

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
@@ -24,13 +24,22 @@ def write(self, b):
2424
self._flush_unlocked()
2525
return len(b)
2626

27+
def _safe_call(self, is_reader, call, *args, **kwargs):
28+
"""Call the supplied callable with retries, as needed.
29+
30+
Method to be overridden in subclasses/mix-ins.
31+
"""
32+
return call(*args, **kwargs)
33+
2734
def _flush_unlocked(self):
2835
self._checkClosed('flush of closed file')
2936
while self._write_buf:
3037
try:
3138
# ssl sockets only except 'bytes', not bytearrays
3239
# so perhaps we should conditionally wrap this for perf?
33-
n = self.raw.write(bytes(self._write_buf))
40+
n = self._safe_call(
41+
False, self.raw.write, bytes(self._write_buf),
42+
)
3443
except io.BlockingIOError as e:
3544
n = e.characters_written
3645
del self._write_buf[:n]

cheroot/ssl/pyopenssl.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,24 @@ def readline(self, size=-1):
145145
size,
146146
)
147147

148-
def sendall(self, *args, **kwargs):
149-
"""Send whole message to the socket."""
148+
def read(self, *args, **kwargs):
149+
"""Read from the wrapped socket, with retry."""
150150
return self._safe_call(
151-
False,
152-
super(SSLFileobjectMixin, self).sendall,
151+
True,
152+
super(SSLFileobjectMixin, self).read,
153153
*args, **kwargs
154154
)
155155

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

0 commit comments

Comments
 (0)