Rearranged the packet and serial code to make more sense
This mostly just reimplements the best parts of the discarded branch: > discard-encapsulated-packets There may still be some work needed.
This commit is contained in:
@@ -21,12 +21,13 @@
|
||||
*/
|
||||
#include "udp_network_utility.hpp"
|
||||
|
||||
#include "serial.hpp"
|
||||
#include "serial_packet.hpp"
|
||||
#include "serial_utility.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
//BUGFIX: memset() is used before sending a packet to remove old data; you don't want to send sensitive data over the network
|
||||
//NOTE: don't confuse SerialPacket with UDPpacket
|
||||
//NOTE: don't confuse SerialPacketBase with UDPpacket
|
||||
|
||||
void UDPNetworkUtility::Open(int port) {
|
||||
socket = SDLNet_UDP_Open(port);
|
||||
@@ -152,10 +153,10 @@ int UDPNetworkUtility::Receive() {
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
//send a SerialPacket
|
||||
//send a SerialPacketBase
|
||||
//-------------------------
|
||||
|
||||
int UDPNetworkUtility::SendTo(const char* ip, int port, SerialPacket* serialPacket) {
|
||||
int UDPNetworkUtility::SendTo(const char* ip, int port, SerialPacketBase* serialPacket) {
|
||||
IPaddress add;
|
||||
if (SDLNet_ResolveHost(&add, ip, port) == -1) {
|
||||
throw(std::runtime_error("Failed to resolve a host"));
|
||||
@@ -164,7 +165,7 @@ int UDPNetworkUtility::SendTo(const char* ip, int port, SerialPacket* serialPack
|
||||
SendTo(&add, serialPacket);
|
||||
}
|
||||
|
||||
int UDPNetworkUtility::SendTo(IPaddress* add, SerialPacket* serialPacket) {
|
||||
int UDPNetworkUtility::SendTo(IPaddress* add, SerialPacketBase* serialPacket) {
|
||||
memset(packet->data, 0, packet->maxlen);
|
||||
serializePacket(serialPacket, packet->data);
|
||||
packet->len = PACKET_BUFFER_SIZE;
|
||||
@@ -179,7 +180,7 @@ int UDPNetworkUtility::SendTo(IPaddress* add, SerialPacket* serialPacket) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int UDPNetworkUtility::SendTo(int channel, SerialPacket* serialPacket) {
|
||||
int UDPNetworkUtility::SendTo(int channel, SerialPacketBase* serialPacket) {
|
||||
memset(packet->data, 0, packet->maxlen);
|
||||
serializePacket(serialPacket, packet->data);
|
||||
packet->len = PACKET_BUFFER_SIZE;
|
||||
@@ -193,7 +194,7 @@ int UDPNetworkUtility::SendTo(int channel, SerialPacket* serialPacket) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int UDPNetworkUtility::SendToAllChannels(SerialPacket* serialPacket) {
|
||||
int UDPNetworkUtility::SendToAllChannels(SerialPacketBase* serialPacket) {
|
||||
memset(packet->data, 0, packet->maxlen);
|
||||
serializePacket(serialPacket, packet->data);
|
||||
packet->len = PACKET_BUFFER_SIZE;
|
||||
@@ -210,7 +211,7 @@ int UDPNetworkUtility::SendToAllChannels(SerialPacket* serialPacket) {
|
||||
return sent;
|
||||
}
|
||||
|
||||
int UDPNetworkUtility::Receive(SerialPacket* serialPacket) {
|
||||
int UDPNetworkUtility::Receive(SerialPacketBase* serialPacket) {
|
||||
memset(packet->data, 0, packet->maxlen);
|
||||
int ret = SDLNet_UDP_Recv(socket, packet);
|
||||
deserializePacket(serialPacket, packet->data);
|
||||
|
||||
Reference in New Issue
Block a user