Created
February 24, 2012 16:07
-
-
Save EmielM/1901791 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ZmqWaiter { | |
zmq::socket_t sleep_socket_; | |
ZmqWaiter(zmq::context_t& ctx) : sleep_socket_(ctx, ZMQ_PUSH) {} | |
// Waits for either | |
// (a) msecs milliseconds to pass | |
// (b) global zmq_ctx to be teared down | |
inline bool Sleep(unsigned long msecs) { | |
try { | |
zmq::pollitem_t pollitem; | |
pollitem.socket = sleep_socket_; | |
zmq::poll(&pollitem, 1, msecs); | |
return true; | |
} | |
catch (zmq::error_t e) { | |
return false; | |
} | |
} | |
// Waits for either | |
// (a) something to happen on file descriptor fd | |
// (b) global zmq_ctx to be teared down | |
inline bool WaitForFd(int fd) { | |
try { | |
zmq::pollitem_t pollitems[2]; | |
pollitems[0].socket = sleep_socket_; | |
pollitems[1].fd = fd; | |
pollitems[1].events = ZMQ_POLLIN | ZMQ_POLLOUT | ZMQ_POLLERR; | |
zmq::poll(pollitems, 2, -1); | |
return true; | |
} | |
catch (zmq::error_t e) { | |
return false; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment