【发布时间】:2012-10-07 07:00:09
【问题描述】:
我在我的程序中使用以下系统调用:
recvfrom
sendto
sendmsg
从上面提到的每个系统调用中,我检查它是否在没有任何中断的情况下完成,如果它被中断,我会重试。
例如:
recvagain:
len = recvfrom(fd, response, MSGSIZE, MSG_WAITALL, (struct sockaddr *)&from, &fromlen);
if (errno == EINTR) {
syslog(LOG_NOTICE, "recvfrom interrupted: %s", strerror(errno));
goto recvagain;
}
这里的问题是每次失败时我是否需要将 errno 值重置为 0。或者如果recvfrom() 成功,是否将errno 重置为0?
recvfrom() 手册页说:
成功完成后,recvfrom() 以字节为单位返回消息的长度。如果没有可接收的消息并且 peer 执行了有序的关闭,recvfrom() 返回 0。 否则,函数返回 -1 并设置 errno 以指示 错误。
sendto 和 sendmsg 的情况相同。
我现在无法真正检查这个,因为我无权访问服务器-客户端设置。 有什么想法吗?
谢谢
【问题讨论】:
标签: c linux operating-system system-calls systems-programming