在 solaris 中如何检测 send() 调用中损坏的套接字?我不想使用信号。
我尝试了 SO_NOSIGPIPE 和 MSG_NOSIGNAL,但两者在 Solaris 中都不可用,我的程序因“管道损坏”错误而被杀死。
有什么方法可以检测破损的管道吗?
谢谢!
最佳答案
您必须使用 sigaction()
专门忽略 SIGPIPE
信号:
struct sigaction act;
act.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &act, NULL);
...然后 send()
将返回 -1,errno
设置为 EPIPE
。
关于c - 在 Solaris send() 调用中检测损坏的管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2205455/