diff --git a/nsock/src/nsock_event.c b/nsock/src/nsock_event.c index 54365dc25..6e8250756 100644 --- a/nsock/src/nsock_event.c +++ b/nsock/src/nsock_event.c @@ -199,6 +199,7 @@ int nsock_event_cancel(nsock_pool ms_pool, nsock_event_id id, int notify) { /* First we figure out what list it is in */ switch (type) { case NSE_TYPE_CONNECT: + case NSE_TYPE_CONNECT_SSL: event_list = &nsp->connect_events; break; diff --git a/nsock/tests/basic.c b/nsock/tests/basic.c index 65ae2e2e0..cb11d58f3 100644 --- a/nsock/tests/basic.c +++ b/nsock/tests/basic.c @@ -42,6 +42,62 @@ static int basic_udata(void *tdata) { return 0; } + +static void cancel_handler(nsock_pool nsp, nsock_event nse, void *udata) { + int *ev_done = (int *)udata; + + if (nse_status(nse) == NSE_STATUS_CANCELLED) + *ev_done = 1; +} + +static int cancel_setup(void **tdata) { + struct basic_test_data *btd; + + btd = calloc(1, sizeof(struct basic_test_data)); + if (btd == NULL) + return -ENOMEM; + + btd->nsp = nsp_new(NULL); + + *tdata = btd; + return 0; +} + +static int cancel_teardown(void *tdata) { + struct basic_test_data *btd = (struct basic_test_data *)tdata; + + if (tdata) { + nsp_delete(btd->nsp); + free(tdata); + } + return 0; +} + +static int cancel_run(void *tdata) { + struct basic_test_data *btd = (struct basic_test_data *)tdata; + struct sockaddr_in peer; + nsock_iod iod; + nsock_event_id id; + int done = 0; + + iod = nsi_new(btd->nsp, NULL); + AssertNonNull(iod); + + memset(&peer, 0, sizeof(peer)); + peer.sin_family = AF_INET; + inet_aton("127.0.0.1", &peer.sin_addr); + + id = nsock_connect_ssl(btd->nsp, iod, cancel_handler, 4000, (void *)&done, + (struct sockaddr *)&peer, sizeof(peer), IPPROTO_TCP, + PORT_TCPSSL, NULL); + nsock_event_cancel(btd->nsp, id, 1); + + nsi_delete(iod, NSOCK_PENDING_SILENT); + + return (done == 1) ? 0 : -ENOEXEC; +} + + const struct test_case TestPoolUserData = { .t_name = "nsock pool user data", .t_setup = basic_setup, @@ -49,4 +105,10 @@ const struct test_case TestPoolUserData = { .t_teardown = basic_teardown }; +const struct test_case TestCancelSSLOperation = { + .t_name = "schedule and cancel SSL connect", + .t_setup = cancel_setup, + .t_run = cancel_run, + .t_teardown = cancel_teardown +}; diff --git a/nsock/tests/tests_main.c b/nsock/tests/tests_main.c index 27d024a03..ac7cda373 100644 --- a/nsock/tests/tests_main.c +++ b/nsock/tests/tests_main.c @@ -26,6 +26,7 @@ char *socket_strerror(int errnum); extern const struct test_case TestPoolUserData; +extern const struct test_case TestCancelOperation; extern const struct test_case TestTimer; extern const struct test_case TestLogLevels; extern const struct test_case TestErrLevels; @@ -38,6 +39,7 @@ extern const struct test_case TestHeapOrdering; static const struct test_case *TestCases[] = { /* ---- basic.c */ &TestPoolUserData, + &TestCancelOperation, /* ---- timer.c */ &TestTimer, /* ---- logs.c */