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


Base class for NetConnection that provides only the sending functionality. More...

Inherits G3D::ReferenceCountedObject.

Inherited by G3D::NetConnection.

Public Member Functions

virtual NetAddress address () const
 Address of the other side of the connection. More...
 
void send (NetMessageType type, const void *bytes, size_t size, NetChannel channel=0, const shared_ptr< MemoryManager > &memoryManager=shared_ptr< MemoryManager >())
 Schedule for sending across this connection. More...
 
void send (NetMessageType type, const void *bytes, size_t size, BinaryOutput &header, NetChannel channel=0, const shared_ptr< MemoryManager > &memoryManager=shared_ptr< MemoryManager >())
 
void send (NetMessageType type, BinaryOutput &bo, NetChannel channel=0)
 Send the contents of this BinaryOutput. More...
 
void send (NetMessageType type, BinaryOutput &bo, BinaryOutput &header, NetChannel channel=0)
 Includes a header. More...
 
void shutdownSenderThreads ()
 
void submitToSendQueues (const _internal::NetMessage &message)
 

Protected Member Functions

 NetSendConnection (_ENetPeer *p, _ENetHost *h)
 
virtual void beforeSend ()
 
virtual void enetsend (NetChannel channel, _ENetPacket *packet)
 Acutally send the packet with enet. More...
 
void processFreeQueue ()
 

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

_ENetHost * m_enetHost
 
_ENetPeer * m_enetPeer
 nullptr for a NetSendConnection, non-null for a NetConnection More...
 
ThreadsafeQueue< _internal::NetworkCallbackInfom_freeQueue
 Callbacks to be run the next time any method is invoked. More...
 

Friends

void addCallback (const shared_ptr< NetSendConnection > &conn, _ENetPacket *packet, const shared_ptr< MemoryManager > &manager, const void *data)
 
void freePacketDataCallback (_ENetPacket *packet)
 
class NetServer
 

Detailed Description


Base class for NetConnection that provides only the sending functionality.

This is only used for NetServer::broadcast(), where there is no analogous "broadcast receive". For most applications, use NetConnection.

Constructor & Destructor Documentation

◆ NetSendConnection()

G3D::NetSendConnection::NetSendConnection ( _ENetPeer *  p,
_ENetHost *  h 
)
inlineprotected

Member Function Documentation

◆ address()

virtual NetAddress G3D::NetSendConnection::address ( ) const
virtual

Address of the other side of the connection.

◆ beforeSend()

virtual void G3D::NetSendConnection::beforeSend ( )
inlineprotectedvirtual

Reimplemented in G3D::NetConnection.

◆ 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>.

◆ enetsend()

virtual void G3D::NetSendConnection::enetsend ( NetChannel  channel,
_ENetPacket *  packet 
)
protectedvirtual

Acutally send the packet with enet.

This allows code reuse with NetConnection, which has a different sending mechanism.

◆ processFreeQueue()

void G3D::NetSendConnection::processFreeQueue ( )
protected

◆ send() [1/4]

void G3D::NetSendConnection::send ( NetMessageType  type,
const void *  bytes,
size_t  size,
NetChannel  channel = 0,
const shared_ptr< MemoryManager > &  memoryManager = shared_ptr< MemoryManager >() 
)

Schedule for sending across this connection.

Parameters
bytesBy default, the memory will be copied, so it is safe to deallocate or change on return
memoryManagerIf notNull, then this memory manager will be used to free bytes once the data has been transmitted. Do not modify or free bytes after invoking send(). If not provided, the contents of bytes are immediately copied and the caller is able to mutate or free it immediately on return. The memoryManagers are queued and can be invoked at the time of any future method invocation. This guarantees that they are run on a thread that the application controls (and not the internal network threads).

Pass a memoryManager when sending large packets to avoid the overhead of copying. Do not pass a memoryManager for small packets, since there is some overhead in initializing the deallocation record.

Parameters
channelSee NetChannel

Messages may be divided over individual packets if large, but are always observed outside of the API as atomic.

Not guaranteed to be delivered if a disconnection occurs on either side before the message is completely transferred, or if this is currently disconnected.

See also
networkSendBacklog

◆ send() [2/4]

void G3D::NetSendConnection::send ( NetMessageType  type,
const void *  bytes,
size_t  size,
BinaryOutput header,
NetChannel  channel = 0,
const shared_ptr< MemoryManager > &  memoryManager = shared_ptr< MemoryManager >() 
)

◆ send() [3/4]

void G3D::NetSendConnection::send ( NetMessageType  type,
BinaryOutput bo,
NetChannel  channel = 0 
)

Send the contents of this BinaryOutput.

This is easier and safer to use than the other version of send(), so it is preferred for general use. However, this method copies the memory, so it is slightly slower than the other overloaded version of send() for large buffers.

See also
networkSendBacklog

◆ send() [4/4]

void G3D::NetSendConnection::send ( NetMessageType  type,
BinaryOutput bo,
BinaryOutput header,
NetChannel  channel = 0 
)

Includes a header.

The header should be fairly small to avoid increasing latency during the extra copies required.

◆ shutdownSenderThreads()

void G3D::NetSendConnection::shutdownSenderThreads ( )

◆ submitToSendQueues()

void G3D::NetSendConnection::submitToSendQueues ( const _internal::NetMessage &  message)

Friends And Related Function Documentation

◆ addCallback

void addCallback ( const shared_ptr< NetSendConnection > &  conn,
_ENetPacket *  packet,
const shared_ptr< MemoryManager > &  manager,
const void *  data 
)
friend

◆ freePacketDataCallback

void freePacketDataCallback ( _ENetPacket *  packet)
friend

◆ NetServer

friend class NetServer
friend

Member Data Documentation

◆ m_enetHost

_ENetHost* G3D::NetSendConnection::m_enetHost
protected

◆ m_enetPeer

_ENetPeer* G3D::NetSendConnection::m_enetPeer
protected

nullptr for a NetSendConnection, non-null for a NetConnection

◆ m_freeQueue

ThreadsafeQueue<_internal::NetworkCallbackInfo> G3D::NetSendConnection::m_freeQueue
protected

Callbacks to be run the next time any method is invoked.


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