예제 #1
0
int SocketChannel::readN(RawBuffer &rb)
{
	int hasRecvCounts = 0;
	char buffer[MAX_BUFFER_LENGTH] = {0};
	int result = 0;

	while ((result = recv((SOCKET)_sock.getHandle(), buffer + hasRecvCounts, MAX_BUFFER_LENGTH - hasRecvCounts, 0)))
	{
		if (result < 0)
		{
			if (errno == EWOULDBLOCK)
			{
				break;
			}else if ( errno == EINTR)
			{
				break;
			}
		}else if (result == 0)
		{
			break;
		}

		hasRecvCounts += result;
		
	}
	result = handleResultErrorResult(result);

	if (result > 0)
	{
		rb.setRawData((unsigned char *)buffer, (unsigned int)hasRecvCounts);
		result = hasRecvCounts;
	}

	return result;
}
예제 #2
0
int SocketChannel::readN(RawBuffer &rb, CommunicatioInformation &ci)
{
	char buffer[MAX_READ_BUFFER_SIZE] = {0};

	SOCKADDR_IN addr = {0};
	int addrSize = sizeof(addr);
	int result = -1;

	result = recvfrom(_sock.getHandle(), buffer, MAX_READ_BUFFER_SIZE, 0, (sockaddr *)&addr, &addrSize);



	if (result > 0)
	{
		rb.setRawData((unsigned char *)buffer, result);
		ci.hostAddress = addr.sin_addr.S_un.S_addr;
		ci.port = addr.sin_port;
		ci.setConnectionType(CT_Socket);
		ci.setSocketMode(SM_UDP);
	}

	return result;

}