@@ -88,22 +88,65 @@ int main (void)
8888 void *ctx = zmq_ctx_new ();
8989 assert (ctx);
9090
91+ // We first test client/server with a ZAP domain but with no handler
92+ // If there is no handler, libzmq should ignore the ZAP option unless
93+ // ZMQ_ZAP_ENFORCE_DOMAIN is set
94+ void *server = zmq_socket (ctx, ZMQ_DEALER);
95+ assert (server);
96+ void *client = zmq_socket (ctx, ZMQ_DEALER);
97+ assert (client);
98+ int rc = zmq_setsockopt (server, ZMQ_ZAP_DOMAIN, " TEST" , 5 );
99+ assert (rc == 0 );
100+ rc = zmq_bind (server, " tcp://127.0.0.1:*" );
101+ assert (rc == 0 );
102+ rc = zmq_getsockopt (server, ZMQ_LAST_ENDPOINT, my_endpoint, &len);
103+ assert (rc == 0 );
104+ rc = zmq_connect (client, my_endpoint);
105+ assert (rc == 0 );
106+ bounce (server, client);
107+ close_zero_linger (client);
108+ close_zero_linger (server);
109+
110+ #ifdef ZMQ_ZAP_ENFORCE_DOMAIN
111+ // Now set ZMQ_ZAP_ENFORCE_DOMAIN which strictly enforces the ZAP
112+ // RFC but is backward-incompatible, now it should fail
113+ server = zmq_socket (ctx, ZMQ_DEALER);
114+ assert (server);
115+ client = zmq_socket (ctx, ZMQ_DEALER);
116+ assert (client);
117+ int required = 1 ;
118+ rc =
119+ zmq_setsockopt (server, ZMQ_ZAP_ENFORCE_DOMAIN, &required, sizeof (int ));
120+ assert (rc == 0 );
121+ rc = zmq_setsockopt (server, ZMQ_ZAP_DOMAIN, " TEST" , 5 );
122+ assert (rc == 0 );
123+ rc = zmq_bind (server, " tcp://127.0.0.1:*" );
124+ assert (rc == 0 );
125+ rc = zmq_getsockopt (server, ZMQ_LAST_ENDPOINT, my_endpoint, &len);
126+ assert (rc == 0 );
127+ rc = zmq_connect (client, my_endpoint);
128+ assert (rc == 0 );
129+ expect_bounce_fail (server, client);
130+ close_zero_linger (client);
131+ close_zero_linger (server);
132+ #endif
133+
91134 // Spawn ZAP handler
92135 // We create and bind ZAP socket in main thread to avoid case
93136 // where child thread does not start up fast enough.
94137 void *handler = zmq_socket (ctx, ZMQ_REP);
95138 assert (handler);
96- int rc = zmq_bind (handler, " inproc://zeromq.zap.01" );
139+ rc = zmq_bind (handler, " inproc://zeromq.zap.01" );
97140 assert (rc == 0 );
98141 void *zap_thread = zmq_threadstart (&zap_handler, handler);
99142
100143 // We bounce between a binding server and a connecting client
101144
102145 // We first test client/server with no ZAP domain
103146 // Libzmq does not call our ZAP handler, the connect must succeed
104- void * server = zmq_socket (ctx, ZMQ_DEALER);
147+ server = zmq_socket (ctx, ZMQ_DEALER);
105148 assert (server);
106- void * client = zmq_socket (ctx, ZMQ_DEALER);
149+ client = zmq_socket (ctx, ZMQ_DEALER);
107150 assert (client);
108151 rc = zmq_bind (server, " tcp://127.0.0.1:*" );
109152 assert (rc == 0 );
0 commit comments