Example #1
0
int32_t udp_reactor_callback( CReactor *pReactor, CSocket *pSocket, void *pUserData )
{
	char recvBuf[1024] = { 0x00, };
		CNetAddr stPeerAddr;
		
		int32_t iRetCode = net_recvfrom( pSocket, recvBuf, sizeof(recvBuf), &stPeerAddr );
		if ( iRetCode > 0 )
		{
			char respbuf[1024 * 2] = { 0x00, };
			
			sprintf( respbuf, "%s:%d hi, %s", stPeerAddr.pIP, stPeerAddr.iPort, recvBuf );
			
			log_print( respbuf );
		
		}
		else 
		{
			log_print( "recv from failed?????????????????" );
			if ( SOCKET_ERROR == iRetCode )
			{
				log_print( "close socket, pSocket->iSocketId-->%d....................", pSocket->iSocketId );
				remove_reactor_socket( pReactor, pSocket );
				pSocket = NULL;
			}	
		}
	
	return 0;	
}
Example #2
0
qboolean	NET_GetPacket (netsrc_t sock, netadr_t *net_from, sizebuf_t *net_message)
{
	int 	ret;
	struct sockaddr_in	from;
	int		fromlen;
	int		net_socket;
	int		protocol;
	int		err;

	if (NET_GetLoopPacket (sock, net_from, net_message))
		return true;

	for (protocol = 0 ; protocol < 2 ; protocol++)
	{
		if (protocol == 0)
			net_socket = ip_sockets[sock];
		else
			net_socket = ipx_sockets[sock];

		if (!net_socket)
			continue;

		fromlen = sizeof(from);
// >>> FIX: For Nintendo Wii using devkitPPC / libogc
// Switching to the equivalent function (and data structures) in the platform:
		//ret = recvfrom (net_socket, net_message->data, net_message->maxsize
		//	, 0, (struct sockaddr *)&from, &fromlen);
		//if (ret == -1)
		ret = net_recvfrom (net_socket, net_message->data, net_message->maxsize > 4096 ? 4096 : net_message->maxsize
			, 0, (struct sockaddr *)&from, &fromlen);
		if (ret < 0)
// <<< FIX
		{
// >>> FIX: For Nintendo Wii using devkitPPC / libogc
// Switching to the equivalent data structures in the platform:
			//err = errno;

			//if (err == EWOULDBLOCK || err == ECONNREFUSED)
			if (ret == -EWOULDBLOCK || ret == -ECONNREFUSED)
// <<< FIX
				continue;
			Com_Printf ("NET_GetPacket: %s from %s\n", NET_ErrorString(),
						NET_AdrToString(*net_from));
			continue;
		}

// >>> FIX: For Nintendo Wii using devkitPPC / libogc
// Adjusting for previous fixes:
		//if (ret == net_message->maxsize)
		if((ret == net_message->maxsize)||(ret >= 4096))
// <<< FIX
		{
			Com_Printf ("Oversize packet from %s\n", NET_AdrToString (*net_from));
			continue;
		}

		net_message->cursize = ret;
		SockadrToNetadr (&from, net_from);
		return true;
	}

	return false;
}