diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 13a18c68..15b59f43 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -1425,8 +1425,13 @@ bail3: free(wsi->c_protocol); bail2: + if (wsi->c_callback) wsi->c_callback(context, wsi, + LWS_CALLBACK_CLIENT_CONNECTION_ERROR, + wsi->user_space, + NULL, 0); libwebsocket_close_and_free_session(context, wsi, - LWS_CLOSE_STATUS_NOSTATUS); + LWS_CLOSE_STATUS_NOSTATUS); // But this should be LWS_CLOSE_STATUS_PROTOCOL_ERR + return 1; } diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index a26df437..f8bfda4c 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -65,6 +65,7 @@ enum libwebsocket_context_options { enum libwebsocket_callback_reasons { LWS_CALLBACK_ESTABLISHED, + LWS_CALLBACK_CLIENT_CONNECTION_ERROR, LWS_CALLBACK_CLIENT_ESTABLISHED, LWS_CALLBACK_CLOSED, LWS_CALLBACK_RECEIVE, @@ -249,7 +250,10 @@ struct libwebsocket_extension; * LWS_CALLBACK_ESTABLISHED: after the server completes a handshake with * an incoming client * - * LWS_CALLBACK_CLIENT_ESTABLISHED: after your client connection completed + * LWS_CALLBACK_CLIENT_CONNECTION_ERROR: the request client connection has + * been unable to complete a handshake with the remote server + * + * LWS_CALLBACK_CLIENT_ESTABLISHED: after your client connection completed * a handshake with the remote server * * LWS_CALLBACK_CLOSED: when the websocket session ends