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:
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],
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--;
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,
wsi->user_space,
eff_buf.token,
eff_buf.token_len);
+ }
}
already_done:
wsi->rx_user_buffer_head = 0;
#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:
/* 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++;
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,
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;
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;
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;
shift -= 8;
}
+ while (p - &pingbuf[LWS_SEND_BUFFER_PRE_PADDING] < size)
+ *p++ = 0;
+
gettimeofday(&tv, NULL);
psd->ringbuffer[psd->ringbuffer_head].issue_timestamp =