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

@ -1148,6 +1148,21 @@ to sockets.
.. versionadded:: 3.3
.. method:: socket.sendfile(file, offset=0, count=None)
Send a file until EOF is reached by using high-performance
:mod:`os.sendfile` and return the total number of bytes which were sent.
*file* must be a regular file object opened in binary mode. If
:mod:`os.sendfile` is not available (e.g. Windows) or *file* is not a
regular file :meth:`send` will be used instead. *offset* tells from where to
start reading the file. If specified, *count* is the total number of bytes
to transmit as opposed to sending the file until EOF is reached. File
position is updated on return or also in case of error in which case
:meth:`file.tell() <io.IOBase.tell>` can be used to figure out the number of
bytes which were sent. The socket must be of :const:`SOCK_STREAM` type. Non-
blocking sockets are not supported.
.. versionadded:: 3.5
.. method:: socket.set_inheritable(inheritable)