update ping test client and stop exposing payload to extensions
Ping and Pong payload in control messages need to be above the fray of extension payload munging Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
parent
cf3590e460
commit
f7248f8dfa
6 changed files with 35 additions and 13 deletions
|
@ -34,7 +34,7 @@ int libwebsocket_client_rx_sm(struct libwebsocket *wsi, unsigned char c)
|
|||
struct lws_tokens eff_buf;
|
||||
int m;
|
||||
|
||||
lwsl_parser(" CRX: %02X %d\n", c, wsi->lws_rx_parse_state);
|
||||
// lwsl_parser(" CRX: %02X %d\n", c, wsi->lws_rx_parse_state);
|
||||
|
||||
switch (wsi->lws_rx_parse_state) {
|
||||
case LWS_RXPS_NEW:
|
||||
|
@ -401,6 +401,7 @@ spill:
|
|||
return -1;
|
||||
|
||||
case LWS_WS_OPCODE_07__PING:
|
||||
lwsl_info("client received ping, doing pong\n");
|
||||
/* parrot the ping packet payload back as a pong*/
|
||||
n = libwebsocket_write(wsi, (unsigned char *)
|
||||
&wsi->rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING],
|
||||
|
@ -409,6 +410,9 @@ spill:
|
|||
break;
|
||||
|
||||
case LWS_WS_OPCODE_07__PONG:
|
||||
lwsl_info("client receied pong\n");
|
||||
lwsl_hexdump(&wsi->rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING],
|
||||
wsi->rx_user_buffer_head);
|
||||
/* keep the statistics... */
|
||||
wsi->pings_vs_pongs--;
|
||||
|
||||
|
@ -486,7 +490,9 @@ spill:
|
|||
if (eff_buf.token_len > 0) {
|
||||
eff_buf.token[eff_buf.token_len] = '\0';
|
||||
|
||||
if (wsi->protocol->callback)
|
||||
if (wsi->protocol->callback) {
|
||||
if (callback_action == LWS_CALLBACK_CLIENT_RECEIVE_PONG)
|
||||
lwsl_info("Client doing pong callback\n");
|
||||
wsi->protocol->callback(
|
||||
wsi->protocol->owning_server,
|
||||
wsi,
|
||||
|
@ -494,6 +500,7 @@ spill:
|
|||
wsi->user_space,
|
||||
eff_buf.token,
|
||||
eff_buf.token_len);
|
||||
}
|
||||
}
|
||||
already_done:
|
||||
wsi->rx_user_buffer_head = 0;
|
||||
|
|
|
@ -562,6 +562,9 @@ libwebsocket_read(struct libwebsocket_context *context,
|
|||
#endif
|
||||
|
||||
#ifndef LWS_NO_CLIENT
|
||||
|
||||
// lwsl_info("mode=%d\n", wsi->mode);
|
||||
|
||||
switch (wsi->mode) {
|
||||
case LWS_CONNMODE_WS_CLIENT_WAITING_PROXY_REPLY:
|
||||
case LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE:
|
||||
|
|
|
@ -306,9 +306,11 @@ just_kill_connection:
|
|||
|
||||
/* delete it from the internal poll list if still present */
|
||||
|
||||
m = 0;
|
||||
for (n = 0; n < context->fds_count; n++) {
|
||||
if (context->fds[n].fd != wsi->sock)
|
||||
continue;
|
||||
m = 1;
|
||||
while (n < context->fds_count - 1) {
|
||||
context->fds[n] = context->fds[n + 1];
|
||||
n++;
|
||||
|
@ -318,6 +320,9 @@ just_kill_connection:
|
|||
n = context->fds_count;
|
||||
}
|
||||
|
||||
if (!m)
|
||||
lwsl_err("Failed to remove fd %d from fds array\n", wsi->sock);
|
||||
|
||||
/* remove also from external POLL support via protocol 0 */
|
||||
if (wsi->sock)
|
||||
context->protocols[0].callback(context, wsi,
|
||||
|
|
21
lib/output.c
21
lib/output.c
|
@ -312,14 +312,17 @@ int libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf,
|
|||
eff_buf.token = (char *)buf;
|
||||
eff_buf.token_len = len;
|
||||
|
||||
for (n = 0; n < wsi->count_active_extensions; n++) {
|
||||
m = wsi->active_extensions[n]->callback(
|
||||
wsi->protocol->owning_server,
|
||||
wsi->active_extensions[n], wsi,
|
||||
LWS_EXT_CALLBACK_PAYLOAD_TX,
|
||||
wsi->active_extensions_user[n], &eff_buf, 0);
|
||||
if (m < 0)
|
||||
return -1;
|
||||
if (protocol != LWS_WRITE_PING && protocol != LWS_WRITE_PONG) {
|
||||
|
||||
for (n = 0; n < wsi->count_active_extensions; n++) {
|
||||
m = wsi->active_extensions[n]->callback(
|
||||
wsi->protocol->owning_server,
|
||||
wsi->active_extensions[n], wsi,
|
||||
LWS_EXT_CALLBACK_PAYLOAD_TX,
|
||||
wsi->active_extensions_user[n], &eff_buf, 0);
|
||||
if (m < 0)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
buf = (unsigned char *)eff_buf.token;
|
||||
|
@ -586,7 +589,7 @@ send_raw:
|
|||
lwsl_debug("\n");
|
||||
#endif
|
||||
|
||||
if (protocol == LWS_WRITE_HTTP) {
|
||||
if (protocol == LWS_WRITE_HTTP || protocol == LWS_WRITE_PONG || protocol == LWS_WRITE_PING) {
|
||||
if (lws_issue_raw(wsi, (unsigned char *)buf - pre,
|
||||
len + pre + post))
|
||||
return -1;
|
||||
|
|
|
@ -779,10 +779,11 @@ spill:
|
|||
return -1;
|
||||
|
||||
case LWS_WS_OPCODE_07__PING:
|
||||
lwsl_info("received %d byte ping, sending pong\n", wsi->rx_user_buffer_head);
|
||||
lwsl_hexdump(&wsi->rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING], wsi->rx_user_buffer_head);
|
||||
/* parrot the ping packet payload back as a pong */
|
||||
n = libwebsocket_write(wsi, (unsigned char *)
|
||||
&wsi->rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING],
|
||||
wsi->rx_user_buffer_head, LWS_WRITE_PONG);
|
||||
&wsi->rx_user_buffer[LWS_SEND_BUFFER_PRE_PADDING], wsi->rx_user_buffer_head, LWS_WRITE_PONG);
|
||||
/* ... then just drop it */
|
||||
wsi->rx_user_buffer_head = 0;
|
||||
return 0;
|
||||
|
|
|
@ -226,6 +226,9 @@ callback_lws_mirror(struct libwebsocket_context * this,
|
|||
shift -= 8;
|
||||
}
|
||||
|
||||
while (p - &pingbuf[LWS_SEND_BUFFER_PRE_PADDING] < size)
|
||||
*p++ = 0;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
psd->ringbuffer[psd->ringbuffer_head].issue_timestamp =
|
||||
|
|
Loading…
Add table
Reference in a new issue