[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [Libevent-users] splice()/sendfile() with sockets
â 29 janvier 2014 21:47 CET, Nick Mathewson <nickm@xxxxxxxxxxxxx>Â:
>> Currently, libevent is not using splice() syscall but it is mentioned at
>> several places. It could be used in place of sendfile(). This would be
>> convenient since it would allow to copy one socket to another through
>> event buffers without the data to be copied in user memory. Does the use
>> of splice() instead of sendfile() be difficult?
>> --
>
> I'd be happy to merge a patch for splice() support. Have a look at
> the evbuffer_splice_sendfile() function to see what you'd need to
> change.
>
> Are there any cases where sendfile is necessary because splice won't
> work? If so, we'll need to use the flags argument to
> evbuffer_file_segment_new() for that.
Note that I opened the an issue to track a bit progress here.
sendfile() now uses splice(). However, splice() is more recent and buggy
until 2.6.28. Here is what we can find about it in HAProxy source code:
/* Versions of splice between 2.6.25 and 2.6.27.12 were bogus and would return EAGAIN
* on incoming shutdowns. On these versions, we have to call recv() after such a return
* in order to find whether splice is OK or not. Since 2.6.27.13 we don't need to do
* this anymore, and we can avoid this logic by defining ASSUME_SPLICE_WORKS.
*/
So, if we overload sendfile(), we need to be ready for splice() to be
accepted but buggy. HAProxy's code show how to detect that and
circumvent it without relying on version numbers.
As pointed in the issue I opened, this is only half of the problem. The
other half is to be able to do zero-copy between sockets.
--
Take care to branch the right way on equality.
- The Elements of Programming Style (Kernighan & Plauger)
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.