int network_udp_send(UDPsocket udp, int channel, Uint8* data) { UDPpacket* d = network_packet_alloc(data[0]); d->data = data; int r = network_udp_send(udp, channel, d); network_packet_free(d); return r; }
/* * network_udp_send() - Send data via UDP over the given channel * ! When the function is called without a packet, simply call it with a temporary one * @udp: the socket to send the data through * @channel: the channel to use * @data: the data to send as a packet */ int network_udp_send(UDPsocket udp, int channel, Uint8* data) { UDPpacket* d = network_packet_alloc(data[0]); // Allocate space for the data packet d->data = data; // Set the packet data int r = network_udp_send(udp, channel, d); // Send the packet network_packet_free(d); // Free the packet return r; // Return the amount of destinations the data was sent to on success, or -1 on failure }
int network_packet_realloc(UDPpacket* packet, int size) { network_packet_free(packet); packet = network_packet_alloc(size); return (packet == NULL) ? 1 : 0; }
/* * network_packet_realloc() - Reallocate space for the packet data * ! Perhaps use this function if network_packet_resize() fails * @packet: the packet to reallocate * @size: the new size of the packet */ int network_packet_realloc(UDPpacket* packet, int size) { network_packet_free(packet); // Free the packet packet = network_packet_alloc(size); // Allocate the packet return (packet == nullptr) ? 1 : 0; // Return 0 on success and 1 on failure }