1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

introduce lws_partial_buffered

Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
Andy Green 2014-08-18 22:49:39 +08:00
parent 822241c2a7
commit 14425eae4e
4 changed files with 38 additions and 2 deletions

View file

@ -21,6 +21,12 @@ over ssl or not. If LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT is used, both
ssl and non-ssl connections are possible and may need to be treated differently
in the user code.
int lws_partial_buffered(wsi) added... should be checked after any
libwebsocket_write that will be followed by another libwebsocket_write inside
the same writeable callback. If set, you can't do any more writes until the
writeable callback is called again. If you only do one write per writeable callback,
you can ignore this.
User api removal
----------------

View file

@ -769,3 +769,26 @@ lws_is_ssl(struct libwebsocket *wsi)
{
return wsi->use_ssl;
}
/**
* lws_partial_buffered() - find out if lws buffered the last write
* @wsi: websocket connection to check
*
* Returns 1 if you cannot use libwebsocket_write because the last
* write on this connection is still buffered, and can't be cleared without
* returning to the service loop and waiting for the connection to be
* writeable again.
*
* If you will try to do >1 libwebsocket_write call inside a single
* WRITEABLE callback, you must check this after every write and bail if
* set, ask for a new writeable callback and continue writing from there.
*
* This is never set at the start of a writeable callback, but any write
* may set it.
*/
LWS_VISIBLE int
lws_partial_buffered(struct libwebsocket *wsi)
{
return !!wsi->truncated_send_len;
}

View file

@ -1169,6 +1169,9 @@ lws_daemonize(const char *_lock_path);
LWS_VISIBLE LWS_EXTERN int
lws_send_pipe_choked(struct libwebsocket *wsi);
LWS_VISIBLE LWS_EXTERN int
lws_partial_buffered(struct libwebsocket *wsi);
LWS_VISIBLE LWS_EXTERN int
lws_frame_is_binary(struct libwebsocket *wsi);

View file

@ -386,13 +386,17 @@ static int callback_http(struct libwebsocket_context *context,
if (m) /* while still active, extend timeout */
libwebsocket_set_timeout(wsi,
PENDING_TIMEOUT_HTTP_CONTENT, 5);
/* if he has indigestion, let him clear it before eating more */
if (lws_partial_buffered(wsi))
break;
} while (!lws_send_pipe_choked(wsi));
libwebsocket_callback_on_writable(context, wsi);
break;
flush_bail:
/* true if still partial pending */
if (lws_send_pipe_choked(wsi)) {
if (lws_partial_buffered(wsi)) {
libwebsocket_callback_on_writable(context, wsi);
break;
}
@ -632,7 +636,7 @@ callback_lws_mirror(struct libwebsocket_context *context,
// lwsl_debug("tx fifo %d\n", (ringbuffer_head - pss->ringbuffer_tail) & (MAX_MESSAGE_QUEUE - 1));
if (lws_send_pipe_choked(wsi)) {
if (lws_partial_buffered(wsi) || lws_send_pipe_choked(wsi)) {
libwebsocket_callback_on_writable(context, wsi);
break;
}