From 6a98054a36d65f9f9b6e50040bd19cb963619a99 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Sun, 30 Jan 2011 20:40:32 +0000 Subject: [PATCH] fix-context-close.patch Signed-off-by: Andy Green --- lib/client-handshake.c | 3 +++ lib/libwebsockets.c | 7 +++++-- test-server/test-client.c | 3 --- test-server/test-ping.c | 6 ------ 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/client-handshake.c b/lib/client-handshake.c index 3b57bd9..c3b7cec 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 989e564..403a7f6 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 289374a..b503343 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 7b901ec..b2a8684 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; -- 2.7.4