Unix域套接字原理.它是如何工作的? [英] Principle of Unix Domain Socket. How does it work?

查看:29
本文介绍了Unix域套接字原理.它是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 Unix 域套接字.特别是关于它是如何工作的.我用许多关键字搜索了很多次,但结果都是关于 API、系统调用、如何使用它、示例......我也读过关于管道和 FIFO 的内容,因为据说 Unix 域套接字与管道和 FIFO 相同,但我仍然想更多地了解 Unix 域套接字的概念/原理.它是如何工作的?(可能在内核级别,因为 Wiki 是这样说的:这允许两个进程打开同一个套接字以进行通信.但是,通信完全发生在操作系统内核中."

I am doing a study about Unix domain socket. Especially about how does it work. I googled many times with many keywords but the results are all about API, system calls, how to use it, examples ... . I have read about Pipe and FIFO too because Unix Domain socket is said to be the same with Pipe and FIFO but I still want to know more about the concept/priciples of Unix Domain Socket. How does it work? (Maybe at the kernel level because Wiki say this:"This allows two processes to open the same socket in order to communicate. However, communication occurs entirely within the operating system kernel."

我仍然想知道为什么 Unix 域 Socket 纪录片比 Pipe 或 FIFO 少?也许是因为它是多年前出生的?

I still wonder why Unix domain Socket documentaries is less than Pipe or FIFO? Maybe because it was born so many years ago?

谁能告诉我任何想法或要阅读的书籍/链接?

Could anyone show me any ideas or which books/links to read?

提前致谢!

推荐答案

Unix 套接字用作任何其他套接字类型.这意味着,套接字系统调用用于它们.FIFO 和 Unix 套接字的区别在于,FIFO 使用文件系统调用,而 Unix 套接字使用套接字调用.

Unix sockets are used as any other socket types. This means, that socket system calls are used for them. The difference between FIFOs and Unix sockets, is that FIFO use file sys calls, while Unix sockets use socket calls.

Unix 套接字作为文件寻址.它允许使用文件权限进行访问控制.

Unix sockets are addressed as files. It allows to use file permissions for access control.

Unix 套接字由套接字 sys 调用创建(而 FIFO 由 mkfifo 创建).如果您需要客户端套接字,则调用连接,将服务器套接字地址传递给它.如果你需要服务器套接字,你可以绑定来分配它的地址.而对于 FIFO 则使用 open 调用.IO 操作通过读/写进行.

Unix sockets are created by socket sys call (while FIFO created by mkfifo). If you need client socket, you call connect, passing it server socket address. If you need server socket, you can bind to assign its address. While, for FIFO open call is used. IO operation is performed by read/write.

Unix socket 可以区分它的客户端,而 FIFO 不能.关于peer的信息由accept调用提供,它返回peer的地址.

Unix socket can distinguish its clients, while FIFO cannot. Info about peer is provided by accept call, it returns address of peer.

Unix 套接字是双向的.这意味着每一方都可以执行读写操作.而 FIFO 是单向的:它有一个写入节点和一个读取节点.

Unix sockets are bidirectional. This means that every side can perform both read and write operations. While, FIFOs are unidirectional: it has a writer peer and a reader peer.

与本地主机 IP 套接字相比,Unix 套接字创建的开销更少,通信速度更快.数据包不需要像本地主机套接字一样通过网络堆栈.由于它们仅存在于本地,因此没有路由.

Unix sockets create less overhead and communication is faster, than by localhost IP sockets. Packets don't need to go through network stack as with localhost sockets. And as they exists only locally, there is no routing.

如果您需要更多有关 Unix 套接字如何在内核级别工作的详细信息,请查看 Linux 内核源代码中的 net/unix/af_unix.c 文件.

If you need more details about, how Unix sockets work at kernel level, please, look at net/unix/af_unix.c file in Linux kernel source.

这篇关于Unix域套接字原理.它是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆