39 #ifndef G3D_NETWORKDEVICE_H
40 #define G3D_NETWORKDEVICE_H
211 size_t L = (size_t)b.
length();
213 if ((
size_t)b.
length() == L) {
228 #if defined(__GNUC__)
229 *lenPtr = gcchtonl(len);
231 *lenPtr = htonl(len);
277 template<
typename T>
inline void send(
uint32 type,
const T& message) {
295 if (array.
size() > 0) {
296 array[0]->binaryOutput.reset();
299 for (
int i = 0; i < array.
size(); ++i) {
313 template<
typename T>
inline bool receive(T& message) {
321 message.deserialize(b);
325 receiveBufferUsedSize = 0;
341 receiveBufferUsedSize = 0;
453 format(
"This LightweightConduit is limited to messages of "
454 "%d bytes (Ethernet hardware limit; this is the "
459 format(
"This LightweightConduit is limited to messages of "
460 "%d bytes (Ethernet hardware limit; this is the "
469 static LightweightConduitRef
create(
uint16 receivePort,
bool enableReceive,
bool enableBroadcast);
479 serializedPacketSize(s),
508 for (
int i = 0; i < a.
size(); ++i) {
519 messageBuffer.
size() - 4,
521 message.deserialize(b);
731 # pragma GCC system_header
static LightweightConduitRef create(uint16 receivePort, bool enableReceive, bool enableBroadcast)
Definition: NetworkDevice.cpp:989
Conduit()
Definition: NetworkDevice.cpp:540
bool bind(SOCKET sock, const NetAddress &addr) const
Definition: NetworkDevice.cpp:484
void describe(TextOutput &t) const
Definition: NetworkDevice.cpp:188
uint32 messageSize
Definition: NetworkDevice.h:185
SOCKET sock
Definition: NetworkDevice.h:552
void receiveHeader()
Definition: NetworkDevice.cpp:875
LightweightConduit(uint16 receivePort, bool enableReceive, bool enableBroadcast)
Definition: NetworkDevice.cpp:999
std::string hostname
Definition: NetworkDevice.h:615
uint32 broadcast
Definition: NetworkDevice.h:627
uint64 bSent
Definition: NetworkDevice.h:64
void closesocket(SOCKET &sock) const
Definition: NetworkDevice.cpp:501
void send(const NetAddress &a, uint32 type, const T &msg)
Definition: NetworkDevice.h:495
std::string name
Definition: NetworkDevice.h:618
Array< EthernetAdapter > m_adapterArray
Definition: NetworkDevice.h:647
static NetListenerRef create(const uint16 port)
Definition: NetworkDevice.cpp:1146
bool initialized
Definition: NetworkDevice.h:645
void addAdapter(const EthernetAdapter &a)
Definition: NetworkDevice.cpp:223
int serializedPacketSize
Definition: NetworkDevice.h:474
uint64 messagesSent() const
Definition: NetworkDevice.cpp:564
Definition: NetworkDevice.h:57
const Array< EthernetAdapter > & adapterArray() const
Definition: NetworkDevice.h:686
virtual uint32 waitingMessageType()
Definition: NetworkDevice.cpp:1093
void send(uint32 type, const T &message)
Definition: NetworkDevice.h:277
State
Definition: NetworkDevice.h:173
Definition: NetworkDevice.h:173
std::string message
Definition: NetworkDevice.h:473
void sendBuffer(const BinaryOutput &b)
Definition: NetworkDevice.cpp:836
void describeSystem(TextOutput &t)
Definition: NetworkDevice.cpp:1254
size_t receiveBufferTotalSize
Definition: NetworkDevice.h:191
static ReliableConduitRef create(const NetAddress &address)
Definition: NetworkDevice.cpp:611
bool clientWaiting() const
Definition: NetworkDevice.cpp:1248
Array< uint32 > m_broadcastAddresses
Definition: NetworkDevice.h:651
virtual bool messageWaiting()
Definition: NetworkDevice.cpp:776
int64 size() const
Definition: BinaryOutput.h:200
void receiveIntoBuffer()
Definition: NetworkDevice.cpp:937
T * getCArray()
Definition: Array.h:256
Dynamic 1D array tuned for performance.
Definition: Array.h:95
bool ok() const
Definition: NetworkDevice.cpp:574
void writeUInt8(uint8 i)
Definition: BinaryOutput.h:283
shared_ptr< class LightweightConduit > LightweightConduitRef
Definition: NetworkDevice.h:355
const uint8 * getCArray() const
Definition: BinaryOutput.h:153
uint64 mSent
Definition: NetworkDevice.h:62
~LightweightConduit()
Definition: NetworkDevice.cpp:1047
Definition: NetAddress.h:18
uint64_t uint64
Definition: g3dmath.h:170
void reset()
Definition: BinaryOutput.cpp:240
uint64 bytesReceived() const
Definition: NetworkDevice.cpp:559
virtual bool messageWaiting()
Definition: NetworkDevice.cpp:1087
void send(const Array< NetAddress > &a, uint32 type, const T &m)
Definition: NetworkDevice.h:504
static void multisend(const Array< ReliableConduitRef > &array, uint32 type, const T &m)
Definition: NetworkDevice.h:290
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
uint16_t uint16
Definition: g3dmath.h:166
SOCKET sock
Definition: NetworkDevice.h:67
~NetListener()
Definition: NetworkDevice.cpp:1204
Definition: NetworkDevice.h:173
std::string localHostName() const
Definition: NetworkDevice.cpp:139
static NetworkDevice * s_instance
Definition: NetworkDevice.h:660
Definition: NetworkDevice.h:471
~ReliableConduit()
Definition: NetworkDevice.cpp:768
uint32 ip
Definition: NetworkDevice.h:621
Definition: ReferenceCount.h:24
NetAddress addr
Definition: NetworkDevice.h:175
uint64 bytesSent() const
Definition: NetworkDevice.cpp:554
Array< uint8 > messageBuffer
Definition: NetworkDevice.h:430
void localHostAddresses(Array< NetAddress > &array) const
Definition: NetworkDevice.cpp:515
bool receive()
Definition: NetworkDevice.h:527
Abstraction of network (socket) functionality.
Definition: NetworkDevice.h:608
NetAddress messageSender
Definition: NetworkDevice.h:420
NetAddress address() const
Definition: NetworkDevice.cpp:870
#define debugAssert(exp)
Definition: debugAssert.h:160
shared_ptr< class NetListener > NetListenerRef
Definition: NetworkDevice.h:540
uint32 subnet
Definition: NetworkDevice.h:624
Description of an ethernet or wireless ethernet adapter.
Definition: NetworkDevice.h:612
virtual uint32 waitingMessageType()=0
static std::string formatMAC(const uint8 mac[6])
Definition: NetworkDevice.cpp:240
uint32_t uint32
Definition: Define.h:150
uint8 mac[6]
Definition: NetworkDevice.h:630
PacketSizeException(const std::string &m, int s, int b)
Definition: NetworkDevice.h:477
void _cleanup()
Definition: NetworkDevice.cpp:475
void * receiveBuffer
Definition: NetworkDevice.h:188
enum G3D::ReliableConduit::State state
std::string __cdecl format(const char *fmt...) G3D_CHECK_PRINTF_ARGS
int maxMessageSize() const
Definition: NetworkDevice.h:490
int size() const
Definition: Array.h:430
BinaryOutput binaryOutput
Definition: NetworkDevice.h:73
uint32 messageType
Definition: NetworkDevice.h:180
Definition: TextOutput.h:60
uint32 messageType
Definition: NetworkDevice.h:425
Definition: NetworkDevice.h:173
bool ok() const
Definition: NetworkDevice.cpp:1243
const Array< uint32 > & broadcastAddressArray() const
Definition: NetworkDevice.h:692
NetworkDevice()
Definition: NetworkDevice.cpp:130
void receive()
Definition: NetworkDevice.h:337
uint8_t uint8
Definition: g3dmath.h:164
void serializeMessage(uint32 type, const T &m, BinaryOutput &b) const
Definition: NetworkDevice.h:442
virtual uint32 waitingMessageType()
Definition: NetworkDevice.cpp:826
virtual bool messageWaiting()
Definition: NetworkDevice.cpp:579
Definition: BinaryOutput.h:52
Definition: NetworkDevice.h:547
NetListener(uint16 port)
Definition: NetworkDevice.cpp:1151
virtual ~Conduit()
Definition: NetworkDevice.cpp:549
Definition: NetworkDevice.h:407
uint64 bReceived
Definition: NetworkDevice.h:65
bool receive(NetAddress &sender, T &message)
Definition: NetworkDevice.h:515
shared_ptr< class ReliableConduit > ReliableConduitRef
Definition: NetworkDevice.h:136
void writeUInt32(uint32 u)
Definition: BinaryOutput.cpp:395
uint32_t uint32
Definition: g3dmath.h:168
G3D::int16 x
Definition: Vector2int16.h:37
Definition: NetworkDevice.h:168
ReliableConduitRef waitForConnection()
Definition: NetworkDevice.cpp:1210
int MTU
Definition: NetworkDevice.h:438
~NetworkDevice()
Definition: NetworkDevice.cpp:135
size_t receiveBufferUsedSize
Definition: NetworkDevice.h:196
static void cleanup()
Definition: NetworkDevice.cpp:121
static void serializeMessage(uint32 t, const T &m, BinaryOutput &b)
Definition: NetworkDevice.h:204
uint64 mReceived
Definition: NetworkDevice.h:63
static std::string formatIP(uint32 ip)
Definition: NetworkDevice.cpp:234
static NetworkDevice * instance()
Definition: NetworkDevice.cpp:109
uint64 messagesReceived() const
Definition: NetworkDevice.cpp:569
ReliableConduit(const NetAddress &addr)
Definition: NetworkDevice.cpp:617
int maxMessageSize
Definition: NetworkDevice.h:475
EthernetAdapter()
Definition: NetworkDevice.cpp:177
bool alreadyReadMessage
Definition: NetworkDevice.h:415
void sendBuffer(const NetAddress &a, BinaryOutput &b)
Definition: NetworkDevice.cpp:1072
bool receive(T &message)
Definition: NetworkDevice.h:313
int64 length() const
Definition: BinaryOutput.h:196