mirror of
				https://github.com/zeromq/libzmq.git
				synced 2025-11-04 04:10:00 +01:00 
			
		
		
		
	@@ -64,6 +64,16 @@ static void zap_handler_disconnect (void *ctx)
 | 
			
		||||
    zap_handler_generic (ctx, zap_disconnect);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void zap_handler_do_not_recv (void *ctx)
 | 
			
		||||
{
 | 
			
		||||
    zap_handler_generic (ctx, zap_do_not_recv);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void zap_handler_do_not_send (void *ctx)
 | 
			
		||||
{
 | 
			
		||||
    zap_handler_generic (ctx, zap_do_not_send);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int expect_new_client_bounce_fail_and_count_monitor_events (
 | 
			
		||||
  void *ctx,
 | 
			
		||||
  char *my_endpoint,
 | 
			
		||||
@@ -344,8 +354,42 @@ void test_zap_errors (socket_config_fn server_socket_config_,
 | 
			
		||||
      0, 0,
 | 
			
		||||
#endif
 | 
			
		||||
      client_socket_config_, client_socket_config_data_);
 | 
			
		||||
    shutdown_context_and_server_side(ctx, zap_thread, server, server_mon,
 | 
			
		||||
        handler, true);
 | 
			
		||||
    shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
 | 
			
		||||
                                      handler, true);
 | 
			
		||||
 | 
			
		||||
    //  ZAP handler does not read request
 | 
			
		||||
    fprintf (stderr,
 | 
			
		||||
             "test_zap_unsuccessful ZAP handler does not read request\n");
 | 
			
		||||
    setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
 | 
			
		||||
        &server_mon, my_endpoint, &zap_handler_do_not_recv,
 | 
			
		||||
        server_socket_config_);
 | 
			
		||||
    test_zap_unsuccessful_no_handler (
 | 
			
		||||
      ctx, my_endpoint, server, server_mon,
 | 
			
		||||
#ifdef ZMQ_BUILD_DRAFT_API
 | 
			
		||||
      ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, EPIPE,
 | 
			
		||||
#else
 | 
			
		||||
      0, 0,
 | 
			
		||||
#endif
 | 
			
		||||
      client_socket_config_, client_socket_config_data_);
 | 
			
		||||
    shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
 | 
			
		||||
                                      handler);
 | 
			
		||||
 | 
			
		||||
    //  ZAP handler does not send reply
 | 
			
		||||
    fprintf (stderr,
 | 
			
		||||
             "test_zap_unsuccessful ZAP handler does not write reply\n");
 | 
			
		||||
    setup_context_and_server_side (
 | 
			
		||||
      &ctx, &handler, &zap_thread, &server, &server_mon, my_endpoint,
 | 
			
		||||
      &zap_handler_do_not_send, server_socket_config_);
 | 
			
		||||
    test_zap_unsuccessful_no_handler (
 | 
			
		||||
      ctx, my_endpoint, server, server_mon,
 | 
			
		||||
#ifdef ZMQ_BUILD_DRAFT_API
 | 
			
		||||
      ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, EPIPE,
 | 
			
		||||
#else
 | 
			
		||||
      0, 0,
 | 
			
		||||
#endif
 | 
			
		||||
      client_socket_config_, client_socket_config_data_);
 | 
			
		||||
    shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
 | 
			
		||||
                                      handler);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main (void)
 | 
			
		||||
 
 | 
			
		||||
@@ -154,7 +154,9 @@ enum zap_protocol_t
 | 
			
		||||
    zap_wrong_request_id,
 | 
			
		||||
    zap_status_invalid,
 | 
			
		||||
    zap_too_many_parts,
 | 
			
		||||
    zap_disconnect
 | 
			
		||||
    zap_disconnect,
 | 
			
		||||
    zap_do_not_recv,
 | 
			
		||||
    zap_do_not_send
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void *zap_requests_handled;
 | 
			
		||||
@@ -182,8 +184,11 @@ void zap_handler_generic (void *ctx,
 | 
			
		||||
      {handler, 0, ZMQ_POLLIN, 0},
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    // if ordered not to receive the request, ignore the second poll item
 | 
			
		||||
    const int numitems = (zap_protocol == zap_do_not_recv) ? 1 : 2;
 | 
			
		||||
 | 
			
		||||
    //  Process ZAP requests forever
 | 
			
		||||
    while (zmq_poll (items, 2, -1) >= 0) {
 | 
			
		||||
    while (zmq_poll (items, numitems, -1) >= 0) {
 | 
			
		||||
        if (items[0].revents & ZMQ_POLLIN) {
 | 
			
		||||
            char *buf = s_recv (control);
 | 
			
		||||
            assert (buf);
 | 
			
		||||
@@ -198,7 +203,10 @@ void zap_handler_generic (void *ctx,
 | 
			
		||||
        if (!version)
 | 
			
		||||
            break; //  Terminating - peer's socket closed
 | 
			
		||||
        if (zap_protocol == zap_disconnect)
 | 
			
		||||
        {
 | 
			
		||||
            free (version);
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        char *sequence = s_recv (handler);
 | 
			
		||||
        char *domain = s_recv (handler);
 | 
			
		||||
@@ -268,12 +276,14 @@ void zap_handler_generic (void *ctx,
 | 
			
		||||
            if (zap_protocol == zap_too_many_parts) {
 | 
			
		||||
                s_sendmore (handler, "");
 | 
			
		||||
            }
 | 
			
		||||
            s_send (handler, "");
 | 
			
		||||
            if (zap_protocol != zap_do_not_send)
 | 
			
		||||
                s_send (handler, "");
 | 
			
		||||
        } else {
 | 
			
		||||
            s_sendmore (handler, "400");
 | 
			
		||||
            s_sendmore (handler, "Invalid client public key");
 | 
			
		||||
            s_sendmore (handler, "");
 | 
			
		||||
            s_send (handler, "");
 | 
			
		||||
            if (zap_protocol != zap_do_not_send)
 | 
			
		||||
                s_send(handler, "");
 | 
			
		||||
        }
 | 
			
		||||
        free (version);
 | 
			
		||||
        free (sequence);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user