What is the role of this code in the mongoose.c file?
#if MG_ENABLE_BROADCAST
mg_add_to_set (mgr-> ctl [1], & read_set, & max_fd);
#endif
What the mg_broadcast () Function Does?
Mongoose core is not multi-threaded, thus must be performed in a single thread. However some operations could be long to execute, and user might offload the calculation to a different thread.
If that is done, the question is how to notify the mongoose thread from some other thread? That’s what mg_broadcast is for. mongoose thread sleeps on all sockets, wakes up when at least one of them has data, and handles IO. One of the socket is a socketpair created by the mg_mgr_init()
. mg_broadcast
sends data into that pipe, waking up mongoose thread, which receives the data and delivers it to active connections.
Thanks! But I see that mg_broadcast () is not called by any function! I commented out the function does not seem to have any effect?
mg_broadcast
is supposed to be used by a user code.
See multithreaded example in the examples folder.
I don’t use multi-threaded files. My client uses websocket to communicate with the server. The program has only two threads under Linux. The communication thread is mongoose thread.
If you don’t use multithreading, don’t use mg_broadcast , since there is no need to.