Contents
What is Unix socket directory?
A Unix domain socket or IPC socket (inter-process communication socket) is a data communications endpoint for exchanging data between processes executing on the same host operating system. Valid socket types in the UNIX domain are: SOCK_STREAM (compare to TCP) – for a stream-oriented socket.
Where is the socket file?
The default location for the Unix socket file that the server uses for communication with local clients is /tmp/mysql. sock . (For some distribution formats, the directory might be different, such as /var/lib/mysql for RPMs.)
What can a Unix domain socket be used for?
UNIX domain sockets can be used to pass file descriptors between processes. This can be used to have a privileged process, which opens a file on request of another process. Usually it performs additional checks before it passes its opened file on to the requesting process. See SCM_RIGHTS in the manual page.
How does Resol create a socket in Unix?
On Resol’s side, the procedure goes as follows: Resol creates a socket by calling socket () . Resol assigns the socket a name. In case of UNIX socket, the name is exactly a filename. Resol bind () the socket with a filename. // We need extra steps to create the _addr_ variable.
When to unlink the socket file in Unix?
Therefore many services unconditionally unlink the socket file before starting. If the old service is still running, its socket will no longer be reachable. Also be aware that close () ing the socket will not remove the socket path, so your daemon should unlink () it itself when shutting down.
How to bind a socket to a file?
In case of UNIX socket, the name is exactly a filename. Resol bind () the socket with a filename. // We need extra steps to create the _addr_ variable. Here we omit it for simplicity. ret = bind(listen_socket, (const struct sockaddr *) &addr, sizeof(struct sockaddr_un));