Can I do a non-blocking read of a grpc bidirectional stream in c++? With a tcp socket for example I can set the O_NONBLOCK flag so that a read doesn't block and returns immediately if there isn't any data to receive. Is this possible with c++?
I have a c++ server that streams frames of audio data to a go server. The go server similarly streams audio data frames back to the c++ server. The c++ server sends a frame of audio bytes to the go server every 20ms. It does this *every* 20ms with no gaps. However the go server only occasionally streams audio data back to the c++ server and often is not sending anything. I want the c++ server to do a non-blocking read of the stream every 20ms - where if it there's no data to receive it returns immediately and does not block the thread.
Currently I have a non-blocking tcp socket connection working. However I need to send more structured data between the two servers. Rather than send protocol buffers down the tcp socket, I'd ideally like to use grpc. However a non-blocking read is a hard requirement for my application so I'm hoping someone can tell me if this is possible with grpc at all? Thanks.
Please note:
- The c++ server is really written in C and I'm using c++ just for grpc at the moment. So if this is possible (and not too difficult) somehow with the grpc c library I'd be interested to hear that.
- I've briefly looked into the completion queue api. However I'm not sure this does what I want (but could be wrong!) - I don't want to send a frame of audio and asyncronously process the response to that particular frame. Instead I want to receive a stream of audio frames and poll this every 20ms, not blocking if there isn't anything to receive.