Commit ed64585e authored by Luca Boccassi's avatar Luca Boccassi

Problem: test_rebind_ipc might not see race condition on fast envs

Solution: pre-create the second socket to save a few cycles between
closing the old one and binding the new one
parent 53f463a3
...@@ -39,9 +39,12 @@ int main (void) ...@@ -39,9 +39,12 @@ int main (void)
void *ctx = zmq_ctx_new (); void *ctx = zmq_ctx_new ();
assert (ctx); assert (ctx);
void *sb = zmq_socket (ctx, ZMQ_PUSH); void *sb0 = zmq_socket (ctx, ZMQ_PUSH);
assert (sb); assert (sb0);
int rc = zmq_bind (sb, SOCKET_ADDR); void *sb1 = zmq_socket (ctx, ZMQ_PUSH);
assert (sb1);
int rc = zmq_bind (sb0, SOCKET_ADDR);
assert (rc == 0); assert (rc == 0);
void *sc = zmq_socket (ctx, ZMQ_PULL); void *sc = zmq_socket (ctx, ZMQ_PULL);
...@@ -49,22 +52,20 @@ int main (void) ...@@ -49,22 +52,20 @@ int main (void)
rc = zmq_connect (sc, SOCKET_ADDR); rc = zmq_connect (sc, SOCKET_ADDR);
assert (rc == 0); assert (rc == 0);
rc = zmq_send (sb, "42", 2, 0); rc = zmq_send (sb0, "42", 2, 0);
assert (rc == 2); assert (rc == 2);
char buffer [2]; char buffer [2];
rc = zmq_recv(sc, buffer, 2, 0); rc = zmq_recv(sc, buffer, 2, 0);
assert (rc == 2); assert (rc == 2);
rc = zmq_close (sb); rc = zmq_close (sb0);
assert (rc == 0); assert (rc == 0);
sb = zmq_socket (ctx, ZMQ_PUSH); rc = zmq_bind (sb1, SOCKET_ADDR);
assert (sb);
rc = zmq_bind (sb, SOCKET_ADDR);
assert (rc == 0); assert (rc == 0);
rc = zmq_send (sb, "42", 2, 0); rc = zmq_send (sb1, "42", 2, 0);
assert (rc == 2); assert (rc == 2);
rc = zmq_recv(sc, buffer, 2, 0); rc = zmq_recv(sc, buffer, 2, 0);
...@@ -73,7 +74,7 @@ int main (void) ...@@ -73,7 +74,7 @@ int main (void)
rc = zmq_close (sc); rc = zmq_close (sc);
assert (rc == 0); assert (rc == 0);
rc = zmq_close (sb); rc = zmq_close (sb1);
assert (rc == 0); assert (rc == 0);
rc = zmq_ctx_term (ctx); rc = zmq_ctx_term (ctx);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment