Boost asio socket: the fastest way to read a file from your hard drive?

So I tried:

int buff_length = 8192;
ifstream stream;
char* buffer = new char[buff_length];

stream.open( path.string().c_str(), ios::binary );

boost::system::error_code ignored_error;

while (stream)
{
    stream.read(buffer, buff_length);
    boost::asio::write(*socket, boost::asio::buffer(buffer, stream.gcount()),
                            boost::asio::transfer_all(), ignored_error);  
}

I wonder how you do it - how to do it faster?

My application should work through Windows, Linux and Mac OS. That is why I use boost alot. I use abfor testing. I want to get 2 or at least 1.5 times faster when reading and sending files. Maybe Boost :: Iostream can help me how?

+5
source share
3 answers

Not quite sure what you need, but to answer your question about fast reading files, you can map the file to memory .

, . .. , , . , , .

Boost.Interprocess .

+1

, sendfile (2), Linux. .

- , , , , , 8 .

0

boost:: asio TransmitFile, . example

0

All Articles