RavEngine
Loading...
Searching...
No Matches
physx::PxSocket Class Reference

#include <PxSocket.h>

Inheritance diagram for physx::PxSocket:
[legend]
Collaboration diagram for physx::PxSocket:
[legend]

Public Member Functions

 PxSocket (bool inEnableBuffering=true, bool blocking=true)
 
bool connect (const char *host, uint16_t port, uint32_t timeout=1000)
 
bool listen (uint16_t port)
 
bool accept (bool block)
 
void disconnect ()
 
bool isConnected () const
 
const char * getHost () const
 
uint16_t getPort () const
 
bool flush ()
 
uint32_t write (const uint8_t *data, uint32_t length)
 
uint32_t read (uint8_t *data, uint32_t length)
 
void setBlocking (bool blocking)
 
bool isBlocking () const
 
- Public Member Functions inherited from physx::PxUserAllocated
PX_INLINE void * operator new (size_t, void *address)
 
PX_INLINE void operator delete (void *, void *)
 
template<typename Alloc >
PX_INLINE void * operator new (size_t size, Alloc alloc, const char *fileName, int line)
 
template<typename Alloc >
PX_INLINE void * operator new (size_t size, size_t, Alloc alloc, const char *fileName, int line)
 
template<typename Alloc >
PX_INLINE void * operator new[] (size_t size, Alloc alloc, const char *fileName, int line)
 
template<typename Alloc >
PX_INLINE void * operator new[] (size_t size, size_t, Alloc alloc, const char *fileName, int line)
 
template<typename Alloc >
PX_INLINE void operator delete (void *ptr, Alloc alloc, const char *fileName, int line)
 
template<typename Alloc >
PX_INLINE void operator delete[] (void *ptr, Alloc alloc, const char *fileName, int line)
 
PX_INLINE void operator delete (void *ptr)
 
PX_INLINE void operator delete[] (void *ptr)
 

Static Public Attributes

static const uint32_t DEFAULT_BUFFER_SIZE = 32768
 

Detailed Description

Socket abstraction API

Member Function Documentation

◆ accept()

bool physx::PxSocket::accept ( bool  block)

Accept a connection on a socket that is in listening mode

Note
This method only supports a single connection client. Additional clients that connect to the listening port will overwrite the existing socket handle.
Parameters
blockwhether or not the call should block
Returns
whether a connection was established

◆ connect()

bool physx::PxSocket::connect ( const char *  host,
uint16_t  port,
uint32_t  timeout = 1000 
)

Opens a network socket for input and/or output

Parameters
hostName of the host to connect to. This can be an IP, URL, etc
portThe port to connect to on the remote host
timeoutTimeout in ms until the connection must be established.
Returns
True if the connection was successful, false otherwise

◆ disconnect()

void physx::PxSocket::disconnect ( )

Disconnects an open socket

◆ flush()

bool physx::PxSocket::flush ( )

Flushes the output stream. Until the stream is flushed, there is no guarantee that the written data has actually reached the destination storage. Flush forces all buffered data to be sent to the output.

Note
flush always blocks. If the socket is in non-blocking mode, this will result the thread spinning.
Returns
True if the flush was successful, false otherwise

◆ getHost()

const char * physx::PxSocket::getHost ( ) const

Returns the name of the connected host. This is the same as the string that was supplied to the connect call.

Returns
The name of the connected host

◆ getPort()

uint16_t physx::PxSocket::getPort ( ) const

Returns the port of the connected host. This is the same as the port that was supplied to the connect call.

Returns
The port of the connected host

◆ isBlocking()

bool physx::PxSocket::isBlocking ( ) const

Returns whether read/write/flush calls to the socket are blocking.

Returns
True if the socket is blocking.

◆ isConnected()

bool physx::PxSocket::isConnected ( ) const

Returns whether the socket is currently open (connected) or not.

Returns
True if the socket is connected, false otherwise

◆ listen()

bool physx::PxSocket::listen ( uint16_t  port)

Opens a network socket for input and/or output as a server. Put the connection in listening mode

Parameters
portThe port on which the socket listens

◆ read()

uint32_t physx::PxSocket::read ( uint8_t *  data,
uint32_t  length 
)

Reads data from the output stream.

Parameters
dataPointer to a buffer where the read data will be stored.
lengthAmount of data to read, in bytes.
Returns
Number of bytes actually read. This could be lower than length if the stream end is encountered or the socket is non-blocking.

◆ setBlocking()

void physx::PxSocket::setBlocking ( bool  blocking)

Sets blocking mode of the socket. Socket must be connected, otherwise calling this method won't take any effect.

◆ write()

uint32_t physx::PxSocket::write ( const uint8_t *  data,
uint32_t  length 
)

Writes data to the output stream.

Parameters
dataPointer to a block of data to write to the stream
lengthAmount of data to write, in bytes
Returns
Number of bytes actually written. This could be lower than length if the socket is non-blocking.

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