Is there a way to cancel a pending operation (without disconnect) or set a timeout for the boost library functions?
I.e. I want to set a timeout on blocking socket in boost asio?
socket.read_some(boost::asio::buffer(pData, maxSize), error_);
Example: I want to read some from the socket, but I want to throw an error if 10 seconds have passed.
Under Linux/BSD the timeout on I/O operations on sockets is directly supported by the operating system. The option can be enabled via
setsocktopt(). I don’t know ifboost::asioprovides a method for setting it or exposes the socket scriptor to allow you to directly set it — the latter case is not really portable.For a sake of completeness here’s the description from the man page: