Author giampaolo.rodola
Recipients giampaolo.rodola
Date 2013-03-26.19:27:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1364326073.47.0.699222209849.issue17552@psf.upfronthosting.co.za>
In-reply-to
Content
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)


=== ALTERNATE API === 

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.

=== WINDOWS SUPPORT ===

Further development may include Windows support by using TransmitFile (http://msdn.microsoft.com/en-us/library/windows/desktop/ms740565(v=vs.85).aspx). 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.
History
Date User Action Args
2013-03-26 19:27:54giampaolo.rodolasetrecipients: + giampaolo.rodola
2013-03-26 19:27:53giampaolo.rodolasetmessageid: <1364326073.47.0.699222209849.issue17552@psf.upfronthosting.co.za>
2013-03-26 19:27:53giampaolo.rodolalinkissue17552 messages
2013-03-26 19:27:53giampaolo.rodolacreate