diff options
author | Andy Green <andy@warmcat.com> | 2019-08-07 10:41:03 +0100 |
---|---|---|
committer | Andy Green <andy@warmcat.com> | 2019-08-08 09:45:09 +0100 |
commit | 1d954d52a3066e0f6271c19ac2d216a9d9c855ce (patch) | |
tree | 095d5e75c6ca9074521bbf0d4b282d9b520727af /minimal-examples/api-tests | |
parent | 20923db2b56d4a2800a18e46f31c06a2ad9359a4 (diff) | |
download | libwebsockets-1d954d52a3066e0f6271c19ac2d216a9d9c855ce.tar.gz |
sequencer: add second aux message arg
Since the messages are queued and then read in order from the event loop
thread, it's not generally safe to pass pointers to argument structs,
since there's no guarantee the lifetime of the thing sending the message
lasted until the sequencer read the message.
This puts pressure on the single void * argument-passed-as-value... this patch
adds a second void * argument-passed-as-value so it's more possible to put
what's needed directly in the argument.
It's also possible to alloc the argument on the heap and have the sequencer
callback free it after it has read it.
Diffstat (limited to 'minimal-examples/api-tests')
-rw-r--r-- | minimal-examples/api-tests/api-test-lws_sequencer/main.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/minimal-examples/api-tests/api-test-lws_sequencer/main.c b/minimal-examples/api-tests/api-test-lws_sequencer/main.c index af058f66..7924c0c5 100644 --- a/minimal-examples/api-tests/api-test-lws_sequencer/main.c +++ b/minimal-examples/api-tests/api-test-lws_sequencer/main.c @@ -35,7 +35,6 @@ enum { */ struct myseq { - struct lws_context *context; struct lws_vhost *vhost; struct lws *cwsi; /* client wsi for current step if any */ @@ -163,7 +162,8 @@ notify: lws_set_wsi_user(wsi, NULL); s->cwsi = NULL; - lws_sequencer_event(lws_sequencer_from_user(s), seq_msg, NULL); + lws_sequencer_queue_event(lws_sequencer_from_user(s), seq_msg, + NULL, NULL); return 0; } @@ -185,7 +185,7 @@ sequencer_start_client(struct myseq *s) lws_strncpy(uri, url_paths[s->state], sizeof(uri)); memset(&i, 0, sizeof i); - i.context = s->context; + i.context = lws_sequencer_get_context(lws_sequencer_from_user(s)); if (lws_parse_uri(uri, &prot, &i.address, &i.port, &path1)) { lwsl_err("%s: uri error %s\n", __func__, uri); @@ -217,8 +217,8 @@ sequencer_start_client(struct myseq *s) /* we couldn't even get started with the client connection */ - lws_sequencer_event(lws_sequencer_from_user(s), - SEQ_MSG_CLIENT_FAILED, NULL); + lws_sequencer_queue_event(lws_sequencer_from_user(s), + SEQ_MSG_CLIENT_FAILED, NULL, NULL); return 1; } @@ -238,7 +238,8 @@ sequencer_start_client(struct myseq *s) */ static lws_seq_cb_return_t -sequencer_cb(struct lws_sequencer *seq, void *user, int event, void *data) +sequencer_cb(struct lws_sequencer *seq, void *user, int event, + void *data, void *aux) { struct myseq *s = (struct myseq *)user; @@ -382,7 +383,6 @@ main(int argc, const char **argv) lwsl_err("%s: unable to create sequencer\n", __func__); goto bail1; } - s->context = context; s->vhost = vh; /* the usual lws event loop */ |