diff --git a/lib/client-handshake.c b/lib/client-handshake.c index 3b57bd9e..c3b7cecc 100644 --- a/lib/client-handshake.c +++ b/lib/client-handshake.c @@ -21,6 +21,9 @@ libwebsocket_client_close(struct libwebsocket *wsi) int n = wsi->state; struct libwebsocket_context *clients; + if (n == WSI_STATE_DEAD_SOCKET) + return; + /* mark the WSI as dead and let the callback know */ wsi->state = WSI_STATE_DEAD_SOCKET; diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 989e5646..403a7f68 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -222,8 +222,11 @@ libwebsocket_context_destroy(struct libwebsocket_context *this) int client; /* close listening skt and per-protocol broadcast sockets */ - for (client = 0; client < this->fds_count; client++) - libwebsocket_close_and_free_session(this->wsi[client]); + for (client = this->count_protocols + 1; client < this->fds_count; client++) + if (this->wsi[client]->client_mode) + libwebsocket_client_close(this->wsi[client]); + else + libwebsocket_close_and_free_session(this->wsi[client]); #ifdef LWS_OPENSSL_SUPPORT if (this->ssl_ctx) diff --git a/test-server/test-client.c b/test-server/test-client.c index 289374aa..b5033431 100644 --- a/test-server/test-client.c +++ b/test-server/test-client.c @@ -243,9 +243,6 @@ int main(int argc, char **argv) while (n >= 0) n = libwebsocket_service(context, 1000); - libwebsocket_client_close(wsi_dumb); - libwebsocket_client_close(wsi_mirror); - libwebsocket_context_destroy(context); return 0; diff --git a/test-server/test-ping.c b/test-server/test-ping.c index 7b901ec3..b2a8684a 100644 --- a/test-server/test-ping.c +++ b/test-server/test-ping.c @@ -489,12 +489,6 @@ int main(int argc, char **argv) ((double)global_rx_count * (double)size) / ((double)(l - started) / 1000000.0) / 1024.0); -// return 0; -fprintf(stderr, "a\n"); - for (n = 0; n < clients; n++) - libwebsocket_client_close(wsi[n]); - -fprintf(stderr, "b\n"); libwebsocket_context_destroy(context); return 0;