[Libwebsockets] should I use LWS_ADOPT_SOCKET for AF_UNIX socket?

Per Bothner per at bothner.com
Tue Feb 18 03:49:37 CET 2020

On 2/15/20 8:08 PM, Andy Green wrote:
> On February 15, 2020 10:20:04 PM GMT, Per Bothner <per at bothner.com> wrote:
>> 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.

I was confused - the problem was not at the connect/accept level,
but later: recvmsg not blocking in the same way it does on Linux.

I couldn't figure out how to make it work on MacOS: I added a call to
poll before the recvmsg, but that only partially helped.

However, using write/read instead of sendmsg/recvmsg seems to work.
I have to forego passing stdin/stdout/stderr from the client to the server,
but I can get most of the same functionality by just using the socket itself.
So I'm trying that instead, at least for MacOS.  It seems promising.

(A bonus of using just the socket rather than passing descriptor is that
the same logic should work if using named pipes instead of local sockets,
if/when I try porting DomTerm to a system without the latter, such as
plain non-WSL Windows.)

> But for unix domain sockets, they are like tcp sockets in that they have a stateful connection concept and are either istening or making connections.  For that reason if you want to listen with one, it's fine but the way follows tcp listen / serving in lws... create a vhost and use the vhost option LWS_SERVER_OPTION_UNIX_SOCK, you set the uds path in .iface IIRC.

I couldn't figure out how to use LWS_SERVER_OPTION_UNIX_SOCK - the
example(s) are unclear how I would use that  And when I figured out
the problem was at the sendmsg/recvmsg level, I didn't pursue it.

> This stuff is in use with gitohashi on https://libwebsockets.org/git ... gitohashi is actually a separate process also using lws to serve over a unix domain socket, lwsws proxies it back out over h1 or h2 to the remote client.

I couldn't find LWS_SERVER_OPTION_UNIX_SOCK in the gitohasi code, so
that didn't help me figure out what to do.
	--Per Bothner
per at bothner.com   http://per.bothner.com/

More information about the Libwebsockets mailing list