zl程序教程

您现在的位置是:首页 >  其它

当前栏目

recvfrom设置超时

设置 超时 recvfrom
2023-06-13 09:12:41 时间

大家好,又见面了,我是你们的朋友全栈君。

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);
}

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/163438.html原文链接:https://javaforall.cn