我有一个小程序,它将文件通过网络发送到位于Windows操作系统上的代理。
当该应用程序在Windows上运行时,一切正常,通信良好,所有文件都成功复制。
但是,当该应用程序在Linux上运行(RedHat 5.3,接收方仍为Windows)时,我会看到Wireshark网络跟踪中出现TCP Zero Window和TCP Window Full消息,每1-2秒钟就会出现一次。几分钟后,代理关闭连接。
Windows-Linux代码几乎相同且非常简单。唯一的非平凡操作是使用SO_SNDBUF和0xFFFF值进行setsockopt。删除此代码并没有帮助。
请问是否有人能够帮我解决这个问题?
编辑:添加发送代码 - 看起来它正确处理了部分写入:
int totalSent=0;
while(totalSent != dataLen)
{
int bytesSent
= ::send(_socket,(char *)(data+totalSent), dataLen-totalSent, 0);
if (bytesSent ==0) {
return totalSent;
}
else if(bytesSent == SOCKET_ERROR){
#ifdef __WIN32
int errcode = WSAGetLastError();
if( errcode==WSAEWOULDBLOCK ){
#else
if ((errno == EWOULDBLOCK) || (errno == EAGAIN)) {
#endif
}
else{
if( !totalSent ) {
totalSent = SOCKET_ERROR;
}
break;
}
}
else{
totalSent+=bytesSent;
}
}
}
提前致谢。
::send(...)
是什么?这是您的类的成员函数,它包装了标准的send(...)
函数吗? - Robert S. Barnes