Re: [asio-users] Questions about file io when using boost.asio
Brought to you by:
chris_kohlhoff
From: lampahome <pah...@mi...> - 2020-09-01 10:30:30
|
> > > I want to do is like libaio in unix system and want to find some library > to reach that easier. > > Hmm, I'm on linux and yet I find libasio works quite well for me. Maybe I > missed something. Although libasio gives me a bit more support, I think, > than just libaio's completion handlers. > I will try libasio and thanks your help > I have two threads(or one is main thread) and one thread will submit io of > file as more as it can, and another one thread will check the execution > state(i.e. return code) of each io. I thought this design pattern will > improve my program. > > I'd use completion handlers for checking return codes. Here's a snippet > from a function of mine, in case it can help: > > void TcpConnection::SendMessage(...) { > > boost::asio::async_write( > *sockets_[connection_index], > boost::asio::buffer(send_queue_[connection_index].front()), > [this, connection_index](boost::system::error_code ec, size_t > length) { > LOGGABLE; > // This is the completion handler. > if (ec) { > LOG_WARNING << "Failed to send message: " << AsioError(ec); > SendFailure(connection_index, ec); > return; > } > // ... > > > I forgot which handler can use lambda function. Thank you again. I will continue combine your advise and look up Doc to develope. |