socket Accept失败

1、  Failed Reason

accetp() 是慢系统调用,在信号产生时会中断其调用并将 errno 变量设置为 EINTR
此时应重新调用 accept() unix signal 会中断系统调用,所以你要在程序中自己判断是否被 signal 所中断,方法是 errno==EINTR

Interrupted system call

 

2、  Fix

while ( connect (fd, &name, namelen) == -1 && errno != EISCONN )//failed
  
if ( errno != EINTR
 )
    
{
      
perror ("connect");
      
exit (EXIT_FAILURE);//not signal, so break,or next circle
    
}

 

while(1) {
if ( (connfd = accept(....)) == -1 ) {
if (errno == EINTR)
continue;
perror("accept()");
exit(1);
}

/* do sth with "connfd" */
}

 

3、  reference

Unix connect() and interrupted system calls

你可能感兴趣的:(socket,unix,System,border,Signal,网格)