Represents a buffered socket that can send and receive data using optional SSL encryption. More...
#include <tcpsocket.h>
Public Member Functions | |
DataSocket (EPoll &epoll, const int domain=AF_INET, const int socket=0, const bool blocking=false, const int events=(EPOLLIN|EPOLLRDHUP)) | |
size_t | available () |
Returns the number of bytes available in the inputBuffer. | |
size_t | read (void *buffer, size_t size) |
Reads up to size bytes from inputBuffer into buffer. More... | |
size_t | write (const void *buffer, size_t size) |
Writes the contents of buffer to the outputBuffer. More... | |
![]() | |
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) | |
Protected Member Functions | |
void | readToInputBuffer () |
Reads all available data from the socket into inputBuffer. | |
void | sendOutputBuffer () |
Writes all available data from the outputBuffer to the socket. More... | |
void | canSend (bool value) |
Sets the epoll event flags. More... | |
void | handleEvents (uint32_t events) override |
Called by the EPoll class when the listening socket recieves an epoll event. More... | |
void | disconnect () override |
Shuts down any SSL connection gracefully. More... | |
void | disconnected () override |
Called when a connection is disconnected. More... | |
virtual void | dataAvailable ()=0 |
Called whenever new data is appended to the inputBuffer. More... | |
virtual SSL * | createSSL (SSLContext *context) |
Factory method for returning an SSL object. More... | |
![]() | |
bool | setEvents (int events) |
Changes which epoll events the socket listens for. More... | |
EPoll & | epoll () |
Returns a reference to the epoll instance used by this socket. | |
Protected Attributes | |
SSL * | ssl_ {nullptr} |
Exposes the underlying SSL record used for openSSL calls to descendant classes. | |
![]() | |
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 | SSL |
Represents a buffered socket that can send and receive data using optional SSL encryption.
This class provides properties and methods common to both the Client and Session classes
Definition at line 159 of file tcpsocket.h.
|
protected |
Sets the epoll event flags.
The flags will include EPOLLOUT if value==true
Definition at line 247 of file tcpsocket.cpp.
|
protectedvirtual |
Factory method for returning an SSL object.
Override to replace the SSL class used.
Definition at line 348 of file tcpsocket.cpp.
|
protectedpure virtual |
Called whenever new data is appended to the inputBuffer.
Clients should override the dataAvailable method to do something in response to received data
|
overrideprotectedvirtual |
Shuts down any SSL connection gracefully.
Socket::disconnect() is called to shutdown the underlying socket
Reimplemented from tcp::Socket.
Definition at line 189 of file tcpsocket.cpp.
|
overrideprotectedvirtual |
Called when a connection is disconnected.
Frees the SSL object that is associated with the connection
Reimplemented from tcp::Socket.
Definition at line 202 of file tcpsocket.cpp.
|
overrideprotectedvirtual |
Called by the EPoll class when the listening socket recieves an epoll event.
Calls either disconnected(), readToInputBuffer() + dataAvailable() or sendOutputBuffer() depending on the events that have been set.
Implements tcp::Socket.
Definition at line 255 of file tcpsocket.cpp.
size_t tcp::DataSocket::read | ( | void * | buffer, |
size_t | size | ||
) |
Reads up to size bytes from inputBuffer into buffer.
Definition at line 313 of file tcpsocket.cpp.
|
protected |
Writes all available data from the outputBuffer to the socket.
Any data that could not be written will be retained in the outputBuffer and sent with the next call to sendOutputBuffer()
Definition at line 226 of file tcpsocket.cpp.
size_t tcp::DataSocket::write | ( | const void * | buffer, |
size_t | size | ||
) |
Writes the contents of buffer to the outputBuffer.
The content of the outputBuffer will be sent automatically at the next EPoll event
Definition at line 330 of file tcpsocket.cpp.