Recv不正确地返回零 [英] Recv returning zero incorrectly
本文介绍了Recv不正确地返回零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个有趣的问题,
- 我将数据字节数据发送到我的服务器,从我的客户端和recv总是返回零。
- 我已验证该函数确实正在获取数据并将其放入char数组中。
- 我已验证客户端在recv()返回零后仍然正确连接,并且仍然可以发送和接收数据到
这对我造成了问题。我需要总计了进来的字符以确定消息何时完成。有人可以解释什么可能导致recv()命令以这种方式执行?
This creates a problem for me. I need to total up the chars coming in to determine when a message is completed. Can someone explain what could cause the recv() command to behave in this manner?
// clean the buffer of any previous received data
// by resetting all bytes to zero
ReadBufferClear();
// try to read some data, using the read buffer
if(this->Return_Value = recv(this->Socket_Filedescriptor,
this->ReadBuffer_Data,
this->ReadBuffer_Size,
0) == -1)
{
// returned -1, notify the server it needs
// to remove this connections FD, and
// close this connection class entry;
return -1;
}
// print return value
fprintf(stdout,"%i\n",this->Return_Value);
// print out the bytes
for(int curPos =0; curPos<this->ReadBuffer_Size; curPos++)
fprintf(stdout,"%i\n",this->ReadBuffer_Data[curPos]);
输出如下所示:
0
0
1
-1
-1
-1
-2
-1
-1
0
0
0 0 1 -1 -1 -1 -2 -1 -1 0 0
推荐答案
您有优先问题。该行应为
You have a precedence problem. The line should be of the form
if ((this->ReturnValue = recv(..).)) == -1)
目前,您正在将recv()的结果与-1进行比较,
At present you're comparing the result of recv() with -1 and storing the Boolean result of that comparison into ReturnValue.
所以recv()根本不返回零。
So recv() isn't returning zero at all.
这篇关于Recv不正确地返回零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文