mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
minimal: hcmulti: modernize startup to use OPERATIONAL
This commit is contained in:
parent
34afca321c
commit
604968a31d
1 changed files with 66 additions and 46 deletions
|
@ -52,7 +52,7 @@ struct cliuser {
|
|||
};
|
||||
|
||||
static int completed, failed, numbered, stagger_idx, posting, count = COUNT,
|
||||
reuse;
|
||||
reuse, staggered;
|
||||
static lws_sorted_usec_list_t sul_stagger;
|
||||
static struct lws_client_connect_info i;
|
||||
static struct lws *client_wsi[COUNT];
|
||||
|
@ -372,6 +372,65 @@ static const lws_system_ops_t system_ops = {
|
|||
|
||||
#endif
|
||||
|
||||
static void
|
||||
stagger_cb(lws_sorted_usec_list_t *sul);
|
||||
|
||||
static void
|
||||
lws_try_client_connection(struct lws_client_connect_info *i, int m)
|
||||
{
|
||||
char path[128];
|
||||
|
||||
if (numbered) {
|
||||
lws_snprintf(path, sizeof(path), "/%d.png", m + 1);
|
||||
i->path = path;
|
||||
} else
|
||||
i->path = urlpath;
|
||||
|
||||
i->pwsi = &client_wsi[m];
|
||||
i->opaque_user_data = (void *)(intptr_t)m;
|
||||
|
||||
if (!lws_client_connect_via_info(i)) {
|
||||
failed++;
|
||||
lwsl_user("%s: failed: conn idx %d\n", __func__, m);
|
||||
if (++completed == count) {
|
||||
lwsl_user("Done: failed: %d\n", failed);
|
||||
lws_context_destroy(context);
|
||||
}
|
||||
} else
|
||||
lwsl_user("started connection %s: idx %d (%s)\n",
|
||||
lws_wsi_tag(client_wsi[m]), m, i->path);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
system_notify_cb(lws_state_manager_t *mgr, lws_state_notify_link_t *link,
|
||||
int current, int target)
|
||||
{
|
||||
struct lws_context *context = mgr->parent;
|
||||
int m;
|
||||
|
||||
if (current != LWS_SYSTATE_OPERATIONAL || target != LWS_SYSTATE_OPERATIONAL)
|
||||
return 0;
|
||||
|
||||
/* all the system prerequisites are ready */
|
||||
|
||||
if (!staggered)
|
||||
/*
|
||||
* just pile on all the connections at once, testing the
|
||||
* pipeline queuing before the first is connected
|
||||
*/
|
||||
for (m = 0; m < count; m++)
|
||||
lws_try_client_connection(&i, m);
|
||||
else
|
||||
/*
|
||||
* delay the connections slightly
|
||||
*/
|
||||
lws_sul_schedule(context, 0, &sul_stagger, stagger_cb,
|
||||
50 * LWS_US_PER_MS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
signal_cb(void *handle, int signum)
|
||||
{
|
||||
|
@ -424,32 +483,6 @@ unsigned long long us(void)
|
|||
return ((unsigned long long)t.tv_sec * 1000000ull) + (unsigned long long)t.tv_usec;
|
||||
}
|
||||
|
||||
static void
|
||||
lws_try_client_connection(struct lws_client_connect_info *i, int m)
|
||||
{
|
||||
char path[128];
|
||||
|
||||
if (numbered) {
|
||||
lws_snprintf(path, sizeof(path), "/%d.png", m + 1);
|
||||
i->path = path;
|
||||
} else
|
||||
i->path = urlpath;
|
||||
|
||||
i->pwsi = &client_wsi[m];
|
||||
i->opaque_user_data = (void *)(intptr_t)m;
|
||||
|
||||
if (!lws_client_connect_via_info(i)) {
|
||||
failed++;
|
||||
lwsl_user("%s: failed: conn idx %d\n", __func__, m);
|
||||
if (++completed == count) {
|
||||
lwsl_user("Done: failed: %d\n", failed);
|
||||
lws_context_destroy(context);
|
||||
}
|
||||
} else
|
||||
lwsl_user("started connection %s: idx %d (%s)\n",
|
||||
lws_wsi_tag(client_wsi[m]), m, i->path);
|
||||
}
|
||||
|
||||
static void
|
||||
stagger_cb(lws_sorted_usec_list_t *sul)
|
||||
{
|
||||
|
@ -479,14 +512,14 @@ stagger_cb(lws_sorted_usec_list_t *sul)
|
|||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
lws_state_notify_link_t notifier = { {0}, system_notify_cb, "app" };
|
||||
lws_state_notify_link_t *na[] = { ¬ifier, NULL };
|
||||
struct lws_context_creation_info info;
|
||||
int m, staggered = 0
|
||||
#if defined(LWS_WITH_TLS_SESSIONS)
|
||||
, pl = 0
|
||||
#endif
|
||||
;
|
||||
unsigned long long start;
|
||||
const char *p;
|
||||
#if defined(LWS_WITH_TLS_SESSIONS)
|
||||
int pl = 0;
|
||||
#endif
|
||||
|
||||
memset(&info, 0, sizeof info); /* otherwise uninitialized garbage */
|
||||
memset(&i, 0, sizeof i); /* otherwise uninitialized garbage */
|
||||
|
@ -526,6 +559,7 @@ int main(int argc, const char **argv)
|
|||
* network wsi) that we will use.
|
||||
*/
|
||||
info.fd_limit_per_thread = 1 + COUNT + 1;
|
||||
info.register_notifier_list = na;
|
||||
info.pcontext = &context;
|
||||
|
||||
#if defined(LWS_WITH_SYS_METRICS)
|
||||
|
@ -638,20 +672,6 @@ int main(int argc, const char **argv)
|
|||
lwsl_warn("%s: session load failed\n", __func__);
|
||||
#endif
|
||||
|
||||
if (!staggered)
|
||||
/*
|
||||
* just pile on all the connections at once, testing the
|
||||
* pipeline queuing before the first is connected
|
||||
*/
|
||||
for (m = 0; m < count; m++)
|
||||
lws_try_client_connection(&i, m);
|
||||
else
|
||||
/*
|
||||
* delay the connections slightly
|
||||
*/
|
||||
lws_sul_schedule(context, 0, &sul_stagger, stagger_cb,
|
||||
50 * LWS_US_PER_MS);
|
||||
|
||||
start = us();
|
||||
while (!intr && !lws_service(context, 0))
|
||||
;
|
||||
|
|
Loading…
Add table
Reference in a new issue