Skip to content

About using mg_ws_send on a separate thread #1449

Discussion options

You must be logged in to vote

@vb-mich , there are couple of things happen when you send data over the struct mg_connection *c pointer.

First, the data gets appended to the c->send buffer. Note, it is not gets send, it gets appended. So the first issue is to make sure no other thread deals with the send buffer. And you can't guarantee that, because the IO thread can send some remaining data and modify the c->send whilst your thread adding some stuff to it.

Another issue is that even if you add data, the IO thread does not know that the data was added - it may continue sleeping in mg_poll(). So your data gets sent whenever the main IO thread wakes up from select(), and that depends on the polling interval you've set in m…

Replies: 5 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@vb-mich
Comment options

@cpq
Comment options

cpq Jan 18, 2022
Maintainer

@vb-mich
Comment options

Answer selected by cpq
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@t123yh
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants