mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
cmdline: introduce builtin switches
Rather than do all switches by hand on the minimal examples, add a helper that knows some "builtin" ones like -d and others to set context options you might want to use in any example.
This commit is contained in:
parent
bce1f01370
commit
bb7f96d32b
3 changed files with 57 additions and 14 deletions
|
@ -269,6 +269,22 @@ lws_parse_uri(char *p, const char **prot, const char **ads, int *port,
|
|||
LWS_VISIBLE LWS_EXTERN const char *
|
||||
lws_cmdline_option(int argc, const char **argv, const char *val);
|
||||
|
||||
/**
|
||||
* lws_cmdline_option_handle_builtin(): apply standard cmdline options
|
||||
*
|
||||
* \param argc: count of argument strings
|
||||
* \param argv: argument strings
|
||||
* \param info: context creation info
|
||||
*
|
||||
* Applies standard options to the context creation info to save them having
|
||||
* to be (unevenly) copied into the minimal examples.
|
||||
*
|
||||
* Applies default log levels that can be overriden by -d
|
||||
*/
|
||||
LWS_VISIBLE LWS_EXTERN void
|
||||
lws_cmdline_option_handle_builtin(int argc, const char **argv,
|
||||
struct lws_context_creation_info *info);
|
||||
|
||||
/**
|
||||
* lws_now_secs(): return seconds since 1970-1-1
|
||||
*/
|
||||
|
|
|
@ -987,6 +987,8 @@ lws_cmdline_option(int argc, const char **argv, const char *val)
|
|||
return argv[c + 1];
|
||||
}
|
||||
|
||||
if (argv[c][n] == '=')
|
||||
return &argv[c][n + 1];
|
||||
return argv[c] + n;
|
||||
}
|
||||
}
|
||||
|
@ -994,6 +996,42 @@ lws_cmdline_option(int argc, const char **argv, const char *val)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static const char * const builtins[] = {
|
||||
"-d",
|
||||
"--udp-tx-loss",
|
||||
"--udp-rx-loss"
|
||||
};
|
||||
|
||||
void
|
||||
lws_cmdline_option_handle_builtin(int argc, const char **argv,
|
||||
struct lws_context_creation_info *info)
|
||||
{
|
||||
const char *p;
|
||||
int n, m, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE;
|
||||
|
||||
for (n = 0; n < (int)LWS_ARRAY_SIZE(builtins); n++) {
|
||||
p = lws_cmdline_option(argc, argv, builtins[n]);
|
||||
if (!p)
|
||||
continue;
|
||||
|
||||
m = atoi(p);
|
||||
|
||||
switch (n) {
|
||||
case 0:
|
||||
logs = m;
|
||||
break;
|
||||
case 1:
|
||||
info->udp_loss_sim_tx_pc = m;
|
||||
break;
|
||||
case 2:
|
||||
info->udp_loss_sim_rx_pc = m;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
lws_set_log_level(logs, NULL);
|
||||
}
|
||||
|
||||
|
||||
const lws_humanize_unit_t humanize_schema_si[] = {
|
||||
{ "Pi ", LWS_PI }, { "Ti ", LWS_TI }, { "Gi ", LWS_GI },
|
||||
|
|
|
@ -204,30 +204,19 @@ int main(int argc, const char **argv)
|
|||
lws_state_notify_link_t *na[] = { ¬ifier, NULL };
|
||||
struct lws_context_creation_info info;
|
||||
struct lws_context *context;
|
||||
const char *p;
|
||||
struct args args;
|
||||
int n = 0, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE
|
||||
/*
|
||||
* For LLL_ verbosity above NOTICE to be built into lws,
|
||||
* lws must have been configured and built with
|
||||
* -DCMAKE_BUILD_TYPE=DEBUG instead of =RELEASE
|
||||
*
|
||||
* | LLL_INFO | LLL_PARSER | LLL_HEADER | LLL_EXT |
|
||||
* LLL_CLIENT | LLL_LATENCY | LLL_DEBUG
|
||||
*/ ;
|
||||
int n = 0;
|
||||
|
||||
args.argc = argc;
|
||||
args.argv = argv;
|
||||
|
||||
signal(SIGINT, sigint_handler);
|
||||
|
||||
if ((p = lws_cmdline_option(argc, argv, "-d")))
|
||||
logs = atoi(p);
|
||||
memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */
|
||||
lws_cmdline_option_handle_builtin(argc, argv, &info);
|
||||
|
||||
lws_set_log_level(logs, NULL);
|
||||
lwsl_user("LWS minimal http client [-d<verbosity>] [-l] [--h1]\n");
|
||||
|
||||
memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */
|
||||
info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
|
||||
info.port = CONTEXT_PORT_NO_LISTEN; /* we do not run any server */
|
||||
info.protocols = protocols;
|
||||
|
|
Loading…
Add table
Reference in a new issue