Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
来自 sys/socket.h 的套接字对(int 系列,int 类型,int 协议,int* sockfd)。
unp 声明family 应该是AF_LOCAL,protocol 应该是0,那么为什么接口需要这样的参数呢?为什么不将其简化为 socketpair(int type, int *sockfd) ?
我相信这里一定有故事,但我就是不知道为什么。
谢谢你告诉我这个故事;)
您应该阅读该语句“AF_LOCAL”(或 _UNIX)是当前唯一实现socketpair() 的协议。
该接口是通用的,可以为其他类型的套接字提供实现。例如,通过创建两个使用 localhost IP 相互连接的套接字来实现对 AF_INET 的支持并不难。唯一的问题是它几乎没有实际用途。Unix 套接字更适合本地连接,现在更改现有的套接字对 API 太麻烦了。