| D++ (DPP) C++ Discord API Bot Library

Search
Loading...
Searching...
No Matches
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:
[legend]

## Public Member Functions

| socket_engine_base (class cluster *creator)
| Default constructor.
| socket_engine_base (const socket_engine_base &)=delete
| Non-copyable.
| socket_engine_base (socket_engine_base &&)=delete
| Non-copyable.
virtual | ~socket_engine_base ()
| Default destructor.
bool | delete_socket (dpp::socket fd)
| Delete a socket from the socket engine.
const socket_stats & | get_stats () const
| Get statistics for socket engine.
void | inplace_modify_fd (dpp::socket fd, uint8_t extra_flags)
| Merge new flags in with the given file descriptor.
socket_engine_base & | operator= (const socket_engine_base &)=delete
| Non-movable.
socket_engine_base & | operator= (socket_engine_base &&)=delete
| Non-movable.
virtual void | process_events ()=0
| Should be called repeatedly in a loop. Will run for a maximum of 1 second.
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.
virtual bool | register_socket (const socket_events &e)
| Register a new socket with the socket engine.
virtual bool | update_socket (const socket_events &e)
| Update an existing socket in the socket engine.

## Public Attributes

class cluster * | owner {nullptr}
| Owning cluster.

## Protected Member Functions

socket_events * | get_fd (dpp::socket fd)
| Find a file descriptors socket events.
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.

## Protected Attributes

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

## 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

  creator | Owning 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 | ( |  | ) |

virtual

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

  e | File 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

  fd | file 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

  fd | file descriptor
  extra_flags | extra 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

  e | Socket events

Returns
  true if socket was added

## ◆ remove_socket()

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

protected virtual

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

  fd | File 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

  e | Socket 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 9.0.13 D++ Library version 9.0.12 D++ Library version 9.0.11 D++ Library version 9.0.10 D++ Library version 9.0.9 D++ Library version 9.0.8 D++ Library version 9.0.7 D++ Library version 9.0.6 D++ Library version 9.0.5 D++ Library version 9.0.4 D++ Library version 9.0.3 D++ Library version 9.0.2 D++ Library version 9.0.1 D++ Library version 9.0.0 D++ Library version 1.0.2 D++ Library version 1.0.1 D++ Library version 1.0.0