mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
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:
parent
b398d33c65
commit
915d14190e
9 changed files with 483 additions and 2 deletions
|
@ -1092,6 +1092,10 @@ or `the MSDN <http://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>`_ on Window
|
|||
|
||||
Availability: Unix.
|
||||
|
||||
.. note::
|
||||
|
||||
For a higher-level version of this see :mod:`socket.socket.sendfile`.
|
||||
|
||||
.. versionadded:: 3.3
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -789,6 +789,9 @@ SSL sockets provide the following methods of :ref:`socket-objects`:
|
|||
(but passing a non-zero ``flags`` argument is not allowed)
|
||||
- :meth:`~socket.socket.send()`, :meth:`~socket.socket.sendall()` (with
|
||||
the same limitation)
|
||||
- :meth:`~socket.socket.sendfile()` (but :mod:`os.sendfile` will be used
|
||||
for plain-text sockets only, else :meth:`~socket.socket.send()` will be used)
|
||||
.. versionadded:: 3.5
|
||||
- :meth:`~socket.socket.shutdown()`
|
||||
|
||||
However, since the SSL (and TLS) protocol has its own framing atop
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue