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

ping allow zero length PING

Part of

https://github.com/warmcat/libwebsockets/issues/256

Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
Andy Green 2015-03-24 21:07:01 +08:00
parent 1677ca52ca
commit 2fd6e6fb55
4 changed files with 8 additions and 4 deletions

View file

@ -235,6 +235,7 @@ just_kill_connection:
lws_free2(wsi->u.ws.ping_payload_buf);
wsi->u.ws.ping_payload_alloc = 0;
wsi->u.ws.ping_payload_len = 0;
wsi->u.ws.ping_pending_flag = 0;
}
}

View file

@ -876,7 +876,7 @@ spill:
lwsl_info("received %d byte ping, sending pong\n",
wsi->u.ws.rx_user_buffer_head);
if (wsi->u.ws.ping_payload_len) {
if (wsi->u.ws.ping_pending_flag) {
/*
* there is already a pending ping payload
* we should just log and drop
@ -910,6 +910,7 @@ spill:
wsi->u.ws.rx_user_buffer_head);
wsi->u.ws.ping_payload_len = wsi->u.ws.rx_user_buffer_head;
wsi->u.ws.ping_pending_flag = 1;
/* get it sent as soon as possible */
libwebsocket_callback_on_writable(wsi->protocol->owning_server, wsi);

View file

@ -794,7 +794,8 @@ struct _lws_websocket_related {
unsigned char *ping_payload_buf; /* non-NULL if malloc'd */
unsigned int ping_payload_alloc; /* length malloc'd */
unsigned int ping_payload_len; /* nonzero if PONG pending */
unsigned int ping_payload_len;
unsigned char ping_pending_flag;
};
struct libwebsocket {

View file

@ -92,7 +92,8 @@ lws_handle_POLLOUT_event(struct libwebsocket_context *context,
#endif
/* pending control packets have next priority */
if (wsi->state == WSI_STATE_ESTABLISHED && wsi->u.ws.ping_payload_len) {
if (wsi->state == WSI_STATE_ESTABLISHED &&
wsi->u.ws.ping_pending_flag) {
n = libwebsocket_write(wsi,
&wsi->u.ws.ping_payload_buf[
LWS_SEND_BUFFER_PRE_PADDING],
@ -101,7 +102,7 @@ lws_handle_POLLOUT_event(struct libwebsocket_context *context,
if (n < 0)
return -1;
/* well he is sent, mark him done */
wsi->u.ws.ping_payload_len = 0;
wsi->u.ws.ping_pending_flag = 0;
/* leave POLLOUT active either way */
return 0;
}