fix issue #17552: add socket.sendfile() method allowing to send a file over a socket by using high-performance os.sendfile() on UNIX. Patch by Giampaolo Rodola'·

This commit is contained in:
Giampaolo Rodola' 2014-06-11 03:54:30 +02:00
parent b398d33c65
commit 915d14190e
9 changed files with 483 additions and 2 deletions

View file

@ -700,6 +700,16 @@ class SSLSocket(socket):
else:
return socket.sendall(self, data, flags)
def sendfile(self, file, offset=0, count=None):
"""Send a file, possibly by using os.sendfile() if this is a
clear-text socket. Return the total number of bytes sent.
"""
if self._sslobj is None:
# os.sendfile() works with plain sockets only
return super().sendfile(file, offset, count)
else:
return self._sendfile_use_send(file, offset, count)
def recv(self, buflen=1024, flags=0):
self._checkClosed()
if self._sslobj: