服务器编程入门(13) Linux套接字设置超时的三种方法


摘要:

    本文介绍在套接字的I/O操作上设置超时的三种方法。


handle_msg((, (strlen(sendbuf) > ( !strcmp(sendbuf, (recv(sockfd,recvbuf,BUFSIZE,) > (errno == sig_alrm(

运行截图:

handle_msg((, (strlen(sendbuf) > ( !strcmp(sendbuf, (readable_timeo(sockfd, ) == readable_timeo( fd, &&== (fd+, &rset, NULL, NULL, &

 

运行截图:

handle_msg( recvbuf[BUFSIZE + = = &tv, (, (strlen(sendbuf) > ( !strcmp(sendbuf, ( (n=recv(sockfd,recvbuf,BUFSIZE,)) < (errno ==

运行截图:

image

可以看到,超时警报成功运行,但依然有上一例中的延迟接收的情况发生,不作处理。


 

示例源码上传到了github上,地址:https://github.com/zs634134578/UNP/tree/tryTimeout

 

 

参考资料:

《UNIX网络编程 卷1:套接字联网API(第3版)》

相关内容