Boost C++ Libraries: Ticket #3150: boost.asio: async_copy(in, out, ...) for POSIX sendfile() support https://svn.boost.org/trac10/ticket/3150 <p> hey guys, </p> <p> i wanted to use boost and boost.asio in order to implement a web service, however, when transmitting static files, i feel not welcome in just memcpy'ing the file into RAM and copying back into kernel space for transmission over TCP/IP. that's where POSIX sendfile() comes into play. </p> <p> it takes an input file descriptor (local file e.g.), an output file descriptor (socket e.g.), offset and count, and transfers data directly from input to output *without* leaving kernel space, this is highly recommented e.g. when sending local files to sockets in HA software. </p> <p> just like async_read/async_write, i imagine that it could be possible in providing an </p> <blockquote> <p> return_type async_copy(input, output, count, finish_callback, ...); </p> </blockquote> <p> would you mind? </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3150 Trac 1.4.3 chris_kohlhoff Sat, 27 Jun 2009 05:30:10 GMT milestone changed https://svn.boost.org/trac10/ticket/3150#comment:1 https://svn.boost.org/trac10/ticket/3150#comment:1 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.40.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> Ticket Christian Parpart <trapni@…> Tue, 11 Aug 2009 09:43:27 GMT cc set https://svn.boost.org/trac10/ticket/3150#comment:2 https://svn.boost.org/trac10/ticket/3150#comment:2 <ul> <li><strong>cc</strong> <span class="trac-author">trapni@…</span> added </li> </ul> <p> I quite don't think that this has anything to do with HA (::= High Availability) but much more with "High Performance" applications. </p> <p> However, I'm really very interested in a native boost integration of this, too, but still, i think this can be quite challenging as the input and output descriptors need to match certain criteria on different UNIX-alike operating systems (btw: windows has something similar) </p> <p> for Linux at least, the requirements are: </p> <ul><li>input fd must be mmap()-able. </li><li>output fd must be a socket. </li></ul><p> Although, when it comes to implementing an HTTP server (in my case), you cannot just pass the filename as a string to async_copy(...) as there are moments where you want to send just parts of a file, or even further: multiple different ranges of a file with some memory "chunks" between. </p> <p> Although, as in HTTP (and I assume this case for most of the file transfer related network protocols) before sending the plain file, you always send some kind of preamble/header, some memory chunk that introduces the range of bytes located in the file. Solaris helps out here with a special syscall, named sendfilev(), which is a combination of writev() and sendfile(). </p> <p> In the end, i think, that a simple "async_copy()" won't be able to cover all this, although, when just implementing a sendfile() wrapper, it won't be long to the next request of sendfilev(). </p> <p> To solve that, I'd like to propose a generalized idea of <code>composed transmit buffers</code> which is an ordered set of chunks of different types (e.g.: mem, file_descriptor, ...) which can be passed to some write(...) and async_write(...) Asio function. </p> <p> This is basically what I have written for my http server case, i'd be happy to see something like this in Asio anytime soon :) </p> <p> The following is a list of links where I implemented the composite transmit buffers with sendfile() support: </p> <ul><li><a class="ext-link" href="http://code.ninchens.net/projects/x0/repository/entry/src/x0/composite_buffer.hpp"><span class="icon">​</span>http://code.ninchens.net/projects/x0/repository/entry/src/x0/composite_buffer.hpp</a> </li><li><a class="ext-link" href="http://code.ninchens.net/projects/x0/repository/entry/src/x0/composite_buffer_async_writer.hpp"><span class="icon">​</span>http://code.ninchens.net/projects/x0/repository/entry/src/x0/composite_buffer_async_writer.hpp</a> </li><li><a class="ext-link" href="http://code.ninchens.net/projects/x0/repository/entry/src/x0/composite_buffer_writer.hpp"><span class="icon">​</span>http://code.ninchens.net/projects/x0/repository/entry/src/x0/composite_buffer_writer.hpp</a> </li></ul><p> hope it'll inspire asio development process :) </p> Ticket