mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-30 00:00:16 +01:00
client allow user callback to close on nonzero return
Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
parent
bbc5c07054
commit
5ac7e7ad5a
3 changed files with 12 additions and 7 deletions
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* libwebsockets - small server side websockets and web server implementation
|
* libwebsockets - small server side websockets and web server implementation
|
||||||
*
|
*
|
||||||
* Copyright (C) 2010-2013 Andy Green <andy@warmcat.com>
|
* Copyright (C) 2010-2014 Andy Green <andy@warmcat.com>
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
@ -382,7 +382,8 @@ spill:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (eff_buf.token_len <= 0 && callback_action != LWS_CALLBACK_CLIENT_RECEIVE_PONG)
|
if (eff_buf.token_len <= 0 &&
|
||||||
|
callback_action != LWS_CALLBACK_CLIENT_RECEIVE_PONG)
|
||||||
goto already_done;
|
goto already_done;
|
||||||
|
|
||||||
eff_buf.token[eff_buf.token_len] = '\0';
|
eff_buf.token[eff_buf.token_len] = '\0';
|
||||||
|
@ -393,7 +394,7 @@ spill:
|
||||||
if (callback_action == LWS_CALLBACK_CLIENT_RECEIVE_PONG)
|
if (callback_action == LWS_CALLBACK_CLIENT_RECEIVE_PONG)
|
||||||
lwsl_info("Client doing pong callback\n");
|
lwsl_info("Client doing pong callback\n");
|
||||||
|
|
||||||
wsi->protocol->callback(
|
m = wsi->protocol->callback(
|
||||||
wsi->protocol->owning_server,
|
wsi->protocol->owning_server,
|
||||||
wsi,
|
wsi,
|
||||||
(enum libwebsocket_callback_reasons)callback_action,
|
(enum libwebsocket_callback_reasons)callback_action,
|
||||||
|
@ -401,6 +402,10 @@ spill:
|
||||||
eff_buf.token,
|
eff_buf.token,
|
||||||
eff_buf.token_len);
|
eff_buf.token_len);
|
||||||
|
|
||||||
|
/* if user code wants to close, let caller know */
|
||||||
|
if (m)
|
||||||
|
return 1;
|
||||||
|
|
||||||
already_done:
|
already_done:
|
||||||
wsi->u.ws.rx_user_buffer_head = 0;
|
wsi->u.ws.rx_user_buffer_head = 0;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -163,7 +163,7 @@ bail:
|
||||||
* we will get a destroy callback to take care
|
* we will get a destroy callback to take care
|
||||||
* of closing nicely
|
* of closing nicely
|
||||||
*/
|
*/
|
||||||
lwsl_err("zlib error inflate %d: %s\n",
|
lwsl_info("zlib error inflate %d: %s\n",
|
||||||
n, conn->zs_in.msg);
|
n, conn->zs_in.msg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,7 +146,7 @@ http_postbody:
|
||||||
case LWS_CONNMODE_WS_CLIENT:
|
case LWS_CONNMODE_WS_CLIENT:
|
||||||
for (n = 0; n < len; n++)
|
for (n = 0; n < len; n++)
|
||||||
if (libwebsocket_client_rx_sm(wsi, *buf++)) {
|
if (libwebsocket_client_rx_sm(wsi, *buf++)) {
|
||||||
lwsl_info("client_rx_sm failed\n");
|
lwsl_debug("client_rx_sm failed\n");
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -417,7 +417,7 @@ cleanup:
|
||||||
for (n = 0; n < len; n++)
|
for (n = 0; n < len; n++)
|
||||||
if (libwebsocket_client_rx_sm(
|
if (libwebsocket_client_rx_sm(
|
||||||
wsi, *buf++) < 0) {
|
wsi, *buf++) < 0) {
|
||||||
lwsl_info("client rx has bailed\n");
|
lwsl_debug("client rx has bailed\n");
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -450,7 +450,7 @@ bail_nuke_ah:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
lwsl_info("closing connection at libwebsocket_read bail:\n");
|
lwsl_debug("closing connection at libwebsocket_read bail:\n");
|
||||||
|
|
||||||
libwebsocket_close_and_free_session(context, wsi,
|
libwebsocket_close_and_free_session(context, wsi,
|
||||||
LWS_CLOSE_STATUS_NOSTATUS);
|
LWS_CLOSE_STATUS_NOSTATUS);
|
||||||
|
|
Loading…
Add table
Reference in a new issue