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'ยท
diff --git a/Doc/library/os.rst b/Doc/library/os.rst
index 2de4888..170d07b 100644
--- a/Doc/library/os.rst
+++ b/Doc/library/os.rst
@@ -1092,6 +1092,10 @@
 
    Availability: Unix.
 
+   .. note::
+
+      For a higher-level version of this see :mod:`socket.socket.sendfile`.
+
    .. versionadded:: 3.3
 
 
diff --git a/Doc/library/socket.rst b/Doc/library/socket.rst
index 3a9d611..ceeb776 100644
--- a/Doc/library/socket.rst
+++ b/Doc/library/socket.rst
@@ -1148,6 +1148,21 @@
 
    .. 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)
 
diff --git a/Doc/library/ssl.rst b/Doc/library/ssl.rst
index 0b0edd8..6eb47e3 100644
--- a/Doc/library/ssl.rst
+++ b/Doc/library/ssl.rst
@@ -789,6 +789,9 @@
   (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
diff --git a/Doc/whatsnew/3.5.rst b/Doc/whatsnew/3.5.rst
index 5c4e0b5..af734c8 100644
--- a/Doc/whatsnew/3.5.rst
+++ b/Doc/whatsnew/3.5.rst
@@ -181,9 +181,18 @@
 
 * Different constants of :mod:`signal` module are now enumeration values using
   the :mod:`enum` module. This allows meaningful names to be printed during
-  debugging, instead of integer “magic numbers”. (contribute by Giampaolo
+  debugging, instead of integer “magic numbers”. (contributed by Giampaolo
   Rodola' in :issue:`21076`)
 
+socket
+------
+
+* New :meth:`socket.socket.sendfile` method allows to send a file over a socket
+  by using high-performance :func:`os.sendfile` function on UNIX resulting in
+  uploads being from 2x to 3x faster than when using plain
+  :meth:`socket.socket.send`.
+  (contributed by Giampaolo Rodola' in :issue:`17552`)
+
 xmlrpc
 ------