This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author giampaolo.rodola
Recipients giampaolo.rodola
Date 2013-03-26.19:27:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
This is based on progress made in issue 13564 and aims to provide a new sendfile() method for the socket class taking advantage of high-performance "zero-copy" os.sendfile() available on most POSIX platforms.
A wrapper on top of os.sendfile() appears to be convenient because getting everything right is a bit tricky. Also we can avoid code duplication in case we want to add sendfile() support to ftplib (issue 13564) and httplib.

=== THE API ===

Attached is a draft patch proposing an API which:

- uses os.sendfile() whenever available and usable (a mmap-like file is required)
- if not falls back on using plain socket.sendall()
- returns a tuple of two elements which indicates whether sendfile() was used and an exception instance in case it wasn't on account of an internal error, if any 
- does not support non-blocking sockets (will raise ValueError)


1) In case the transfer is interrupted halfway because of an error the user has no clue on how many bytes were sent (and file.tell() won't tell =)). As such it probably makes sense to provide a custom socket.SendfileError exception encapsulating the original exception and the bytes sent as arguments.

2) For the same reason the returned tuple should probably include the number of bytes transmitted.


Further development may include Windows support by using TransmitFile ( Once we agree on an API I might start looking into Windows code (which appears to be quite tricky btw).

Any feedback is very welcome.
Date User Action Args
2013-03-26 19:27:54giampaolo.rodolasetrecipients: + giampaolo.rodola
2013-03-26 19:27:53giampaolo.rodolasetmessageid: <>
2013-03-26 19:27:53giampaolo.rodolalinkissue17552 messages
2013-03-26 19:27:53giampaolo.rodolacreate