Im building a TCP client based on Boost::ASIO lib. I used read_some()
from Boost to read the response from the server. I want to implement a time out logic in it, which send a "ping" command if there has been no communication for 10 seconds. The problem is
l=_socket->read_some(boost::asio::buffer(this->reply,sizeof(this->reply)),error);
seems to block the program execution when there is no data to be transferred to the read buffer. So is there any way out of it? I didn't want to use the async_read_some()
as I need this thread to sleep if there is no data has been transferred in to the buffer, that was easily done in read_some()
as it returns the size of data transferred.
The main thing is even during time-out I dont want to close the connection, but to check if the server responds to a ping command, if it doesn't I would move to re-connection. So this is more or less checking if the server is still there connected, when no data is transmitted over a time period.