TheHydroImpulse/rust-nanomsg — pull request #17 by polyfractal (2014-04-29 02:31:55+00:00)
Title: Enhancement/nn poll

This implements the rust-safe version of nn_poll(). Because of the way nn_poll operates, it is possible that an error flag is set, so this commit also implements nn_errno().

There is already a NanoErr, which appears to be a very light wrapper around the error number and an error string. This didn't feel very "rusty" to me, so I added an error enum which matches the NanoMsg errors. This allows pattern matching on the the errors and makes for much cleaner syntax (I think). Open to opinions/changes.

The enum is currently called NanoError, which is confusingly similar to NanoErr...it should probably be renamed

poll() accepts three parameters:

- send (bool): check if this socket can send a message
- receive (bool): check if this socket can receive a message (e.g.
a pending message is waiting)
- timeout (int): how long to wait before returning with an error

poll() returns an Option, containing either:

- (send, receive) = Some((bool, bool))
- error = Err(NanoError)

The second commit in this PR implements two convenience methods (`can_send` and `can_receive`), which make it easier to interact with the poll method if you just want a true/false response (instead of dealing with error handling).