"connection reset by peer"的可能原因

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


屏蔽信号的代码

      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
}

猜你喜欢

转载自ocelot1985-163-com.iteye.com/blog/1064580