def sendfile(self, file, blocksize=262144, offset=0, use_fallback=True):
"""sendfile(file[, blocksize[, offset[, use_fallback]]]) -> sent
Send a file until EOF is reached attempting to use high-performance
os.sendfile() in which case *file* must be a regular file object
opened in binary mode; if not and *use_fallback* is True send()
will be used instead.
File position is updated on return or also in case of error in
which case file.tell() can be used to figure out the number of
bytes which were transmitted.
*blocksize* is the maximum number of bytes to transmit at one time,
*offset* tells from where to start reading the file.
The socket must be of SOCK_STREAM type.
Non-blocking sockets are not supported.
Return the total number of bytes which were transmitted.
Debatable questions which were raised during the discussion on the bug tracker are:
1 - whether to provide a "use_fallback" argument which when False raises an exception in case os.sendfile() could not be used
2 - whether to provide a custom exception in order to signal the number of bytes transmitted as opposed to use file.tell() afterwards; for the record, I'm -1 on this.
3 - whether to commit the patch as-is without including Windows support via TransmitFile() and
post-pone that for a later time in a separate issue
4 - (extra) whether to provide a "callback" argument which gets called against each block of data before it is being sent. This would be useful to apply data transformation or to implement a progress bar or something. Note if this gets added it would sort of conflict with the "use_fallback=False" parameter because in order to apply data transformation socket.send() must be used instead of os.sendfile().
So far #1 appears to be the most debatable question.