Alex Shtoff
Alex Shtoff

Reputation: 2640

Cancelling a blocking read operation in Thrift

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?

Upvotes: 9

Views: 1016

Answers (2)

stefan.schwetschke
stefan.schwetschke

Reputation: 8932

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.

Upvotes: 5

secmask
secmask

Reputation: 8127

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.

Upvotes: 3

Related Questions