AF_UNIX domain - why use local file names only?

前端 未结 3 1634
我寻月下人不归
我寻月下人不归 2021-01-05 09:32

When using socket in the UNIX domain, it is advisable to use path name for the directory directory mounted on the local disk. The UNIX domain only allows inte

相关标签:
3条回答
  • 2021-01-05 10:11

    The end-points of UNIX domain sockets are represented by files in the file system (instead of by host / port).

    However the communication between processes is done within the local system and does not result in a seekable file getting stored anywhere.

    The advantage of using the file system as the namespace for the end-points is that normal file permissions and ACLs can be applied - if you can't open the end-point you can't connect. IP sockets have no such mechanism.

    0 讨论(0)
  • 2021-01-05 10:25

    A Unix domain socket or IPC socket (inter-process communication socket) is a data communications endpoint that is similar to an Internet socket, but does not use a network protocol for communication. It is used in POSIX operating systems for inter-process communication. The correct standard POSIX term is POSIX Local IPC Sockets.

    Unix domain connections appear as byte streams, much like network connections, but all data remains within the local computer. UNIX domain sockets use the file system as address name space, i.e. they are referenced by processes as inodes in the file system. This allows two distinct processes to open the same socket in order to communicate. However, the actual communication (the data exchange) does not use the file system, but buffers in kernel memory.

    In addition to sending data, processes can send file descriptors across a Unix domain socket connection using the sendmsg() and recvmsg() system calls.

    0 讨论(0)
  • 2021-01-05 10:32

    It means that if you create a AF_UNIX socket on a NFS disk which is shared between two machines A and B, you cannot have a process on A writing data to the unix socket and a process on B reading data from that socket.

    The communication happens at kernel level, and you can only transfer data among processes sitting in the same kernel.

    0 讨论(0)
提交回复
热议问题