Software and Services, Portable Libraries
2019.Mar.01
A library for managing digital certificates
|
An OS independent wrapper for polling I/O connections. More...
#include "<SaS/Common/Poll.hpp>"
Classes | |
struct | CallBacks |
Public Member Functions | |
Poll () | |
Poll - default Constructor. More... | |
virtual | ~Poll () |
Poll Destructor. More... | |
bool | AddFd (const int fd, const unsigned short events, const CallBacks *cb=nullptr) |
Add fd the the list of callback that the current callback function will handle when cb is nullptr. More... | |
void | CloseDown () |
Close down everything. More... | |
virtual InstanceCount_t | decInstance () const |
Decrement the instance. More... | |
void | Disable (const int fd, const unsigned short events) |
Disable All Transport & User callbacks for fd for events. More... | |
void | Enable (const int fd, const unsigned short events) |
Enable All T& User callbacks for fd for events. More... | |
File * | GetFile (const int fd) |
Get a File handle to the named file descriptor. More... | |
virtual InstanceCount_t | getInstance () const |
PollFunc_t | GetTransportAcceptCallback () const |
PollFunc_t | GetTransportCallback (const int fd, const unsigned short events) const |
Get any Transport callback function for fd using events. More... | |
CallBacks * | GetTransportCallbacks () const |
Get the Transport callbacks. More... | |
void * | GetTransportData () const |
PollFunc_t | GetTransportDefaultCallback (const unsigned short events) const |
Get the Transport default callback function for the named events. More... | |
PollFunc_t | GetUserAcceptCallback () const |
PollFunc_t | GetUserCallback (const int Fd, unsigned short Events) const |
Get any User callback function for fd using events. More... | |
CallBacks * | GetUserCallbacks () const |
Get the User callbacks. More... | |
void * | GetUserData () const |
PollFunc_t | GetUserDefaultCallback (const unsigned short events) const |
Get the User default callback function for the named events. More... | |
virtual InstanceCount_t | incInstance () const |
Increment the instance. More... | |
void | Lock () |
Lock this data so changes can be made. More... | |
void | operator delete (void *ToFree) |
const struct pollfd * | PollFd () const |
nfds_t | PollFdSize () const |
bool | RemoveFd (const int fd) |
Remove fd from the poll list. More... | |
void | SetTimeout (const int milliseconds) |
void | SetTransportAcceptCallback (const PollFunc_t ThePollFunc, const void *userData=nullptr) |
Set Transport accept call back. More... | |
void | SetTransportCallback (const int fd, const unsigned short events, const PollFunc_t ThePollFunc, const unsigned int bufSize) |
Set the a Transport callback. More... | |
void | SetTransportData (const void *Data) |
void | SetTransportDefaultCallback (const unsigned short events, const PollFunc_t ThePollFunc, const unsigned int bufSize) |
Set the default Transport callback. More... | |
void | SetTransportFillRdCallback (const int fd, const unsigned short events, const PollFunc_t ThePollFunc, const unsigned int bufsize) |
Set the Transport callback. More... | |
void | SetUserAcceptCallback (const PollFunc_t ThePollFunc, const void *userData=nullptr) |
Set User accept call back. More... | |
void | SetUserCallback (const int fd, const unsigned short events, const PollFunc_t ThePollFunc, const unsigned int bufSize) |
Set the a User callback. More... | |
void | SetUserData (const void *Data) |
void | SetUserData (int fd, const void *Data) |
void | SetUserDefaultCallback (const unsigned short events, const PollFunc_t ThePollFunc, const unsigned int bufSize=0) |
Set the default User callback. More... | |
void | SetUserFillRdCallback (const int fd, const unsigned short events, const PollFunc_t ThePollFunc, const unsigned int bufsize) |
USER (only used for callbacks, and sets Transport FD poll fd's). More... | |
void | TransportDisable (const int fd, const unsigned short events) |
Disable Transport callbacks for fd for events. More... | |
void | TransportEnable (const int fd, const unsigned short events) |
Enable Transport callbacks for fd for events. More... | |
void | Unlock () |
Unlock this data, changes are complete. More... | |
void | UserDisable (const int fd, const unsigned short events) |
Disable User callbacks for fd for events. More... | |
void | UserEnable (const int fd, const unsigned short events) |
Enable User callbacks for fd for events. More... | |
int | Wait (bool Once=false) |
Only call after struct pollfd (below) is setup. More... | |
int | WakeUpFd () const |
Get the wake up FD. More... | |
Static Public Member Functions | |
static void * | GetUserData (int fd) |
Public Attributes | |
EXPORT_COMMON typedef int(* | PollFunc_t )(const int fd, const unsigned short revents, CallBacks *callBacks, const unsigned int len, const char *data) |
For FILL-READ callback len and data are supplied, else they are zero and nullptr. More... | |
Friends | |
void * | _WakeUpThread (void *) |
void | AtExitCleanup () |
One time global initialization. More... | |
An OS independent wrapper for polling I/O connections.
Poll Events:
This implementation has two level, the OS level (T meaning transport) and the user level (User).
The User level is what the calling program uses to set or get data or callbacks.
The Transport level is the implementation specific level. Normally calling program never use the Transport level.
This implementation uses the POSIX poll() on systems that have it, or a private implementation that uses select() on systems that have that.
In addition to emulating the features of POSIX poll() this implementation will buffer in or out the data. The caller can for example pass a buffer down and have this implementation send it (or fill it) to/from the designated FD asynchronously of the calling program. Then callback the calling programs handler to notify it that the task is complete.
SoftwareAndServices::Library::Common::Poll::Poll | ( | ) |
Poll - default Constructor.
|
virtual |
Poll Destructor.
bool SoftwareAndServices::Library::Common::Poll::AddFd | ( | const int | fd, |
const unsigned short | events, | ||
const CallBacks * | cb = nullptr |
||
) |
Add fd the the list of callback that the current callback function will handle when cb is nullptr.
If cb is non-nullptr, then add cb as a handler for fd and events.
fd | The file descriptor to add. |
events | the events to handle. |
cb | An optional callback to add. |
void SoftwareAndServices::Library::Common::Poll::CloseDown | ( | ) |
Close down everything.
This closes down all the sockets, and closes all the file descriptors.
|
inlinevirtualinherited |
Decrement the instance.
Definition at line 129 of file instance.hpp.
void SoftwareAndServices::Library::Common::Poll::Disable | ( | const int | fd, |
const unsigned short | events | ||
) |
Disable All Transport & User callbacks for fd for events.
fd | The fd to disable. |
events | The events to disable for fd. |
void SoftwareAndServices::Library::Common::Poll::Enable | ( | const int | fd, |
const unsigned short | events | ||
) |
Enable All T& User callbacks for fd for events.
fd | The fd to disable. |
events | The events to disable for fd. |
File* SoftwareAndServices::Library::Common::Poll::GetFile | ( | const int | fd | ) |
|
inlinevirtualinherited |
Definition at line 118 of file instance.hpp.
PollFunc_t SoftwareAndServices::Library::Common::Poll::GetTransportAcceptCallback | ( | ) | const |
PollFunc_t SoftwareAndServices::Library::Common::Poll::GetTransportCallback | ( | const int | fd, |
const unsigned short | events | ||
) | const |
Get any Transport callback function for fd using events.
CallBacks* SoftwareAndServices::Library::Common::Poll::GetTransportCallbacks | ( | ) | const |
Get the Transport callbacks.
void* SoftwareAndServices::Library::Common::Poll::GetTransportData | ( | ) | const |
PollFunc_t SoftwareAndServices::Library::Common::Poll::GetTransportDefaultCallback | ( | const unsigned short | events | ) | const |
Get the Transport default callback function for the named events.
If events are handled by more than one callback, then this function will return nullptr. The best way to call it, where there is a possibility of multiple callbacks, each for a unique set of events, is to make this call with one poll event at a time.
events | Which events to look for. |
PollFunc_t SoftwareAndServices::Library::Common::Poll::GetUserAcceptCallback | ( | ) | const |
PollFunc_t SoftwareAndServices::Library::Common::Poll::GetUserCallback | ( | const int | Fd, |
unsigned short | Events | ||
) | const |
Get any User callback function for fd using events.
Fd | The file descriptor to search for. |
Events | The callback method that handles the bits in Events. |
CallBacks* SoftwareAndServices::Library::Common::Poll::GetUserCallbacks | ( | ) | const |
Get the User callbacks.
void* SoftwareAndServices::Library::Common::Poll::GetUserData | ( | ) | const |
|
static |
fd | The file descriptors data to fetch. |
PollFunc_t SoftwareAndServices::Library::Common::Poll::GetUserDefaultCallback | ( | const unsigned short | events | ) | const |
Get the User default callback function for the named events.
If events are handled by more than one callback, then this function will return nullptr. The best way to call it, where there is a possibility of multiple callbacks, each for a unique set of events, is to make this call with one poll event at a time.
events | Which events to look for. |
|
inlinevirtualinherited |
Increment the instance.
Definition at line 109 of file instance.hpp.
|
inline |
const struct pollfd* SoftwareAndServices::Library::Common::Poll::PollFd | ( | ) | const |
nfds_t SoftwareAndServices::Library::Common::Poll::PollFdSize | ( | ) | const |
bool SoftwareAndServices::Library::Common::Poll::RemoveFd | ( | const int | fd | ) |
Remove fd from the poll list.
fd | The file descriptor to stop polling. |
void SoftwareAndServices::Library::Common::Poll::SetTimeout | ( | const int | milliseconds | ) |
milliseconds | How long for poll() to wait. |
void SoftwareAndServices::Library::Common::Poll::SetTransportAcceptCallback | ( | const PollFunc_t | ThePollFunc, |
const void * | userData = nullptr |
||
) |
Set Transport accept call back.
ThePollFunc | The name of the callback that handles notifications that an ACCEPT is available. (server accepting new incoming connections) |
userData | Optional user data to be remembered and passed back to ThePollFunc when called. |
void SoftwareAndServices::Library::Common::Poll::SetTransportCallback | ( | const int | fd, |
const unsigned short | events, | ||
const PollFunc_t | ThePollFunc, | ||
const unsigned int | bufSize | ||
) |
Set the a Transport callback.
Set to nullptr and it will disable it. Setting it to non-nullptr will NOT enable it - use Enable(). Used to override the default Transport callback for the named events.
fd | Use the ThePollFunc for event with this fd |
events | The poll events that ThePollFunc will handle. |
ThePollFunc | A callback to be called for the named events. |
bufSize | ... |
void SoftwareAndServices::Library::Common::Poll::SetTransportData | ( | const void * | Data | ) |
Data | - Default server data (Transport) to use. |
void SoftwareAndServices::Library::Common::Poll::SetTransportDefaultCallback | ( | const unsigned short | events, |
const PollFunc_t | ThePollFunc, | ||
const unsigned int | bufSize | ||
) |
Set the default Transport callback.
Set to nullptr and it will disable it. Setting it to non-nullptr will NOT enable it - use Enable().
events | The poll events that ThePollFunc will handle. |
ThePollFunc | A callback to be called for the named events. |
bufSize | Size of the buffer desired. |
void SoftwareAndServices::Library::Common::Poll::SetTransportFillRdCallback | ( | const int | fd, |
const unsigned short | events, | ||
const PollFunc_t | ThePollFunc, | ||
const unsigned int | bufsize | ||
) |
Set the Transport callback.
Does an IOCTL to the FD, determines the number of bytes that can be read, and fills the buffer to the amount readable.
fd | The file descriptor to work with. |
bufsize | is the MAX memory buffer allowed. After that, it is MMAP'd and the calling function MUST un-map it when done. |
events | Which poll events to use. |
ThePollFunc | The callback function to call. |
void SoftwareAndServices::Library::Common::Poll::SetUserAcceptCallback | ( | const PollFunc_t | ThePollFunc, |
const void * | userData = nullptr |
||
) |
Set User accept call back.
ThePollFunc | The name of the callback that handles notifications that an ACCEPT is available. (server accepting new incoming connections) |
userData | Optional user data to be remembered and passed back to ThePollFunc when called. |
void SoftwareAndServices::Library::Common::Poll::SetUserCallback | ( | const int | fd, |
const unsigned short | events, | ||
const PollFunc_t | ThePollFunc, | ||
const unsigned int | bufSize | ||
) |
Set the a User callback.
Set to nullptr and it will disable it. Setting it to non-nullptr will NOT enable it - use Enable(). Used to override the default User callback for the named events.
fd | Use the ThePollFunc for event with this fd |
events | The poll events that ThePollFunc will handle. |
ThePollFunc | A callback to be called for the named events. |
bufSize | ... |
void SoftwareAndServices::Library::Common::Poll::SetUserData | ( | const void * | Data | ) |
Data | Default server data (User) to use. |
void SoftwareAndServices::Library::Common::Poll::SetUserData | ( | int | fd, |
const void * | Data | ||
) |
Data | Default server data (User) to use for the provided file descriptor. |
fd | The file descriptor that matches this Data. |
void SoftwareAndServices::Library::Common::Poll::SetUserDefaultCallback | ( | const unsigned short | events, |
const PollFunc_t | ThePollFunc, | ||
const unsigned int | bufSize = 0 |
||
) |
Set the default User callback.
Set to nullptr and it will disable it. Setting it to non-nullptr will NOT enable it - use Enable().
events | The poll events that ThePollFunc will handle. |
ThePollFunc | A callback to be called for the named events. |
bufSize | Size of the buffer desired. |
void SoftwareAndServices::Library::Common::Poll::SetUserFillRdCallback | ( | const int | fd, |
const unsigned short | events, | ||
const PollFunc_t | ThePollFunc, | ||
const unsigned int | bufsize | ||
) |
USER (only used for callbacks, and sets Transport FD poll fd's).
Set the User callback. Does an IOCTL to the FD, determines the number of bytes that can be read, and fills the buffer to the amount readable.
fd | The file descriptor to work with. |
events | Which poll events to use. |
ThePollFunc | The callback function to call. |
bufsize | is the MAX memory buffer allowed. After that, it is MMAP'd and the calling function MUST un-map it when done. |
void SoftwareAndServices::Library::Common::Poll::TransportDisable | ( | const int | fd, |
const unsigned short | events | ||
) |
Disable Transport callbacks for fd for events.
fd | The fd to disable. |
events | The events to disable for fd. |
void SoftwareAndServices::Library::Common::Poll::TransportEnable | ( | const int | fd, |
const unsigned short | events | ||
) |
Enable Transport callbacks for fd for events.
fd | The fd to disable. |
events | The events to disable for fd. |
|
inline |
void SoftwareAndServices::Library::Common::Poll::UserDisable | ( | const int | fd, |
const unsigned short | events | ||
) |
Disable User callbacks for fd for events.
fd | The fd to disable. |
events | The events to disable for fd. |
void SoftwareAndServices::Library::Common::Poll::UserEnable | ( | const int | fd, |
const unsigned short | events | ||
) |
Enable User callbacks for fd for events.
fd | The fd to disable. |
events | The events to disable for fd. |
int SoftwareAndServices::Library::Common::Poll::Wait | ( | bool | Once = false | ) |
Only call after struct pollfd (below) is setup.
Once | When true, only check once, then exit. |
int SoftwareAndServices::Library::Common::Poll::WakeUpFd | ( | ) | const |
Get the wake up FD.
Send a 'Q' to this fd to have poll(2) quit.
Send a 'W' to wake up poll(2) when you add/delete/update file descriptors to the poll(2) list.
Anything else sent will be treated as a 'W' - not recommended as applications may have other meaning for the value.
|
friend |
One time global initialization.
EXPORT_COMMON typedef int(* SoftwareAndServices::Library::Common::Poll::PollFunc_t) (const int fd, const unsigned short revents, CallBacks *callBacks, const unsigned int len, const char *data) |
For FILL-READ callback len and data are supplied, else they are zero and nullptr.
The is the function signature for a read callback. A read callback is called when the buffer is full of read information and is notifying the calling program that no more I/O will occur on this file handle until the buffer is emptied.
fd | The file descriptor to work with. |
revents | Which events logical OR of (POLL_ACCEPT_FD, POLLIN, POLLRDBAND, POLLPRI, POLLOUT, POLLWRBAND, POLLERR, POLLHUP, POLLNVAL) |
callBacks | List of callbacks |
len | How much to read (ignored with some callback options). |
data | Where to put the data (ignored with some callback options) |