After binding a ZeroMQ socket to an endpoint and closing the socket, binding another socket to the same endpoint requires several attempts. The previous calls to zmq_bind up until the successful one fail with the error "Address in use" (EADDRINUSE).
The following code demonstrates the problem:
#include <cassert> #include <iostream> #include "zmq.h" int main() { void *ctx = zmq_ctx_new(); assert( ctx ); void *skt; skt = zmq_socket( ctx, ZMQ_REP ); assert( skt ); assert( zmq_bind( skt, "tcp://*:5555" ) == 0 ); assert( zmq_close( skt ) == 0 ); skt = zmq_socket( ctx, ZMQ_REP ); assert( skt ); int fail = 0; while ( zmq_bind( skt, "tcp://*:5555" ) ) { ++fail; } std::cout << fail << std::endl; } I'm using ZeroMQ 4.0.3 on Windows XP SP3, compiler is VS 2008. libzmq.dll has been built with the provided Visual Studio solution.
This prints 1 here when doing a "Debug" build (both of the code above and of libzmq.dll) and 0 using a "Release" build. Strange enough, when running the code above with mixed build configuration (Debug with Release lib), fail counts up to 6.