Multi threading


I’m toying around with the mongoose library and copied the multi-threaded example but I have a question
about that: Why is the fn_data pointer of the mg_connection used to store the socket from the socketpair this means
that you cannot have any user context when using this solution. Looking at the definition in net.h is states:

void *fn_data; // User-specified function parameter

Wouldn’t it be better to add an extra variable to the mg_connection which lets say is called sockfd or so that can
contain this information. Am I also correct that with the mg_socketpair I’m busy polling the socket ? e.g. the MG_EV_POLL
event is raised for every connection by mg_mgr_poll().


There is no need for an extra field in the struct mg_connection.
If you require more things to store in fn_data, other than a socket, create a structure that holds everything you require (including socket), allocate that struct and store an allocated pointer in the fn_data.