I am using Apache thrift in C++ on Windows and I would like to ask for your help with cancellation of a blocking read operation that is in progress. The read operation (for example – TProtocol::readByte) is blocked until the data is received. When I close the transport from another thread, I get a failed assertion about a null pointer.
Is there any other way to cancel a blocked read operation?
Assuming you are running on Windows (according to the tags on your question): You can cancel a blocking socket operation with WSACancelBlockingCall
(although this operation is deprecated, it should still work). Your socket will then return the error code WSAEINTR
(Interrupted function call) instead of WSAETIMEDOUT
.
In Thrift, you can use TSocket::getSocketFD() or TPipe::getPipeHandle() to get the according handle for canceling the current operation.
if you're using blocking mode, so the only option to abort the read operation is set a timeout on the TSocket before read it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With