I’m new to network programming in general, so please bear with me. I couldn’t find anything about this in the boost documentation. When using asio::async_read, an end of file error is raised when there is no data to be read from the socket (at least, I think it does). Is there any way to implement some kind of check to prevent this behavior? What I’m trying to get at is: is there any way to wait for data to be present, and then read said data and call the handler? (If this is poorly worded, please say so. I will try to clarify.)
Share
eofis returned when the other side of the socket is closed, not when there is no data to read.This is called polling, it’s what the asio
io_servicedoes for you. You tell theio_servicethat you want to read data from the socket by initiating anasync_read. It performs the read on your behalf and invokes the completion handler when it is finished successfully or unsuccessfully.It might be worth your time to study the differences between asynchronous and synchronous methods offered by Boost.Asio.