TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::Conduit Class Referenceabstract

#include <NetworkDevice.h>

Public Member Functions

virtual ~Conduit ()
 
uint64 bytesSent () const
 
uint64 messagesSent () const
 
uint64 bytesReceived () const
 
uint64 messagesReceived () const
 
virtual bool messageWaiting ()
 
virtual uint32 waitingMessageType ()=0
 
bool ok () const
 
- Public Member Functions inherited from G3D::ReferenceCountedObject
virtual ~ReferenceCountedObject ()
 

Protected Member Functions

 Conduit ()
 

Protected Attributes

uint64 mSent
 
uint64 mReceived
 
uint64 bSent
 
uint64 bReceived
 
SOCKET sock
 
BinaryOutput binaryOutput
 

Friends

class NetworkDevice
 
class NetListener
 

Detailed Description

Constructor & Destructor Documentation

G3D::Conduit::Conduit ( )
protected
540  : binaryOutput("<memory>", G3D_LITTLE_ENDIAN) {
541  sock = 0;
542  mSent = 0;
543  mReceived = 0;
544  bSent = 0;
545  bReceived = 0;
546 }
uint64 bSent
Definition: NetworkDevice.h:64
uint64 mSent
Definition: NetworkDevice.h:62
SOCKET sock
Definition: NetworkDevice.h:67
BinaryOutput binaryOutput
Definition: NetworkDevice.h:73
Definition: System.h:50
uint64 bReceived
Definition: NetworkDevice.h:65
uint64 mReceived
Definition: NetworkDevice.h:63
G3D::Conduit::~Conduit ( )
virtual
549  {
551 }
void closesocket(SOCKET &sock) const
Definition: NetworkDevice.cpp:501
SOCKET sock
Definition: NetworkDevice.h:67
static NetworkDevice * instance()
Definition: NetworkDevice.cpp:109

+ Here is the call graph for this function:

Member Function Documentation

uint64 G3D::Conduit::bytesReceived ( ) const
559  {
560  return bReceived;
561 }
uint64 bReceived
Definition: NetworkDevice.h:65
uint64 G3D::Conduit::bytesSent ( ) const
554  {
555  return bSent;
556 }
uint64 bSent
Definition: NetworkDevice.h:64
uint64 G3D::Conduit::messagesReceived ( ) const
569  {
570  return mReceived;
571 }
uint64 mReceived
Definition: NetworkDevice.h:63
uint64 G3D::Conduit::messagesSent ( ) const
564  {
565  return mSent;
566 }
uint64 mSent
Definition: NetworkDevice.h:62
bool G3D::Conduit::messageWaiting ( )
virtual

If true, receive will return true.

Reimplemented in G3D::LightweightConduit, and G3D::ReliableConduit.

579  {
580  return readWaiting(sock);
581 }
static bool readWaiting(const SOCKET &sock)
Definition: NetworkDevice.cpp:72
SOCKET sock
Definition: NetworkDevice.h:67

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool G3D::Conduit::ok ( ) const

Returns true if the connection is ok.

574  {
575  return (sock != 0) && (sock != SOCKET_ERROR);
576 }
SOCKET sock
Definition: NetworkDevice.h:67

+ Here is the caller graph for this function:

virtual uint32 G3D::Conduit::waitingMessageType ( )
pure virtual

Returns the type of the waiting message (i.e. the type supplied with send). The return value is zero when there is no message waiting.

One way to use this is to have a Table mapping message types to pre-allocated subclasses so receiving looks like:

    // My base class for messages.
    class Message {
        virtual void serialize(BinaryOutput&) const;
        virtual void deserialize(BinaryInput&);
        virtual void process() = 0;
    };
    Message* m = table[conduit->waitingMessageType()];
    conduit->receive(m);
    m->process();

Another is to simply switch on the message type:

    switch (conduit->waitingMessageType()) {
    case 0:
       // No message
       break;
    case ENTITY_SPAWN_MSG:
       {
          EntitySpawnMsg m;
          condiut->receive(m);
          spawnEntity(m.id, m.position, m.modelID);
       }
       break;
       ...
    }
 

Implemented in G3D::LightweightConduit, and G3D::ReliableConduit.

Friends And Related Function Documentation

friend class NetListener
friend
friend class NetworkDevice
friend

Member Data Documentation

BinaryOutput G3D::Conduit::binaryOutput
protected

Used for serialization. One per socket to make this threadsafe.

uint64 G3D::Conduit::bReceived
protected
uint64 G3D::Conduit::bSent
protected
uint64 G3D::Conduit::mReceived
protected
uint64 G3D::Conduit::mSent
protected
SOCKET G3D::Conduit::sock
protected

The documentation for this class was generated from the following files: