moetsi / Sensor-Stream-Pipe

Open Source Sensor Stream Server and Client for Digitizing Reality
MIT License
70 stars 11 forks source link

Use polling to check NetworkReader has new frame #7

Closed eidetic-av closed 3 years ago

eidetic-av commented 3 years ago

Not sure if this is in your interest to merge or not, but I noticed that NetworkReader::HasNextFrame() has not been implemented in master... it just always returns true.

For the client I am building, it was necessary that I implemented this properly because of the blocking nature of NetworkReader::NextFrame(). I cannot just call this every frame and have the thread block, so first I check HasNextFrame() and only call NextFrame() if it returns true.

I say I'm not sure if my solution is in your interest to merge because it uses the draft API of zeromq. That being said, this particular polling API I am using has not changed in years....

Both zeromq and cppzmq need to be built with the draft api flags to enable this.

My solution is to just create a zmq::poller which simply checks if a frame has arrived. The polling timeout before the function returns false is set with POLL_TIMEOUT_MS.

amourao commented 3 years ago

Yeah, on our current use-case it does not make a big difference, but I agree it makes sense and makes to SSP applicable to more use cases. I'll merge it after checking the Windows build situation. Thanks.

amourao commented 3 years ago

To avoid conflicts with Moetsi's current setup, I've added polling as an optional build option, set by the env var SSP_WITH_ZMQ_POLLING.

The README and INSTALL.md will be updated accordingly (mentioned in the ZMQ install step) and linked to this PR.