I use boost::asio::read (or may be the equivalent async_read) to read some data from a socket.
Is it possible that I leave the bytes read in the underlying socket so that next time I call read on the socket I receive again that data ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Like Simon said, you can’t do it with
boost::asio::read()(orboost::asio::async_read()). However, forread()you could callnative_handle()on the socket to get the socket descriptor and then use::recvmsg()with theMSG_PEEKflag. Similarly, you could callasync_read()withnull_buffers()as the receive buffer and then use thenative_handle()/::recvmsg()trick to peek the data. Check out this section of the boost documentation for how to use null_buffers().