Support Forum       G3D Web Page     
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
G3D::Conduit Class Referenceabstract

Inherits G3D::ReferenceCountedObject.

Public Member Functions

virtual ~Conduit ()
 
uint64 bytesReceived () const
 
uint64 bytesSent () const
 
uint64 messagesReceived () const
 
uint64 messagesSent () const
 
virtual bool messageWaiting ()
 
If true, receive will return true. More...
 
bool ok () const
 Returns true if the connection is ok. More...
 
virtual uint32 waitingMessageType ()=0
 
Returns the type of the waiting message (i.e. More...
 

Protected Member Functions

 Conduit ()
 

Static Protected Member Functions

template<class T , class ... ArgTypes>
static shared_ptr< T > createShared (ArgTypes &&... args)
 Like std::make_shared, but works for protected constructors. More...
 

Protected Attributes

BinaryOutput binaryOutput
 
Used for serialization. More...
 
uint64 bReceived
 
uint64 bSent
 
uint64 mReceived
 
uint64 mSent
 
SOCKET sock
 

Friends

class NetListener
 
class NetworkDevice
 

Detailed Description

Deprecated:

Constructor & Destructor Documentation

◆ Conduit()

G3D::Conduit::Conduit ( )
protected

◆ ~Conduit()

virtual G3D::Conduit::~Conduit ( )
virtual

Member Function Documentation

◆ bytesReceived()

uint64 G3D::Conduit::bytesReceived ( ) const

◆ bytesSent()

uint64 G3D::Conduit::bytesSent ( ) const

◆ createShared()

template<class T , class ... ArgTypes>
static shared_ptr<T> G3D::ReferenceCountedObject::createShared ( ArgTypes &&...  args)
inlinestaticprotectedinherited

Like std::make_shared, but works for protected constructors.

Call as createShared<myclass>.

◆ messagesReceived()

uint64 G3D::Conduit::messagesReceived ( ) const

◆ messagesSent()

uint64 G3D::Conduit::messagesSent ( ) const

◆ messageWaiting()

virtual bool G3D::Conduit::messageWaiting ( )
virtual


If true, receive will return true.

◆ ok()

bool G3D::Conduit::ok ( ) const

Returns true if the connection is ok.

◆ waitingMessageType()

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;
       ...
    }
 

Friends And Related Function Documentation

◆ NetListener

friend class NetListener
friend

◆ NetworkDevice

friend class NetworkDevice
friend

Member Data Documentation

◆ binaryOutput

BinaryOutput G3D::Conduit::binaryOutput
protected


Used for serialization.

One per socket to make this threadsafe.

◆ bReceived

uint64 G3D::Conduit::bReceived
protected

◆ bSent

uint64 G3D::Conduit::bSent
protected

◆ mReceived

uint64 G3D::Conduit::mReceived
protected

◆ mSent

uint64 G3D::Conduit::mSent
protected

◆ sock

SOCKET G3D::Conduit::sock
protected

documentation generated on Wed Nov 24 2021 08:01:54 using doxygen 1.8.15