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
This commit is contained in:
Luca Boccassi 2017-10-06 11:12:13 +01:00
parent 53f463a3fa
commit ed64585e93

View File

@ -39,9 +39,12 @@ int main (void)
void *ctx = zmq_ctx_new ();
assert (ctx);
void *sb = zmq_socket (ctx, ZMQ_PUSH);
assert (sb);
int rc = zmq_bind (sb, SOCKET_ADDR);
void *sb0 = zmq_socket (ctx, ZMQ_PUSH);
assert (sb0);
void *sb1 = zmq_socket (ctx, ZMQ_PUSH);
assert (sb1);
int rc = zmq_bind (sb0, SOCKET_ADDR);
assert (rc == 0);
void *sc = zmq_socket (ctx, ZMQ_PULL);
@ -49,22 +52,20 @@ int main (void)
rc = zmq_connect (sc, SOCKET_ADDR);
assert (rc == 0);
rc = zmq_send (sb, "42", 2, 0);
rc = zmq_send (sb0, "42", 2, 0);
assert (rc == 2);
char buffer [2];
rc = zmq_recv(sc, buffer, 2, 0);
assert (rc == 2);
rc = zmq_close (sb);
rc = zmq_close (sb0);
assert (rc == 0);
sb = zmq_socket (ctx, ZMQ_PUSH);
assert (sb);
rc = zmq_bind (sb, SOCKET_ADDR);
rc = zmq_bind (sb1, SOCKET_ADDR);
assert (rc == 0);
rc = zmq_send (sb, "42", 2, 0);
rc = zmq_send (sb1, "42", 2, 0);
assert (rc == 2);
rc = zmq_recv(sc, buffer, 2, 0);
@ -73,7 +74,7 @@ int main (void)
rc = zmq_close (sc);
assert (rc == 0);
rc = zmq_close (sb);
rc = zmq_close (sb1);
assert (rc == 0);
rc = zmq_ctx_term (ctx);