Compare commits
1 Commits
d2d7c82ca4
...
3ba33575e6
Author | SHA1 | Date | |
---|---|---|---|
|
3ba33575e6 |
2
Makefile
2
Makefile
@ -33,7 +33,7 @@ COMMON_OBJS := \
|
|||||||
$(OBJDIR)/src/lib_SDL_Log.o \
|
$(OBJDIR)/src/lib_SDL_Log.o \
|
||||||
$(OBJDIR)/src/signal_common.o \
|
$(OBJDIR)/src/signal_common.o \
|
||||||
$(OBJDIR)/src/UDPbase.o \
|
$(OBJDIR)/src/UDPbase.o \
|
||||||
$(OBJDIR)/src/SafeUDPpacket.o \
|
$(OBJDIR)/src/SafeUDPpacketV.o \
|
||||||
$(OBJDIR)/src/util.o
|
$(OBJDIR)/src/util.o
|
||||||
|
|
||||||
SERVER_OBJS := \
|
SERVER_OBJS := \
|
||||||
|
@ -86,59 +86,3 @@ class SafeUDPpacket
|
|||||||
Uint8 *data (Uint8* data) const { return get()->data = data; }
|
Uint8 *data (Uint8* data) const { return get()->data = data; }
|
||||||
Uint8 *data (void) const { return get()->data; }
|
Uint8 *data (void) const { return get()->data; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class SafeUDPpacketV
|
|
||||||
{
|
|
||||||
std::vector<SafeUDPpacket> m_packetV;
|
|
||||||
public:
|
|
||||||
SafeUDPpacketV (const void*, const int, const int mtu = 1450);
|
|
||||||
SafeUDPpacketV (int howmany, int size)
|
|
||||||
{
|
|
||||||
UDPpacket** p;
|
|
||||||
m_packetV.reserve (howmany);
|
|
||||||
if (NULL == (p = SDLNet_AllocPacketV (howmany, size)))
|
|
||||||
{
|
|
||||||
throw "SDLNet_AllocPacketV: " + std::string (SDLNet_GetError ());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (; (p != NULL) && (*p != NULL); p++)
|
|
||||||
{
|
|
||||||
m_packetV.push_back (SafeUDPpacket (*p));
|
|
||||||
}
|
|
||||||
SDL_assert ((m_packetV.size () > 0) && (howmany == (int)m_packetV.size ()));
|
|
||||||
/*
|
|
||||||
* SDLNet_FreePacketV just calls SDLNet_FreePacket on each packet.
|
|
||||||
* The "packetV" itself is just something allocated on the heap.
|
|
||||||
* We don't need this any longer.
|
|
||||||
*/
|
|
||||||
SDL_free (p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int Send (UDPsocket sock)
|
|
||||||
{
|
|
||||||
size_t size;
|
|
||||||
int numsent;
|
|
||||||
UDPpacket** pV;
|
|
||||||
size = m_packetV.size ();
|
|
||||||
if (NULL != (pV = (UDPpacket**)SDL_malloc (sizeof (UDPpacket*) * size)))
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < size; i++)
|
|
||||||
pV[i] = m_packetV[i].get ();
|
|
||||||
numsent = SDLNet_UDP_SendV (sock, pV, size);
|
|
||||||
SDL_free (pV);
|
|
||||||
}
|
|
||||||
return numsent;
|
|
||||||
}
|
|
||||||
|
|
||||||
const SafeUDPpacket& get (size_t idx) { return m_packetV.at (idx); }
|
|
||||||
size_t size (void) const { return m_packetV.size (); }
|
|
||||||
|
|
||||||
void channel (int channel) { for (auto& p : m_packetV) { p.channel (channel); } }
|
|
||||||
void len (int len) { for (auto& p : m_packetV) { p.len (len); } }
|
|
||||||
void maxlen (int maxlen) { for (auto& p : m_packetV) { p.maxlen (maxlen); } }
|
|
||||||
void status (int status) { for (auto& p : m_packetV) { p.status (status); } }
|
|
||||||
void address (IPaddress address) { for (auto& p : m_packetV) { p.address (address); } }
|
|
||||||
|
|
||||||
std::string toString (void);
|
|
||||||
};
|
|
||||||
|
60
include/SafeUDPpacketV.h
Normal file
60
include/SafeUDPpacketV.h
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "SafeUDPpacket.h"
|
||||||
|
|
||||||
|
class SafeUDPpacketV
|
||||||
|
{
|
||||||
|
std::vector<SafeUDPpacket> m_packetV;
|
||||||
|
public:
|
||||||
|
SafeUDPpacketV (const void*, const int, const int mtu = 1450);
|
||||||
|
SafeUDPpacketV (int howmany, int size)
|
||||||
|
{
|
||||||
|
UDPpacket** p;
|
||||||
|
m_packetV.reserve (howmany);
|
||||||
|
if (NULL == (p = SDLNet_AllocPacketV (howmany, size)))
|
||||||
|
{
|
||||||
|
throw "SDLNet_AllocPacketV: " + std::string (SDLNet_GetError ());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (; (p != NULL) && (*p != NULL); p++)
|
||||||
|
{
|
||||||
|
m_packetV.push_back (SafeUDPpacket (*p));
|
||||||
|
}
|
||||||
|
SDL_assert ((m_packetV.size () > 0) && (howmany == (int)m_packetV.size ()));
|
||||||
|
/*
|
||||||
|
* SDLNet_FreePacketV just calls SDLNet_FreePacket on each packet.
|
||||||
|
* The "packetV" itself is just something allocated on the heap.
|
||||||
|
* We don't need this any longer.
|
||||||
|
*/
|
||||||
|
SDL_free (p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int Send (UDPsocket sock)
|
||||||
|
{
|
||||||
|
size_t size;
|
||||||
|
int numsent;
|
||||||
|
UDPpacket** pV;
|
||||||
|
size = m_packetV.size ();
|
||||||
|
if (NULL != (pV = (UDPpacket**)SDL_malloc (sizeof (UDPpacket*) * size)))
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < size; i++)
|
||||||
|
pV[i] = m_packetV[i].get ();
|
||||||
|
numsent = SDLNet_UDP_SendV (sock, pV, size);
|
||||||
|
SDL_free (pV);
|
||||||
|
}
|
||||||
|
return numsent;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t size (void) const { return m_packetV.size (); }
|
||||||
|
const SafeUDPpacket& get (size_t idx) { return m_packetV.at (idx); }
|
||||||
|
|
||||||
|
void channel (int channel) { for (auto& p : m_packetV) { p.channel (channel); } }
|
||||||
|
void len (int len) { for (auto& p : m_packetV) { p.len (len); } }
|
||||||
|
void maxlen (int maxlen) { for (auto& p : m_packetV) { p.maxlen (maxlen); } }
|
||||||
|
void status (int status) { for (auto& p : m_packetV) { p.status (status); } }
|
||||||
|
void address (IPaddress address) { for (auto& p : m_packetV) { p.address (address); } }
|
||||||
|
|
||||||
|
std::string toString (void);
|
||||||
|
};
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
#include "SafeUDPpacket.h"
|
#include "SafeUDPpacketV.h"
|
||||||
|
|
||||||
SafeUDPpacketV::SafeUDPpacketV (const void* buf, const int size, const int mtu)
|
SafeUDPpacketV::SafeUDPpacketV (const void* buf, const int size, const int mtu)
|
||||||
{
|
{
|
@ -8,7 +8,7 @@
|
|||||||
#include "unused.h"
|
#include "unused.h"
|
||||||
#include "UDPbase.h"
|
#include "UDPbase.h"
|
||||||
#include "FileIO.h"
|
#include "FileIO.h"
|
||||||
#include "SafeUDPpacket.h"
|
#include "SafeUDPpacketV.h"
|
||||||
#include "lib_GetOpt.h"
|
#include "lib_GetOpt.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
Loading…
Reference in New Issue
Block a user