ZeroCM / zcm

Zero Communications and Marshalling
http://zerocm.github.io/zcm/
GNU Lesser General Public License v2.1
237 stars 69 forks source link

zcm handle with timeout #380

Open olsoni opened 2 years ago

olsoni commented 2 years ago

Current implementation has "handle" block until a message is received or published. Running into some scenarios where this behavior is undesirable, and it'd be nice if there was a way to pass a maximum time to the function before it would return E_AGAIN.

jbendes commented 2 years ago

This kinda goes against the "blocking" vs "nonblocking" transport API. We can, of course, adjust the API, but I would be hesitant to do so

olsoni commented 2 years ago

Yeah I realize that. I think it might even be as easy as allowing handle_nonblock to be called even on a blocking transport. Currently, it just asserts if you try to do that, even though there's nothing stopping blocking.cpp from effectively doing a handle_nonblock (ie check to see if there's a message available, then either dispatch it or return E_AGAIN). I think I would be ok with that API update.

jbendes commented 2 years ago

There's no api to "check" if there's a message available as far as I'm aware. On a blocking transport, that check blocks

olsoni commented 2 years ago

Not from the transport, but luckily that's not what it actually needs to check. It just needs to check if the threadsafe_queue recvQueue has a message sitting in it. Currently, handle just blocks until the queue has a message (rather than check if it has a message).