riolet / WAFer

WAFer is a C language-based software platform for scalable server-side and networking applications. Think node.js for C programmers.
GNU General Public License v2.0
693 stars 69 forks source link

AF-Unix #53

Open janus opened 9 years ago

janus commented 9 years ago

I was a bit confused while going through your code particularly when I noticed that socket used "AF-Unix" . Why using it? I also noticed that now you have epoll, thread, and select. I fcntl and thread, but what do you again with epoll

truongminh commented 9 years ago

Why does nope.c use AF_UNIX socket?

With NOPE_THREADS enabled, the worker and master threads needs someway to communicate with the other. In this case, nope.c use a socketpair to make the communication between the master and a worker asynchronous.

If you want to communicate with a remote host, then you will probably need an INET socket. The difference is that an INET socket is bound to an IP address-port tuple, while a UNIX socket is "bound" to a special file on your filesystem. Generally, only processes running on the same machine can communicate through the latter.

So, why would one use a UNIX socket? Exactly for the reason above: communication between processes on the same host, being a lightweight alternative to an INET socket via loopback.