mirror of
https://github.com/python/cpython.git
synced 2025-10-05 14:41:07 +00:00
[3.6] bpo-27340: Use memoryview in SSLSocket.sendall() (GH-3384) (#3434)
* bpo-27340: Use memoryview in SSLSocket.sendall()
SSLSocket.sendall() now uses memoryview to create slices of data. This fix
support for all bytes-like object. It is also more efficient and avoids
costly copies.
Signed-off-by: Christian Heimes <christian@python.org>
* Cast view to bytes, fix typo
Signed-off-by: Christian Heimes <christian@python.org>.
(cherry picked from commit 888bbdc192
)
This commit is contained in:
parent
6c99b652f7
commit
9423f5d688
3 changed files with 19 additions and 5 deletions
|
@ -959,11 +959,12 @@ class SSLSocket(socket):
|
|||
raise ValueError(
|
||||
"non-zero flags not allowed in calls to sendall() on %s" %
|
||||
self.__class__)
|
||||
amount = len(data)
|
||||
count = 0
|
||||
while (count < amount):
|
||||
v = self.send(data[count:])
|
||||
count += v
|
||||
with memoryview(data) as view, view.cast("B") as byte_view:
|
||||
amount = len(byte_view)
|
||||
while count < amount:
|
||||
v = self.send(byte_view[count:])
|
||||
count += v
|
||||
else:
|
||||
return socket.sendall(self, data, flags)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue