Encapsulates a socket handle that is capable of recieving epoll events. More...
#include <tcpsocket.h>
Public Member Functions | |
Socket (EPoll &epoll, const int domain=AF_INET, const int socket=0, const bool blocking=false, const int events=(EPOLLIN|EPOLLRDHUP)) | |
Construct a blocking or non-blocking socket handle that responds to certain epoll events. More... | |
~Socket () | |
Closes and destroys the socket. More... | |
int | socket () const |
Return the linux socket handle. | |
int | domain () const |
Return the socket domain (AF_INET or AF_INET6) | |
virtual void | disconnect () |
Shuts down the socket gracefully. | |
Protected Member Functions | |
bool | setEvents (int events) |
Changes which epoll events the socket listens for. More... | |
virtual void | handleEvents (uint32_t events)=0 |
Called when the socket recieves an epoll event. More... | |
virtual void | disconnected () |
Called when a connection is disconnected due to a network error. More... | |
EPoll & | epoll () |
Returns a reference to the epoll instance used by this socket. | |
Protected Attributes | |
recursive_mutex | mtx |
The mutex used to provide exclusive access to the socket. | |
SocketState | state_ |
Descendant classes can manipulate the socket state directly. | |
Friends | |
class | EPoll |
Encapsulates a socket handle that is capable of recieving epoll events.
Definition at line 96 of file tcpsocket.h.
tcp::Socket::Socket | ( | EPoll & | epoll, |
const int | domain = AF_INET , |
||
const int | socket = 0 , |
||
const bool | blocking = false , |
||
const int | events = (EPOLLIN | EPOLLRDHUP) |
||
) |
Construct a blocking or non-blocking socket handle that responds to certain epoll events.
domain | Either AF_INET or AF_INET6 |
socket | The socket handle to encapsulate. If 0 is provided, a socket handle will be automatically created. |
blocking | If true, a blocking socket will be created. If false, a non-blocking socket will be created. |
events | A bit flag of the epoll events to register interest include |
Definition at line 97 of file tcpsocket.cpp.
tcp::Socket::~Socket | ( | ) |
Closes and destroys the socket.
Definition at line 135 of file tcpsocket.cpp.
|
protectedvirtual |
Called when a connection is disconnected due to a network error.
Sets the socket state to DISCONNECTED and frees its resources. Override disconnected to perform additional cleanup of a dropped socket connection.
Reimplemented in tcp::DataSocket, and tcp::Session.
Definition at line 173 of file tcpsocket.cpp.
|
protectedpure virtual |
Called when the socket recieves an epoll event.
Descendant classes override this abstract method to respond to epoll events
events | A bitmask of event flags. See the epoll documentation |
Implemented in tcp::DataSocket, tcp::Client, and tcp::Server.
|
protected |
Changes which epoll events the socket listens for.
Descendant classes may want to override this
events | A bitmask of event flags. See the epoll documentation |
Definition at line 148 of file tcpsocket.cpp.