[Libwebsockets] should I use LWS_ADOPT_SOCKET for AF_UNIX socket?
per at bothner.com
Sat Feb 15 23:20:04 CET 2020
tl;dr: If for a AF_UNIX socket I just want to use lws to multiplex
listening to a connection, should I use LWS_ADOPT_SOCKET? It seems not.
Details: For DomTerm I use Unix domain sockets to communicate between a client making
a request to the server, which listens on an AF_UNIX socket. For example if you type
at the command line the (client) domterm will try to connect to the server domterm and
send it a request to "print" various information about the server status. This information
is sent back to the client command, which prints it on its stdout.
In the server I use lws_adopt_descriptor_vhost on the listening socket.
Currently, the 2nd argument is 0 - but should it be LWS_ADOPT_SOCKET?
On Linux it works fine with passing 0 to lws_adopt_descriptor_vhost:
The corresponding callback handler in my code handles LWS_CALLBACK_RAW_RX_FILE
by calling accept on the socket, followed by recvmsg to receive the
request from the client.
On MacOS this doesn't work. The connection is made, in the sense that
the client calls connect, and the server accept returns. However.
the client hangs in the connect command. The server recmsg fails
to receive anything - since the client is hanging.
I wrote a simple test program that does *not* use lws, and that worked
fine on both Linux and MacOS.
If I pass LWS_ADOPT_SOCKET to lws_adopt_descriptor_vhost then things
get a bit further: The connect in the client returns. However, the server
rops_handle_POLLIN_raw_skt calls lws_buflist_aware_read, which calls
recvfrom, which fails.
All I want to do is tie in the "listen for connection" state into the
lws polling/event framework (I'm using the default/builtin polling).
I do not want lws to do recvfrom or other hand-shaking.
Am I correct in concluding I should *not* be passing LWS_ADOPT_SOCKET
to lws_adopt_descriptor_vhost in this situation?
If you have any guess why the connect call hangs on MacOS (but not on Linux
and not if using LWS_ADOPT_SOCKET) that would be fabulous. I tried
adding a call:
fcntl(csocket.filefd, F_SETFL, O_NONBLOCK);
but that didn't seem to make a difference.
per at bothner.com http://per.bothner.com/
More information about the Libwebsockets