diff --git a/lib/client.c b/lib/client.c index 6422fb7b..576c7ff1 100644 --- a/lib/client.c +++ b/lib/client.c @@ -596,8 +596,7 @@ check_accept: } /* allocate the per-connection user memory (if any) */ - if (wsi->protocol->per_session_data_size && - !libwebsocket_ensure_user_space(wsi)) { + if (libwebsocket_ensure_user_space(wsi)) { lwsl_err("Problem allocating wsi user mem\n"); goto bail2; } diff --git a/lib/handshake.c b/lib/handshake.c index b21d73db..50138dd8 100644 --- a/lib/handshake.c +++ b/lib/handshake.c @@ -122,7 +122,7 @@ libwebsocket_read(struct libwebsocket_context *context, lwsl_info("HTTP request for '%s'\n", lws_hdr_simple_ptr(wsi, WSI_TOKEN_GET_URI)); - if (libwebsocket_ensure_user_space(wsi) == NULL) { + if (libwebsocket_ensure_user_space(wsi)) { /* drop the header info */ if (wsi->u.hdr.ah) free(wsi->u.hdr.ah); diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 849ffb44..65adcf5a 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -2154,16 +2154,11 @@ libwebsocket_get_reserved_bits(struct libwebsocket *wsi) return wsi->u.ws.rsv; } -/** - * libwebsocket_ensure_user_space(): return the user context for the connection if possible - * @wsi: websocket connection instance - */ - -void * +int libwebsocket_ensure_user_space(struct libwebsocket *wsi) { if (!wsi->protocol) - return NULL; + return 1; /* allocate the per-connection user memory (if any) */ @@ -2172,12 +2167,12 @@ libwebsocket_ensure_user_space(struct libwebsocket *wsi) wsi->protocol->per_session_data_size); if (wsi->user_space == NULL) { lwsl_err("Out of memory for conn user space\n"); - return NULL; + return 1; } memset(wsi->user_space, 0, wsi->protocol->per_session_data_size); } - return wsi->user_space; + return 0; } static void lwsl_emit_stderr(int level, const char *line) diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index e1c04cc4..779af2ed 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -880,9 +880,6 @@ libwebsocket_is_final_fragment(struct libwebsocket *wsi); LWS_EXTERN unsigned char libwebsocket_get_reserved_bits(struct libwebsocket *wsi); -LWS_EXTERN void * -libwebsocket_ensure_user_space(struct libwebsocket *wsi); - LWS_EXTERN int libwebsocket_rx_flow_control(struct libwebsocket *wsi, int enable); diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index 6c2ae74f..3bde4918 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -508,6 +508,9 @@ LWS_EXTERN int lws_hdr_simple_create(struct libwebsocket *wsi, enum lws_token_indexes h, const char *s); +LWS_EXTERN int +libwebsocket_ensure_user_space(struct libwebsocket *wsi); + #ifndef LWS_NO_SERVER LWS_EXTERN int handshake_0405(struct libwebsocket_context *context, struct libwebsocket *wsi); diff --git a/lib/server-handshake.c b/lib/server-handshake.c index 627fb31b..75938fe9 100644 --- a/lib/server-handshake.c +++ b/lib/server-handshake.c @@ -75,8 +75,7 @@ handshake_0405(struct libwebsocket_context *context, struct libwebsocket *wsi) } /* allocate the per-connection user memory (if any) */ - if (wsi->protocol->per_session_data_size && - !libwebsocket_ensure_user_space(wsi)) + if (libwebsocket_ensure_user_space(wsi)) goto bail; /* create the response packet */ diff --git a/libwebsockets-api-doc.html b/libwebsockets-api-doc.html index 306f18e6..c0ea6cd3 100644 --- a/libwebsockets-api-doc.html +++ b/libwebsockets-api-doc.html @@ -382,16 +382,6 @@ Some apis can act on all live connections of a given protocol, this is how you can get a pointer to the active protocol if needed.