[noPoll] Integration with existing IO loop

Tony Mountifield tony en softins.co.uk
Jue Abr 6 11:07:20 CEST 2017


In article <823e6a9a-f2bd-8b08-6db6-c4d03e277533 at fetcorp.com>,
Dave Gilmour (FET) <dave at fetcorp.com> wrote:
> 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 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.

Are you setting the connected socket to non-blocking?

if (! nopoll_conn_set_sock_block(nopoll_conn_socket(conn), nopoll_false)) {
	// handle error
}

I do so in my on_ready handler.

Presumably, if you are handling the sockets yourself, you are completing the accept
as described in section 2.2. of http://www.aspl.es/nopoll/html/nopoll_core_library_manual.html

Another approach might be to have one thread servicing the nopoll sockets
using nopoll_loop_wait(), and another thread servicing the non-nopoll sockets.
You might still need to set the socket to non-blocking.

Disclaimer: I'm still pretty new to nopoll, and climbing the learning curve!

Cheers
Tony
-- 
Tony Mountifield
Work: tony at softins.co.uk - http://www.softins.co.uk
Play: tony at mountifield.org - http://tony.mountifield.org


Más información sobre la lista de distribución noPoll