Skip to content
Snippets Groups Projects
Commit d99476b2 authored by Andy Green's avatar Andy Green
Browse files

refactor move flow control to server.c

parent e38031a3
Branches
Tags
No related merge requests found
...@@ -524,48 +524,7 @@ lws_latency(struct libwebsocket_context *context, struct libwebsocket *wsi, ...@@ -524,48 +524,7 @@ lws_latency(struct libwebsocket_context *context, struct libwebsocket *wsi,
} }
#endif #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 * libwebsocket_rx_flow_control() - Enable and disable socket servicing for
......
...@@ -756,6 +756,9 @@ LWS_EXTERN int openssl_websocket_private_data_index; ...@@ -756,6 +756,9 @@ LWS_EXTERN int openssl_websocket_private_data_index;
LWS_EXTERN int lws_server_socket_service( LWS_EXTERN int lws_server_socket_service(
struct libwebsocket_context *context, struct libwebsocket_context *context,
struct libwebsocket *wsi, struct libwebsocket_pollfd *pollfd); 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 #endif
/* /*
......
...@@ -128,6 +128,41 @@ int lws_context_init_server(struct lws_context_creation_info *info, ...@@ -128,6 +128,41 @@ int lws_context_init_server(struct lws_context_creation_info *info,
return 0; 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 #ifdef LWS_OPENSSL_SUPPORT
static void static void
......
...@@ -454,7 +454,7 @@ drain: ...@@ -454,7 +454,7 @@ drain:
free(wsi->u.ws.rxflow_buffer); free(wsi->u.ws.rxflow_buffer);
wsi->u.ws.rxflow_buffer = NULL; wsi->u.ws.rxflow_buffer = NULL;
/* having drained the rxflow buffer, can rearm POLLIN */ /* 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 #ifdef LWS_OPENSSL_SUPPORT
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment