diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 94608202..03c37c26 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -485,6 +485,11 @@ just_kill_connection: #ifdef LWS_OPENSSL_SUPPORT } #endif + + /* outermost destroy notification for wsi (user_space still intact) */ + context->protocols[0].callback(context, wsi, + LWS_CALLBACK_WSI_DESTROY, wsi->user_space, NULL, 0); + if (wsi->protocol && wsi->protocol->per_session_data_size && wsi->user_space) /* user code may own */ free(wsi->user_space); diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index e6c607f8..a1af4b86 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -182,6 +182,8 @@ enum libwebsocket_callback_reasons { LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED, LWS_CALLBACK_PROTOCOL_INIT, LWS_CALLBACK_PROTOCOL_DESTROY, + LWS_CALLBACK_WSI_CREATE, /* always protocol[0] */ + LWS_CALLBACK_WSI_DESTROY, /* always protocol[0] */ LWS_CALLBACK_GET_THREAD_ID, /* external poll() management support */ @@ -680,6 +682,10 @@ struct libwebsocket_extension; * context is getting destroyed. Take the opportunity to * deallocate everything that was allocated by the protocol. * + * LWS_CALLBACK_WSI_CREATE: outermost (earliest) wsi create notification + * + * LWS_CALLBACK_WSI_DESTROY: outermost (latest) wsi destroy notification + * * The next four reasons are optional and only need taking care of if you * will be integrating libwebsockets sockets into an external polling * array. diff --git a/lib/server.c b/lib/server.c index dcb6cc19..62691851 100644 --- a/lib/server.c +++ b/lib/server.c @@ -119,6 +119,13 @@ libwebsocket_create_new_server_wsi(struct libwebsocket_context *context) new_wsi->user_space = NULL; new_wsi->ietf_spec_revision = 0; + /* + * outermost create notification for wsi + * no user_space because no protocol selection + */ + context->protocols[0].callback(context, new_wsi, + LWS_CALLBACK_WSI_CREATE, NULL, NULL, 0); + return new_wsi; }