mg_wakeup_server_ex() sends a message to the socketpair and returns immediately. Main server loop, which runs in a separate thread, reads that message, calls the callback, and sends one byte back (so that recv() unblocks) to indicate it has finished with the callback.
Thus the purpose of recv() is to wait until the main thread calls the callback. My guess is that you're calling mg_wakeup_server_ex from the main thread rather then from the separate thread, therefore it deadlocks. mg_wakeup_server_ex() is designed to be used from non-main-thread. If you're in the main thread, you can iterate over connections using mg_next() and send your messages directly. On Wed, Jul 30, 2014 at 1:41 PM, swati joshi <[email protected]> wrote: > Hi, As suggested, I tired printing logs before and after recv ( ) inside > ns_server_wakeup_ex( ) and ns_server_poll( ). > Observation is that, in ns_server_poll ( ) there are prints getting > printed before and after recv ( ). > However, in ns_server_wakeup_ex( ) the same doesnt happen. Before and > After recv ( ) gets printed untill the case of getting blocked inside recv > ( ) occurs. > Hence Polling stops and the message exchange over mg_conn stops. > > In my code, currently if i comment recv ( ) inside ns_server_wakeup_ex( ), > everything is working fine. > I have a question here, what is the significance of having recv ( ) inside > ns_server_wakeup_ex( ) ? Because, ns_server_wakeup_ex( ) is called > from mg_wakeup_server_ex ( ), and i call mg_wakeup_server_ex ( ) with a > callback where i write into websocket using mg_websocket_write( ). So If my > job is just to write/ send to websocket , why reading / recv ( ) in > ns_server_wakeup_ex( ) ? > > Below is my code, > static int websocket_data_push(struct mg_connection *conn, enum mg_event > ev) > { > printf("Inside websocket_data_push \n"); > printf("URI %s \n" ,conn->uri); > printf("Sending Event %s \n" ,(char *) conn->callback_param); > if (ev == MG_POLL) > { > if (strcmp(conn->uri, "/web") == 0 && conn->is_websocket) { > printf("Sending Event %s \n" ,(char *) conn->callback_param); > mg_websocket_printf(conn, WEBSOCKET_OPCODE_TEXT, "%s", > (const char *) conn->callback_param); > } > } > return MG_TRUE; > } > > ... > mg_wakeup_server_ex(mgserver, websocket_data_push, "%lu %s", > (unsigned long) time(NULL), (const char *) > evString); > ... > > Do you suspect, if return value of callback would matter ? > If yes, then my other cases would not be working fine. > > Basically, My code is a mixture of C & C++. > I have mg_wakeup_server_ex( ) called from a member function of Class-A > and callback is a global function to this class. > I have Class-B Class-C and Class-D, doing the job and ultimately framing a > char* response to be sent to client. > So these classes call the method, where mg_wakeup_server_ex ( ) is invoked. > Things work fine Class-B and Class-C. But Class-D which does exactly the > same job, its response gets blocked in recv ( ) . As I said earlier , > commenting recv ( ) works fine for everything that I expect. > > Could you suggest something ? > > -- > You received this message because you are subscribed to the Google Groups > "mongoose-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/mongoose-users. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "mongoose-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/mongoose-users. For more options, visit https://groups.google.com/d/optout.
