D++ (DPP)
C++ Discord API Bot Library
dpp::socket_engine_base Struct Referenceabstract

This is the base class for socket engines. The actual implementation is OS specific and the correct implementation is detected by CMake. It is then compiled specifically into DPP so only one implementation can exist in the implementation. All implementations should behave identically to the user, abstracting out implementation-specific behaviours (e.g. difference between edge and level triggered event mechanisms etc). More...

#include <socketengine.h>

+ Collaboration diagram for dpp::socket_engine_base:

Public Member Functions

 socket_engine_base (class cluster *creator)
 Default constructor. More...
 
 socket_engine_base (const socket_engine_base &)=delete
 Non-copyable. More...
 
 socket_engine_base (socket_engine_base &&)=delete
 Non-copyable. More...
 
socket_engine_baseoperator= (const socket_engine_base &)=delete
 Non-movable. More...
 
socket_engine_baseoperator= (socket_engine_base &&)=delete
 Non-movable. More...
 
virtual ~socket_engine_base ()=default
 Default destructor. More...
 
virtual void process_events ()=0
 Should be called repeatedly in a loop. Will run for a maximum of 1 second. More...
 
virtual bool register_socket (const socket_events &e)
 Register a new socket with the socket engine. More...
 
virtual bool update_socket (const socket_events &e)
 Update an existing socket in the socket engine. More...
 
bool delete_socket (dpp::socket fd)
 Delete a socket from the socket engine. More...
 
void prune ()
 Iterate through the list of sockets and remove any with WANT_DELETION set. This will also call implementation-specific remove_socket() on each entry to be removed. More...
 
void inplace_modify_fd (dpp::socket fd, uint8_t extra_flags)
 Merge new flags in with the given file descriptor. More...
 
const socket_statsget_stats () const
 Get statistics for socket engine. More...
 

Public Attributes

class clusterowner {nullptr}
 Owning cluster. More...
 

Protected Member Functions

socket_eventsget_fd (dpp::socket fd)
 Find a file descriptors socket events. More...
 
virtual bool remove_socket (dpp::socket fd)
 Called by the prune() function to remove sockets when safe to do so. This is normally at the end or before an iteration of the event loop. More...
 

Protected Attributes

std::shared_mutex fds_mutex
 Mutex for fds. More...
 
socket_container fds
 File descriptors, and their states. More...
 
socket_stats stats {}
 Socket engine statistics. More...
 

Detailed Description

This is the base class for socket engines. The actual implementation is OS specific and the correct implementation is detected by CMake. It is then compiled specifically into DPP so only one implementation can exist in the implementation. All implementations should behave identically to the user, abstracting out implementation-specific behaviours (e.g. difference between edge and level triggered event mechanisms etc).

Constructor & Destructor Documentation

◆ socket_engine_base() [1/3]

dpp::socket_engine_base::socket_engine_base ( class cluster creator)

Default constructor.

Parameters
creatorOwning cluster

◆ socket_engine_base() [2/3]

dpp::socket_engine_base::socket_engine_base ( const socket_engine_base )
delete

Non-copyable.

◆ socket_engine_base() [3/3]

dpp::socket_engine_base::socket_engine_base ( socket_engine_base &&  )
delete

Non-copyable.

◆ ~socket_engine_base()

virtual dpp::socket_engine_base::~socket_engine_base ( )
virtualdefault

Default destructor.

Member Function Documentation

◆ delete_socket()

bool dpp::socket_engine_base::delete_socket ( dpp::socket  fd)

Delete a socket from the socket engine.

Note
This will not remove the socket immediately. It will set the WANT_DELETION flag causing it to be removed as soon as is safe to do so (once all events associated with it are completed).
Parameters
eFile descriptor
Returns
true if socket was queued for deletion

◆ get_fd()

socket_events * dpp::socket_engine_base::get_fd ( dpp::socket  fd)
protected

Find a file descriptors socket events.

Parameters
fdfile descriptor
Returns
file descriptor or nullptr if doesn't exist

◆ get_stats()

const socket_stats & dpp::socket_engine_base::get_stats ( ) const

Get statistics for socket engine.

Returns
socket stats

◆ inplace_modify_fd()

void dpp::socket_engine_base::inplace_modify_fd ( dpp::socket  fd,
uint8_t  extra_flags 
)

Merge new flags in with the given file descriptor.

Parameters
fdfile descriptor
extra_flagsextra flags to add

◆ operator=() [1/2]

socket_engine_base & dpp::socket_engine_base::operator= ( const socket_engine_base )
delete

Non-movable.

◆ operator=() [2/2]

socket_engine_base & dpp::socket_engine_base::operator= ( socket_engine_base &&  )
delete

Non-movable.

◆ process_events()

virtual void dpp::socket_engine_base::process_events ( )
pure virtual

Should be called repeatedly in a loop. Will run for a maximum of 1 second.

◆ prune()

void dpp::socket_engine_base::prune ( )

Iterate through the list of sockets and remove any with WANT_DELETION set. This will also call implementation-specific remove_socket() on each entry to be removed.

◆ register_socket()

virtual bool dpp::socket_engine_base::register_socket ( const socket_events e)
virtual

Register a new socket with the socket engine.

Parameters
eSocket events
Returns
true if socket was added

◆ remove_socket()

virtual bool dpp::socket_engine_base::remove_socket ( dpp::socket  fd)
protectedvirtual

Called by the prune() function to remove sockets when safe to do so. This is normally at the end or before an iteration of the event loop.

Parameters
fdFile descriptor to remove

◆ update_socket()

virtual bool dpp::socket_engine_base::update_socket ( const socket_events e)
virtual

Update an existing socket in the socket engine.

Parameters
eSocket events
Returns
true if socket was updated

Member Data Documentation

◆ fds

socket_container dpp::socket_engine_base::fds
protected

File descriptors, and their states.

◆ fds_mutex

std::shared_mutex dpp::socket_engine_base::fds_mutex
protected

Mutex for fds.

◆ owner

class cluster* dpp::socket_engine_base::owner {nullptr}

Owning cluster.

◆ stats

socket_stats dpp::socket_engine_base::stats {}
protected

Socket engine statistics.

D++ Library version 10.0.35D++ Library version 10.0.34D++ Library version 10.0.33D++ Library version 10.0.32D++ Library version 10.0.31D++ Library version 10.0.30D++ Library version 10.0.29D++ Library version 10.0.28D++ Library version 10.0.27D++ Library version 10.0.26D++ Library version 10.0.25D++ Library version 10.0.24D++ Library version 10.0.23D++ Library version 10.0.22D++ Library version 10.0.21D++ Library version 10.0.20D++ Library version 10.0.19D++ Library version 10.0.18D++ Library version 10.0.17D++ Library version 10.0.16D++ Library version 10.0.15D++ Library version 10.0.14D++ Library version 10.0.13D++ Library version 10.0.12D++ Library version 10.0.11D++ Library version 10.0.10D++ Library version 10.0.9D++ Library version 10.0.8D++ Library version 10.0.7D++ Library version 10.0.6D++ Library version 10.0.5D++ Library version 10.0.4D++ Library version 10.0.3D++ Library version 10.0.2D++ Library version 10.0.1D++ Library version 10.0.0D++ Library version 9.0.19D++ Library version 9.0.18D++ Library version 9.0.17D++ Library version 9.0.16D++ Library version 9.0.15D++ Library version 9.0.14D++ Library version 9.0.13D++ Library version 9.0.12D++ Library version 9.0.11D++ Library version 9.0.10D++ Library version 9.0.9D++ Library version 9.0.8D++ Library version 9.0.7D++ Library version 9.0.6D++ Library version 9.0.5D++ Library version 9.0.4D++ Library version 9.0.3D++ Library version 9.0.2D++ Library version 9.0.1D++ Library version 9.0.0D++ Library version 1.0.2D++ Library version 1.0.1D++ Library version 1.0.0