【发布时间】:2009-02-25 08:07:44
【问题描述】:
我看到一小部分使用 write(2) 写入非阻塞 TCP 套接字的消息在源接口上看不到,也没有被目标接收到。
可能是什么问题?应用程序有什么方法可以检测到这一点并重试?
while (len > 0) {
res = write (c->sock_fd, tcp_buf, len);
if (res < 0) {
switch (errno) {
case EAGAIN:
case EINTR:
<handle case>
break;
default:
<close connection>
}
}
else {
len -= res;
}
}
【问题讨论】:
-
你能把代码贴在这儿还是在粘贴箱里?
-
while (len > 0) { res = write (c->sock_fd, tcp_buf, len); if (res break;默认值: }
-
在你的 else 部分你也应该做
tcp_buf = ((char*)tcp_buf) + res; -
我仍然看到问题。在大约 1000 个请求中,有 4 个请求没有到达套接字。
-
在我的回答中检查关于短期套接字的编辑。
标签: tcp nonblocking