-1
こんにちは私はここからこのrecv()ループを使用しています:Winsock recv() does not block recv()関数は常に-1を返してループを終了し、何かを受け取る。非ブロッキングソケットを持つメインのコードを呼び出すwinsock recv()は常に-1を返します
int System::receive(SOCKET &recvSocket)
{
char buffer[4096] = { 0 };
int numBytes;
do {
numBytes = recv(recvSocket, buffer, 4095, 0);
//lastReceived = lastReceived + buffer;
//get recent contents of buffer
cout << numBytes << endl;
if (numBytes > 0)
{
cout << buffer << endl;
continue;
}
if (numBytes == 0)
{
std::cout << "Client disconnected!" << std::endl;
break;
}
int nError = WSAGetLastError();
cout << nError << endl;
if (nError != WSAEWOULDBLOCK)
{
std::cout << "Winsock error code: " << nError << std::endl;
break;
}
} while (1);
return numBytes;
}
:
SOCKET establishedConn = Server.acceptSocket(listenSocket);
u_long iMode = 1;
if (establishedConn != NULL) {
ioctlsocket(establishedConn, FIONBIO, &iMode);
Server.receive(establishedConn); //receive request from client
}
をその何も返さない理由理由はありますか?