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.
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
GridMate::SocketDriverCommon Class Referenceabstract

#include <SocketDriver.h>

Inherits GridMate::Driver.

Inherited by GridMate::SocketDriver.

Classes

class  PlatformSocketDriver
 

Public Types

using SocketType = Platform::SocketType_Platform
 
- Public Types inherited from GridMate::Driver
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

 SocketDriverCommon (bool isFullPackets=false, bool isCrossPlatform=false, bool isHighPerformance=false)
 
unsigned int GetMaxNumConnections () const override
 Return maximum number of active connections at the same time. More...
 
unsigned int GetMaxSendSize () const override
 Return maximum data size we can send/receive at once in bytes, supported by the platform.
 
unsigned int GetPacketOverheadSize () const override
 Return packet overhead size in bytes.
 
ResultCode Initialize (int familyType=BSD_AF_INET, const char *address=nullptr, unsigned int port=0, bool isBroadcast=false, unsigned int receiveBufferSize=0, unsigned int sendBufferSize=0) override
 
unsigned int GetPort () const override
 Returns communication port (must be called after Initialize, otherwise it will return 0)
 
ResultCode Send (const AZStd::intrusive_ptr< DriverAddress > &to, const char *data, unsigned int dataSize) override
 Send data to a user defined address.
 
unsigned int Receive (char *data, unsigned int maxDataSize, AZStd::intrusive_ptr< DriverAddress > &from, ResultCode *resultCode=0) override
 
bool WaitForData (AZStd::chrono::microseconds timeOut=AZStd::chrono::microseconds(0)) override
 
void StopWaitForData () override
 
bool WasStopeedWaitingForData () override
 Return true if WaitForData was interrupted before the timeOut expired, otherwise false.
 
AZStd::intrusive_ptr< DriverAddressCreateDriverAddress (const AZStd::string &address) override=0
 
virtual AZStd::intrusive_ptr< DriverAddressCreateDriverAddress (const sockaddr *sockAddr)=0
 Additional CreateDriverAddress function should be implemented.
 
- Public Member Functions inherited from GridMate::Driver
virtual void Update ()
 
virtual void ProcessIncoming ()
 
virtual void ProcessOutgoing ()
 
virtual bool CanSend () const
 

Protected Member Functions

virtual SocketType CreateSocket (int af, int type, int protocol)
 returns result of socket(af,type,protocol)
 
virtual int BindSocket (const sockaddr *sockAddr, size_t sockAddrLen)
 returns the result of bind(sockAddr)
 
virtual ResultCode SetSocketOptions (bool isBroadcast, unsigned int receiveBufferSize, unsigned int sendBufferSize)
 set's default socket options
 
- Protected Member Functions inherited from GridMate::Driver
virtual void DestroyDriverAddress (DriverAddress *address)=0
 

Protected Attributes

SocketType m_socket
 
unsigned short m_port
 
bool m_isStoppedWaitForData
 True if last WaitForData was interrupted otherwise false.
 
bool m_isFullPackets
 True if we use max packet size vs internet safe packet size (64KB vs 1500 usually)
 
bool m_isCrossPlatform
 True if we support cross platform communication. Then we make sure we use common features.
 
bool m_isIpv6
 True if we use version 6 of the internet protocol, otherwise false.
 
bool m_isDatagram
 True if the socket was created with SOCK_DGRAM.
 
AZStd::unique_ptr< PlatformSocketDriverm_platformDriver
 Platform specific implementation of socket calls.
 
bool m_isHighPerformance
 True if using platform-specific high-performance implementation.
 
- Protected Attributes inherited from GridMate::Driver
bool m_canSend
 Can the driver accept more data.
 
AZStd::string IPPortToAddress (const char *ip, unsigned int port) const override
 
bool AddressToIPPort (const AZStd::string &address, AZStd::string &ip, unsigned int &port) const override
 
static AZStd::string IPPortToAddressString (const char *ip, unsigned int port)
 Create address for the socket driver from IP and port.
 
static bool AddressStringToIPPort (const AZStd::string &address, AZStd::string &ip, unsigned int &port)
 Decompose an address to IP and port.
 
static BSDSocketFamilyType AddressFamilyType (const AZStd::string &ip)
 Return the family type of the address (AF_INET,AF_INET6 AF_UNSPEC)
 
static BSDSocketFamilyType AddressFamilyType (const char *ip)
 

Detailed Description

Base common class for all SocketBased drivers, you can't NOT create an instance of the SocketDriverCommon use CreateSocketDriver function for a BSD socket driver.

Member Function Documentation

◆ CreateDriverAddress()

AZStd::intrusive_ptr<DriverAddress> GridMate::SocketDriverCommon::CreateDriverAddress ( const AZStd::string &  address)
overridepure 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.

Implements GridMate::Driver.

Implemented in GridMate::SocketDriver.

◆ GetMaxNumConnections()

unsigned int GridMate::SocketDriverCommon::GetMaxNumConnections ( ) const
inlineoverridevirtual

Return maximum number of active connections at the same time.

Platform specific functionality.

Implements GridMate::Driver.

Reimplemented in GridMate::StreamSocketDriver.

◆ Initialize()

ResultCode GridMate::SocketDriverCommon::Initialize ( int  familyType = BSD_AF_INET,
const char *  address = nullptr,
unsigned int  port = 0,
bool  isBroadcast = false,
unsigned int  receiveBufferSize = 0,
unsigned int  sendBufferSize = 0 
)
overridevirtual

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

Parameters
ftfamily type, for the BSD socket it can be AFT_IPV4 or AFT_IPV6.
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.
isBroadcastis valid for Ipv4 only (otherwise ignored). Sets the socket to support broadcasts.
receiveBufferSizesocket receive buffer size in bytes, use 0 for default values.
sendBufferSizesocket send buffer size, use 0 for default values.

Implements GridMate::Driver.

◆ IPPortToAddress()

AZStd::string GridMate::SocketDriverCommon::IPPortToAddress ( const char *  ip,
unsigned int  port 
) const
inlineoverridevirtual

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.

Implements GridMate::Driver.

◆ Receive()

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

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.

Implements GridMate::Driver.

◆ StopWaitForData()

void GridMate::SocketDriverCommon::StopWaitForData ( )
overridevirtual

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.

Implements GridMate::Driver.

◆ WaitForData()

bool GridMate::SocketDriverCommon::WaitForData ( AZStd::chrono::microseconds  timeOut = AZStd::chrono::microseconds(0))
overridevirtual

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.

Implements GridMate::Driver.


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