Represents a TCP connection accepted by the Server. More...
#include <tcpserver.h>
Public Member Functions | |
Server & | server () const |
Returns a reference to the Server that owns this Session. | |
in_port_t | peer_port () const |
Returns the peer port number used to connect to this Session. | |
in_addr_t | peer_address () const |
Returns the peer address used to connect to this Session. | |
bool | connected () const |
Returns true if the session is connected to a peer. | |
void | disconnect () override |
Shutdown the socket and close the session. More... | |
![]() | |
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 | |
Session (EPoll &epoll, Server &server, const int socket, const struct sockaddr_in peer_addr) | |
Creates a new session. More... | |
virtual | ~Session () |
The destructor is protected and is called by the disconnect() or disconnected() methods. | |
virtual void | accepted () |
Called by the Server::acceptConnection after a connection has been accepted. More... | |
void | disconnected () override |
Called when a tcp connection is dropped. More... | |
![]() | |
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. | |
Friends | |
class | SSL |
class | Server |
Additional Inherited Members | |
![]() | |
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. | |
Represents a TCP connection accepted by the Server.
A Session descendant class is instantiated by the server using the Session::createSession() method. It is destroyed by calling disconnect() or disconnected()
Definition at line 117 of file tcpserver.h.
|
inlineprotected |
Creates a new session.
The constructor is protected and is called by the Server::createSession() method
Definition at line 145 of file tcpserver.h.
|
protectedvirtual |
Called by the Server::acceptConnection after a connection has been accepted.
Server calls this method to signal the start of the session Override accepted() to perform initial actions when a session starts.
Override accepted to perform operations when a session is first established. In the base class, accepted() prints a message to clog.
Definition at line 248 of file tcpserver.cpp.
|
overridevirtual |
Shutdown the socket and close the session.
Starts a graceful shutdown of the session Override disconnect() to send any last messages required before the session is terminated.
Internally calls disconnect()
Override disconnect() to perform additional cleanup operations before a session is intentionally closed.
Be sure to call flush() to ensure the data is actually written to the write buffer.
Reimplemented from tcp::Socket.
Definition at line 267 of file tcpserver.cpp.
|
overrideprotectedvirtual |
Called when a tcp connection is dropped.
Called in response to a disconnected TCP Connection Override disconnected() to perform cleanup operations when a connection is unexpectedly lost.
Shuts down the network socket, removes itself from Server.sessions[], then destroys itself.
An application can override disconnected() to perform additional cleanup operations before the underlying TCP connection gets torn down.
Reimplemented from tcp::Socket.
Definition at line 279 of file tcpserver.cpp.