我有一个有趣的问题,
这给我带来了麻烦。我需要总结出来的字符以确定消息何时完成。有人能解释一下导致recv()命令以这种方式运行的原因吗?
// 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)
您有优先权问题。该行的格式应为
if ((this->ReturnValue = recv(..).)) == -1)
目前,您正在将recv()的结果与-1进行比较,并将该比较的布尔结果存储到ReturnValue中。
所以recv()根本不会返回零。