"connection reset by peer"的可能原因

[b][size=large]对方没有close就cancel了socket pair,你就会收到一个sig_pipe信号然后strerror会显示“connection reset by peer”的错误。防止程序退出解决方法就是处理SIGPIPE信号[/size][/b]


屏蔽信号的代码

      void   InstalSignal()
{
signal(SIGHUP ,SIG_IGN ); /* hangup, generated when terminal disconnects */
signal(SIGINT ,SIG_IGN ); /* interrupt, generated from terminal special char */
signal(SIGQUIT ,SIG_IGN ); /* (*) quit, generated from terminal special char */
signal(SIGILL ,SIG_IGN ); /* (*) illegal instruction (not reset when caught)*/
signal(SIGTRAP ,SIG_IGN ); /* (*) trace trap (not reset when caught) */
signal(SIGABRT ,SIG_IGN ); /* (*) abort process */
#ifdef D_AIX
signal(SIGEMT ,SIG_IGN ); /* EMT intruction */
#endif
signal(SIGFPE ,SIG_IGN ); /* (*) floating point exception */
signal(SIGKILL ,SIG_IGN ); /* kill (cannot be caught or ignored) */
signal(SIGBUS ,SIG_IGN ); /* (*) bus error (specification exception) */
signal(SIGSEGV ,SIG_IGN ); /* (*) segmentation violation */
signal(SIGSYS ,SIG_IGN ); /* (*) bad argument to system call */
signal(SIGPIPE ,SIG_IGN ); /* write on a pipe with no one to read it */
signal(SIGALRM ,SIG_IGN ); /* alarm clock timeout */
//signal(SIGTERM ,stopproc ); /* software termination signal */
signal(SIGURG ,SIG_IGN ); /* (+) urgent contition on I/O channel */
signal(SIGSTOP ,SIG_IGN ); /* (@) stop (cannot be caught or ignored) */
signal(SIGTSTP ,SIG_IGN ); /* (@) interactive stop */
signal(SIGCONT ,SIG_IGN ); /* (!) continue (cannot be caught or ignored) */
signal(SIGCHLD ,SIG_IGN); /* (+) sent to parent on child stop or exit */
signal(SIGTTIN ,SIG_IGN); /* (@) background read attempted from control terminal*/
signal(SIGTTOU ,SIG_IGN); /* (@) background write attempted to control terminal */
signal(SIGIO ,SIG_IGN); /* (+) I/O possible, or completed */
signal(SIGXCPU ,SIG_IGN); /* cpu time limit exceeded (see setrlimit()) */
signal(SIGXFSZ ,SIG_IGN); /* file size limit exceeded (see setrlimit()) */

#ifdef D_AIX
signal(SIGMSG ,SIG_IGN); /* input data is in the ring buffer */
#endif

signal(SIGWINCH,SIG_IGN); /* (+) window size changed */
signal(SIGPWR ,SIG_IGN); /* (+) power-fail restart */
//signal(SIGUSR1 ,stopproc); /* user defined signal 1 */
//signal(SIGUSR2 ,stopproc); /* user defined signal 2 */
signal(SIGPROF ,SIG_IGN); /* profiling time alarm (see setitimer) */

#ifdef D_AIX
signal(SIGDANGER,SIG_IGN); /* system crash imminent; free up some page space */
#endif

signal(SIGVTALRM,SIG_IGN); /* virtual time alarm (see setitimer) */

#ifdef D_AIX
signal(SIGMIGRATE,SIG_IGN); /* migrate process */
signal(SIGPRE ,SIG_IGN); /* programming exception */
signal(SIGVIRT ,SIG_IGN); /* AIX virtual time alarm */
signal(SIGALRM1,SIG_IGN); /* m:n condition variables - RESERVED - DON 'T USE */
signal(SIGWAITING,SIG_IGN); /* m:n scheduling - RESERVED - DON 'T USE */
signal(SIGCPUFAIL ,SIG_IGN); /* Predictive De-configuration of Processors - */
signal(SIGKAP,SIG_IGN); /* keep alive poll from native keyboard */
signal(SIGRETRACT,SIG_IGN); /* monitor mode should be relinguished */
signal(SIGSOUND ,SIG_IGN); /* sound control has completed */
signal(SIGSAK ,SIG_IGN); /* secure attention key */
#endif
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值