Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 701
Alex Shtof Avatar asked Aug 29 '13 07:08

Alex Shtof


2 Answers

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.

like image 53
stefan.schwetschke Avatar answered Sep 22 '22 22:09

stefan.schwetschke


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.

like image 3
secmask Avatar answered Sep 23 '22 22:09

secmask