mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
minimal: ws client spam: modernize with pvo and cancel service after interrupted
This commit is contained in:
parent
0dd8a4a503
commit
1c72e9eee6
1 changed files with 15 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* lws-minimal-ws-client-spam
|
||||
*
|
||||
* Written in 2010-2019 by Andy Green <andy@warmcat.com>
|
||||
* Written in 2010-2021 by Andy Green <andy@warmcat.com>
|
||||
*
|
||||
* This file is made available under the Creative Commons CC0 1.0
|
||||
* Universal Public Domain Dedication.
|
||||
|
@ -110,8 +110,10 @@ callback_minimal_spam(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (tries == closed + errors)
|
||||
if (tries == closed + errors) {
|
||||
interrupted = 1;
|
||||
lws_cancel_service(lws_get_context(wsi));
|
||||
}
|
||||
break;
|
||||
|
||||
/* --- client callbacks --- */
|
||||
|
@ -126,8 +128,10 @@ callback_minimal_spam(struct lws *wsi, enum lws_callback_reasons reason,
|
|||
|
||||
case LWS_CALLBACK_CLIENT_CLOSED:
|
||||
closed++;
|
||||
if (tries == closed + errors)
|
||||
if (tries == closed + errors) {
|
||||
interrupted = 1;
|
||||
lws_cancel_service(lws_get_context(wsi));
|
||||
}
|
||||
if (tries == limit) {
|
||||
lwsl_user("%s: leaving CLOSED (try %d, est %d, sent %d, closed %d, err %d)\n",
|
||||
__func__, tries, est, sent, closed, errors);
|
||||
|
@ -176,6 +180,13 @@ static const struct lws_protocols protocols[] = {
|
|||
{ NULL, NULL, 0, 0 }
|
||||
};
|
||||
|
||||
static struct lws_protocol_vhost_options pvo = {
|
||||
NULL, /* "next" pvo linked-list */
|
||||
NULL, /* "child" pvo linked-list */
|
||||
"lws-spam-test", /* protocol name we belong to on this vhost */
|
||||
"OK" /* ignored */
|
||||
};
|
||||
|
||||
static void
|
||||
sigint_handler(int sig)
|
||||
{
|
||||
|
@ -206,6 +217,7 @@ int main(int argc, const char **argv)
|
|||
info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
|
||||
info.port = CONTEXT_PORT_NO_LISTEN; /* we do not run any server */
|
||||
info.protocols = protocols;
|
||||
info.pvo = &pvo;
|
||||
#if defined(LWS_WITH_MBEDTLS) || defined(USE_WOLFSSL)
|
||||
/*
|
||||
* OpenSSL uses the system trust store. mbedTLS has to be told which
|
||||
|
|
Loading…
Add table
Reference in a new issue