您的位置:首页 > 其它

recvfrom设置超时

2014-03-09 01:54 260 查看
struct timeval tv;
int ret;
tv.tv_sec = 10;
tv.tv_usec = 0;
if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) < 0) {
printf("socket option  SO_RCVTIMEO not support\n");
return;
}
if ((ret = recvfrom(s, buf, sizeof buf, 0, NULL, NULL)) < 0) {
if (ret == EWOULDBLOCK || ret == EAGAIN)
printf("recvfrom timeout\n");
else
printf("recvfrom err:%d\n", ret);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  recvfrom socket超时