diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index 487c9699..ff0c91fd 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -524,48 +524,7 @@ lws_latency(struct libwebsocket_context *context, struct libwebsocket *wsi, } #endif -#ifdef LWS_NO_SERVER -int -_libwebsocket_rx_flow_control(struct libwebsocket *wsi) -{ - return 0; -} -#else -int -_libwebsocket_rx_flow_control(struct libwebsocket *wsi) -{ - struct libwebsocket_context *context = wsi->protocol->owning_server; - /* there is no pending change */ - if (!(wsi->u.ws.rxflow_change_to & LWS_RXFLOW_PENDING_CHANGE)) - return 0; - - /* stuff is still buffered, not ready to really accept new input */ - if (wsi->u.ws.rxflow_buffer) { - /* get ourselves called back to deal with stashed buffer */ - libwebsocket_callback_on_writable(context, wsi); - return 0; - } - - /* pending is cleared, we can change rxflow state */ - - wsi->u.ws.rxflow_change_to &= ~LWS_RXFLOW_PENDING_CHANGE; - - lwsl_info("rxflow: wsi %p change_to %d\n", wsi, - wsi->u.ws.rxflow_change_to & LWS_RXFLOW_ALLOW); - - /* adjust the pollfd for this wsi */ - - if (wsi->u.ws.rxflow_change_to & LWS_RXFLOW_ALLOW) { - if (lws_change_pollfd(wsi, 0, LWS_POLLIN)) - return -1; - } else - if (lws_change_pollfd(wsi, LWS_POLLIN, 0)) - return -1; - - return 1; -} -#endif /** * libwebsocket_rx_flow_control() - Enable and disable socket servicing for diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index 8d1a66f0..c7b6c05d 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -756,6 +756,9 @@ LWS_EXTERN int openssl_websocket_private_data_index; LWS_EXTERN int lws_server_socket_service( struct libwebsocket_context *context, struct libwebsocket *wsi, struct libwebsocket_pollfd *pollfd); + LWS_EXTERN int _libwebsocket_rx_flow_control(struct libwebsocket *wsi); +#else +#define _libwebsocket_rx_flow_control(_a) (0) #endif /* diff --git a/lib/server.c b/lib/server.c index cc921fef..093e28e1 100644 --- a/lib/server.c +++ b/lib/server.c @@ -128,6 +128,41 @@ int lws_context_init_server(struct lws_context_creation_info *info, return 0; } +int +_libwebsocket_rx_flow_control(struct libwebsocket *wsi) +{ + struct libwebsocket_context *context = wsi->protocol->owning_server; + + /* there is no pending change */ + if (!(wsi->u.ws.rxflow_change_to & LWS_RXFLOW_PENDING_CHANGE)) + return 0; + + /* stuff is still buffered, not ready to really accept new input */ + if (wsi->u.ws.rxflow_buffer) { + /* get ourselves called back to deal with stashed buffer */ + libwebsocket_callback_on_writable(context, wsi); + return 0; + } + + /* pending is cleared, we can change rxflow state */ + + wsi->u.ws.rxflow_change_to &= ~LWS_RXFLOW_PENDING_CHANGE; + + lwsl_info("rxflow: wsi %p change_to %d\n", wsi, + wsi->u.ws.rxflow_change_to & LWS_RXFLOW_ALLOW); + + /* adjust the pollfd for this wsi */ + + if (wsi->u.ws.rxflow_change_to & LWS_RXFLOW_ALLOW) { + if (lws_change_pollfd(wsi, 0, LWS_POLLIN)) + return -1; + } else + if (lws_change_pollfd(wsi, LWS_POLLIN, 0)) + return -1; + + return 1; +} + #ifdef LWS_OPENSSL_SUPPORT static void diff --git a/lib/service.c b/lib/service.c index 9b23c16d..fabe7829 100644 --- a/lib/service.c +++ b/lib/service.c @@ -454,7 +454,7 @@ drain: free(wsi->u.ws.rxflow_buffer); wsi->u.ws.rxflow_buffer = NULL; /* having drained the rxflow buffer, can rearm POLLIN */ - _libwebsocket_rx_flow_control(wsi); + n = _libwebsocket_rx_flow_control(wsi); /* n ignored, needed for NO_SERVER case */ } #ifdef LWS_OPENSSL_SUPPORT