Upgrading from 2.0 to 2.1

These are the main areas of impact on your applications moving from 2.0 to 2.1:

  • In 2.0, zmq_close[3] and zmq_term[3] discarded any in-flight messages, so it was unsafe to close a socket and terminate right after sending messages. In 2.1, these calls are safe: zmq_term will flush anything that's waiting to be sent. In 2.0 code we often added a sleep(1) to get around the problem. In 2.1, this is not needed.
  • By contrast, in 2.0, it was safe to call zmq_term[3] even if there were open sockets. In 2.1, this is not safe, and it may cause zmq_term to block. So in 2.1 you must always close every socket, before calling zmq_term. Furthermore, if you have any outgoing messages or connects waiting on a socket, 2.1 will by default wait forever trying to deliver these. You must set the LINGER socket option (e.g. to zero), on every socket which may still be busy, before calling zmq_term:
int zero = 0;
zmq_setsockopt (mysocket, ZMQ_LINGER, &zero, sizeof (zero));
  • In 2.0, zmq_poll[3] would return arbitrarily early, so you could not use it as a timer. We would work around this with a loop checked how much time was left, and called zmq_poll again as needed. In 2.1, zmq_poll properly waits for the full timeout if there are no events.
  • In 2.1, all blockable calls, such as zmq_poll[3] and zmq_recv[3] will return -1 and set errno to ETERM if they refer to a context that has been terminated. Thus, it would be safe in 2.0 to treat a non-zero return code from zmq_recv or zmq_poll as fatal, but in 2.1 you should treat these as 'exit whatever loop you are in and end your thread'.
  • In 2.0, ZeroMQ would ignore any interrupted system calls, which meant that no ZeroMQ call would ever return EINTR if a signal was received during its operation. This caused problems with loss of signals such as SIGINT (Ctrl-C handling), especially for language runtimes. In 2.1, any blocking ZeroMQ call such as zmq_recv[3] will return EINTR if it is interrupted by a signal.