diff --git a/include/libwebsockets/lws-client.h b/include/libwebsockets/lws-client.h index b8693f181..4b5db85ed 100644 --- a/include/libwebsockets/lws-client.h +++ b/include/libwebsockets/lws-client.h @@ -61,6 +61,17 @@ enum lws_client_connect_ssl_connection_flags { LCCSCF_H2_PRIOR_KNOWLEDGE = (1 << 18), LCCSCF_WAKE_SUSPEND__VALIDITY = (1 << 19), /* our validity checks are important enough to wake from suspend */ + LCCSCF_PRIORITIZE_READS = (1 << 20), + /**< + * Normally lws balances reads and writes on all connections, so both + * are possible even on busy connections, and we go around the event + * loop more often to facilitate that, even if there is pending data. + * + * This flag indicates that you want to handle any pending reads on this + * connection without yielding the service loop for anything else. This + * means you may block other connection processing in favour of incoming + * data processing on this one if it receives back to back incoming rx. + */ }; /** struct lws_client_connect_info - parameters to connect with when using diff --git a/lib/roles/ws/ops-ws.c b/lib/roles/ws/ops-ws.c index e7cd5947d..17882edc7 100644 --- a/lib/roles/ws/ops-ws.c +++ b/lib/roles/ws/ops-ws.c @@ -1209,6 +1209,13 @@ drain: } pending = lws_ssl_pending(wsi); + +#if defined(LWS_WITH_CLIENT) + if (!pending && (wsi->flags & LCCSCF_PRIORITIZE_READS) && + lws_buflist_total_len(&wsi->buflist)) + pending = 9999999; +#endif + if (pending) { if (lws_is_ws_with_ext(wsi)) pending = pending > wsi->ws->rx_ubuf_alloc ?