gpt4 book ai didi

sockets - libuv 如何在对等方(linux)重置连接时忽略 SIGPIPE

转载 作者:行者123 更新时间:2023-12-03 11:50:27 24 4
gpt4 key购买 nike

我收到了 SIGPIPE来自 uv_write()因为连接是由对等方重置的。

p/x stream->flags
0x46064

./src/unix/internal.h:# define UV__POLLRDHUP 0x2000

用于 BSD 防止 SIGPIPE libuv 有:
./src/unix/core.c

#if defined(SO_NOSIGPIPE)
{
int on = 1;
setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, &on, sizeof(on));
}
#endif

Linux 没有 SO_NOSIGPIPE作为一种选择。任何关于如何处理的建议 SIGPIPEsignal(SIGPIPE, SIG_IGN); 之外的 Linux 信号

最佳答案

您必须更新 uv_write()调用 send() MSG_NOSIGNAL旗帜:

Don't generate a SIGPIPE signal if the peer on a stream-oriented socket has closed the connection. The EPIPE error is still returned. This provides similar behavior to using sigaction(2) to ignore SIGPIPE, but, whereas MSG_NOSIGNAL is a per-call feature, ignoring SIGPIPE sets a process attribute that affects all threads in the process.

关于sockets - libuv 如何在对等方(linux)重置连接时忽略 SIGPIPE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44551990/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com