Open 3D Engine GridMate API Reference  2205.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
GridMate::Driver Class Referenceabstract

#include <Driver.h>

Inherited by GridMate::SocketDriverCommon.

Public Types

enum  ErrorCodes {
  EC_OK = 0, EC_SOCKET_CREATE, EC_SOCKET_LISTEN, EC_SOCKET_CLOSE,
  EC_SOCKET_MAKE_NONBLOCK, EC_SOCKET_BIND, EC_SOCKET_SOCK_OPT, EC_SOCKET_CONNECT,
  EC_SOCKET_ACCEPT, EC_SECURE_CONFIG, EC_SECURE_CREATE, EC_SECURE_CERT,
  EC_SECURE_PKEY, EC_SECURE_CA_CERT, EC_SEND, EC_SEND_ADDRESS_NOT_BOUND,
  EC_RECEIVE, EC_PLATFORM = 1000, EC_BUFFER_TOOLARGE = 1001
}
 
enum  BSDSocketFamilyType { BSD_AF_INET = 0, BSD_AF_INET6, BSD_AF_UNSPEC }
 
typedef unsigned int ResultCode
 

Public Member Functions

virtual void Update ()
 
virtual void ProcessIncoming ()
 
virtual void ProcessOutgoing ()
 
virtual unsigned int GetMaxNumConnections () const =0
 Return maximum number of active connections at the same time. More...
 
virtual unsigned int GetMaxSendSize () const =0
 Return maximum data size we can send/receive at once in bytes, supported by the platform.
 
virtual unsigned int GetPacketOverheadSize () const
 Return packet overhead size in bytes.
 
virtual ResultCode Initialize (int familyType=0, const char *address=nullptr, unsigned int port=0, bool isBroadcast=false, unsigned int receiveBufferSize=0, unsigned int sendBufferSize=0)=0
 Transforms an error code to string. More...
 
virtual unsigned int GetPort () const =0
 Returns communication port (must be called after Initialize, otherwise it will return 0)
 
virtual ResultCode Send (const AZStd::intrusive_ptr< DriverAddress > &to, const char *data, unsigned int dataSize)=0
 Send data to a user defined address.
 
virtual unsigned int Receive (char *data, unsigned int maxDataSize, AZStd::intrusive_ptr< DriverAddress > &from, ResultCode *resultCode=0)=0
 
virtual bool WaitForData (AZStd::chrono::microseconds timeOut=AZStd::chrono::microseconds(0))=0
 
virtual void StopWaitForData ()=0
 
virtual bool WasStopeedWaitingForData ()=0
 Return true if WaitForData was interrupted before the timeOut expired, otherwise false.
 
virtual AZStd::intrusive_ptr< DriverAddressCreateDriverAddress (const AZStd::string &address)=0
 
virtual bool CanSend () const
 
virtual AZStd::string IPPortToAddress (const char *ip, unsigned int port) const =0
 
virtual bool AddressToIPPort (const AZStd::string &address, AZStd::string &ip, unsigned int &port) const =0
 

Protected Member Functions

virtual void DestroyDriverAddress (DriverAddress *address)=0
 

Protected Attributes

bool m_canSend
 Can the driver accept more data.
 

Friends

class DriverAddress
 

Detailed Description

Driver interface is the interface for the lowest level of the transport layer.

Note
All the code is executed in a thread context! Any interaction with the outside code should be made thread safe.

Member Enumeration Documentation

◆ BSDSocketFamilyType

Family types for BSD socket.

◆ ErrorCodes

Enumerator
EC_SEND_ADDRESS_NOT_BOUND 

We failed to send because the remote address was NOT bound.

EC_PLATFORM 

use codes above 1000 for platform specific error codes

Member Function Documentation

◆ CanSend()

virtual bool GridMate::Driver::CanSend ( ) const
inlinevirtual

Returns true if the driver can accept new data (ex, has buffer space).

◆ CreateDriverAddress()

virtual AZStd::intrusive_ptr<DriverAddress> GridMate::Driver::CreateDriverAddress ( const AZStd::string &  address)
pure virtual

Creates internal driver address to be used for send/receive calls.

Note
if the ip and the port are the same, the same pointer will be returned. You can use the returned pointer to compare for unique addresses.
Driver address allocates internal resources, use it only when you intend to communicate. Otherwise operate with the string address.

Implemented in GridMate::SocketDriverCommon, and GridMate::SocketDriver.

◆ GetMaxNumConnections()

virtual unsigned int GridMate::Driver::GetMaxNumConnections ( ) const
pure virtual

Return maximum number of active connections at the same time.

Platform specific functionality.

Implemented in GridMate::SocketDriverCommon, and GridMate::StreamSocketDriver.

◆ Initialize()

virtual ResultCode GridMate::Driver::Initialize ( int  familyType = 0,
const char *  address = nullptr,
unsigned int  port = 0,
bool  isBroadcast = false,
unsigned int  receiveBufferSize = 0,
unsigned int  sendBufferSize = 0 
)
pure virtual

Transforms an error code to string.

User should implement create and bind a UDP socket. This socket will be used for all communications.

Parameters
ftfamily type (this value depends on the platform), 0 will use the default family type (for BSD socket this is ipv4)
addresswhen 0 it we will assume "any address".
portWhen left 0, we use implicit bind (assigned by the system). Otherwise provide a valid port number.
receiveBufferSizesocket receive buffer size in bytes, use 0 for default values.
sendBufferSizesocket send buffer size, use 0 for default values.

Implemented in GridMate::SocketDriverCommon.

◆ IPPortToAddress()

virtual AZStd::string GridMate::Driver::IPPortToAddress ( const char *  ip,
unsigned int  port 
) const
pure virtual

Address conversion functionality. They MUST implemented thread safe. Generally this is not a problem since they just part local data. Create address from ip and port. If ip == NULL we will assign a broadcast address.

Implemented in GridMate::SocketDriverCommon.

◆ Receive()

virtual unsigned int GridMate::Driver::Receive ( char *  data,
unsigned int  maxDataSize,
AZStd::intrusive_ptr< DriverAddress > &  from,
ResultCode *  resultCode = 0 
)
pure virtual

Receives a datagram and stores the source address. maxDataSize must be >= than GetMaxSendSize(). Returns the num of of received bytes.

Note
If a datagram from a new connection is received, NewConnectionCB will be called. If it rejects the connection the returned from pointer will be NULL while the actual data will be returned.

Implemented in GridMate::SocketDriverCommon.

◆ StopWaitForData()

virtual void GridMate::Driver::StopWaitForData ( )
pure virtual

When you enter wait for data mode, for many reasons you might want to stop wait for data. If you implement this function you need to make sure it's a thread safe function.

Implemented in GridMate::SocketDriverCommon.

◆ WaitForData()

virtual bool GridMate::Driver::WaitForData ( AZStd::chrono::microseconds  timeOut = AZStd::chrono::microseconds(0))
pure virtual

Wait for data to be to the ready for receive. Time out is the maximum time to wait before this function returns. If left to default value it will be in blocking mode (wait until data is ready to be received).

Returns
true if there is data to be received (always true if timeOut == 0), otherwise false.

Implemented in GridMate::SocketDriverCommon.


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