[noPoll] Integration with existing IO loop
Dave Gilmour (FET)
dave en fetcorp.com
Mie Abr 5 22:37:21 CEST 2017
I am attempting to integrate nopoll into an existing IO loop because I
have other sockets that I must also look after. I am having an issue
with my first call to nopoll_conn_get_msg blocking.
I am initializing nopoll as follows:
nopoll_thread_handlers(mutex_create, mutex_destroy, mutex_lock,
mutex_unlock);
ctx = nopoll_ctx_new ();
noPollConn* listener = nopoll_listener_new (ctx, "192.168.85.133", "8000");
nopoll_ctx_set_on_msg (ctx, on_message, NULL);
nopoll_ctx_set_on_ready(ctx, on_ready, NULL);
nopoll_log_enable(ctx, 1);
nopoll_log_set_handler(ctx, on_log, NULL);
I then determine which socket is being used for the master listener by
calling
sockWSMasterListener = nopoll_conn_socket(listener);
At the top of my io loop I do a FD_SET on the master listener socket (as
well as for other sockets I'm managing) for the readfds that is passed
to select, and call select.
I get an event on that the listener socket so I call
ws_client_conn = nopoll_conn_accept (ctx, listener);
in order to accept the connection and obtain the socket that is now
associated with the new connection.
The next cycle through the io loop I do a FD_SET on the new socket (as
well as for other sockets I'm managing and the master listener) for the
readfds that is passed to select, and call select again
I get an event on the connected socket and call nopoll_conn_get_msg
(ws_client_conn);
My problem is this call does not return. I have tracked it down to the
following line of code in nopoll_conn.c:
/* get the first 2 bytes from the websocket header */
bytes = __nopoll_conn_receive (conn, buffer, 2); <<<<<<<<<<<<<<this call
blocks
The problem is that when this happens I am not servicing any of my other
sockets any more. Once a message is passed either from the client to the
server or vice versa everything seems to go ahead without a problem. So
my question is, what is nopoll waiting for at this point and how can I
avoid the blocking.
My apologies for the long-windedness of this question.
Thank you.
Más información sobre la lista de distribución noPoll