UNIX 域套接字:是否存在“忙”套接字之类的东西?信号?
如果接收端无法处理负载,通过 UNIX 域套接字(AF_UNIX 类型)推送数据的客户端是否可以收到忙信号?
或者
套接字之上是否必须有一个客户端-服务器协议来处理流量控制?
Can a Client pushing data through a UNIX domain socket ( AF_UNIX type ) be signaled busy if the receiving end cannot cope with the load?
OR
Must there be a Client-Server protocol on top of the socket to handle flow control?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您绝对可以对 UNIX 域套接字进行阻塞发送。如果接收方的接收缓冲区已满,或者未完成(未传送)的发送套接字缓冲区的数量过高,则发送方将阻塞。
SOCK_STREAM UNIX 域套接字的工作方式类似于 TCP 套接字。 SOCK_DGRAM UNIX 域套接字的工作方式与 UDP 类似,不同之处在于 UNIX 域数据报保证按顺序传送,而 UDP 套接字可以重新排序或删除。 (此外,UNIX 域套接字可用于在进程之间发送文件描述符和传递用户凭据,而这两者都无法通过 TCP、UDP 或管道来完成。)
因此,因为所有类型的 UNIX 域都保证按顺序传递套接字,接收方在忙于做其他事情时可以停止接收,而发送方在没有更多可用缓冲区空间时将自动阻塞(或者如果他们请求非阻塞操作,则会通知没有更多缓冲区空间)他们的插座)。然后,当接收方再次开始接收时,发送方将被允许发送更多内容。
You can definitely do a blocking send to a UNIX Domain socket. If the receiving side's receive buffer is full, or if the number of outstanding (undelivered) send socket buffers is too high, the sender will block.
SOCK_STREAM UNIX Domain Sockets work like TCP sockets. SOCK_DGRAM UNIX Domain Sockets work like UDP, except that UNIX Domain datagrams have guaranteed, in-order delivery, whereas UDP sockets can be re-ordered or dropped. (Also, UNIX Domain Sockets can be used to send file descriptors and pass user credentials between processes, neither of which can be done with TCP, UDP, or pipes.)
So, because in-order delivery is guaranteed by all types of UNIX Domain Sockets, the receiver can just stop receiving when it is busy doing other things, and the sender will be automatically blocked when there's no more buffer space available (or will be notified that there's no more buffer space, if they requested non-blocking operation on their socket). Then, when the receiver starts receiving again, the sender will be allowed to send more.
除非您将其包含在协议中,否则服务器无法告诉客户端暂停发送信息。
Unless you include this in the protocol, there is no way for the server to tell the client to pause sending the information.
除了服务器知道它何时“忙”并发送回特定信号(例如 HTTP 的 503 服务不可用)之外。您还可以将客户端连接设置为在一定时间长度后超时,如果收到超时事件,则将其解释为服务器正忙。
Other than the server having some knowledge of when it is 'busy' and sending a specific signal back (e.g. HTTP's 503 Service Unavailable). You can also set up the client side connection to timeout after a certain length of time, and if you get a timeout event, interpret that as the server is busy.