当接收端未从套接字读取时,通过 Unix 套接字发送的消息会发生什么情况?

What happens with messages that are being sent over a Unix socket while the receiving end is not reading from the socket?

我目前正在学习 IPC 和 Unix 域套接字。我想知道在接收端未从套接字读取时通过 Unix 套接字发送的消息会发生什么情况? 无论是否有人在阅读,它们都会被发送,还是它们会排在某种队列中等待 reader

根据我的研究(Linux),在数据报的情况下(message-oriented) Unix套接字:

  • 如果接收端没有在socket上做bind(),发送端将无法执行sendto();
  • 如果接收端已经在套接字上完成了bind()并且没有继续做recvfrom(),发送方将在一定限度内排队一批消息并停止;
  • 如果接收端恢复recvfrom(),发送方将恢复。

另请参阅:sysctl net.unix.max_dgram_qlen(队列大小)。