|
|
检测socket客户端异常断开时候可不可以这样子?
int numbytes = recv(Jinfo->clientfd, receive, rcvlen, 0);
if ( numbytes <= 0){
if (errno == EINTR){ 被中断 继续循环 }
int s_errno;
socklen_t len_t = sizeof(s_errno);
if (getsockopt(Jinfo->clientfd, SOL_SOCKET, SO_ERROR, &s_errno, &len_t) == -1){
printf("we have a SO_ERROR on socket %d, close and return it!\n", Jinfo->clientfd);
close (Jinfo->clientfd);
return 0;
}
}
s_errno表示SO_ERROR值 当select检测到可读 但recv返回为0 或者-1时候表示对方断开???
我的程序中断客户端的时候 得到errno的值为104 不知道为什么 上面两个if都没有执行到 |
|