int network_udp_recvv(UDPsocket udp, UDPpacket** packets) { int recv = 0; recv = SDLNet_UDP_RecvV(udp, packets); if (recv == -1) { std::cerr << "Failed to recieve vector data over UDP: " << SDLNet_GetError() << "\n"; } return recv; }
/* Receive a single packet from the UDP socket. The returned packet contains the source address and the channel it arrived on. If it did not arrive on a bound channel, the the channel will be set to -1. This function returns the number of packets read from the network, or -1 on error. This function does not block, so can return 0 packets pending. */ int SDLNet_UDP_Recv(UDPsocket sock, UDPpacket *packet) { UDPpacket *packets[2]; /* Receive a packet array of 1 */ packets[0] = packet; packets[1] = NULL; return(SDLNet_UDP_RecvV(sock, packets)); }
/* * network_udp_recvv() - Receive multiple data packets via UDP * @udp: the socket to receive the data from * @packets: the pointer to store the data at */ int network_udp_recv_vector(UDPsocket udp, UDPpacket** packets) { int recv = 0; // Define how many packets were received recv = SDLNet_UDP_RecvV(udp, packets); // Attempt to receive the data if (recv == -1) { // If an error occured while receiving the data std::cerr << "Failed to receive vector data over UDP: " << SDLNet_GetError() << "\n"; // Output the error message return -1; // Return -1 on failure } return recv; // Return the amount of packets that were received on success, or 0 for no packets }