sptk2 logo
SPTK Home Page
Public Types | Public Member Functions | Protected Member Functions | Friends | List of all members
sptk::ServerConnection Class Reference

#include <ServerConnection.h>

Inheritance diagram for sptk::ServerConnection:
sptk::Runable sptk::SSLServerConnection sptk::TCPServerConnection sptk::WSConnection sptk::WSSSLConnection

Public Types

enum class  Type { TCP , SSL }
 
using Function = std::function< void(const Runable &task, TCPSocket &socket, const String &address)>
 

Public Member Functions

 ServerConnection (TCPServer &server, SOCKET connectionSocket, Type type, const sockaddr_in *connectionAddress, const String &taskName, const ServerConnection::Function &connectionFunction={})
 
TCPSocketsocket () const
 
TCPServerserver () const
 
String address () const
 
size_t serial () const
 
- Public Member Functions inherited from sptk::Runable
 Runable (const String &name)
 
virtual ~Runable ()=default
 
void execute ()
 
virtual void terminate ()
 
bool terminated () const
 
String name () const
 

Protected Member Functions

void setSocket (const STCPSocket &socket)
 
void parseAddress (const sockaddr_in *connectionAddress)
 
void run () override
 
virtual void run ()=0
 

Friends

class TCPServer
 

Detailed Description

Abstract TCP or SSL server connection thread

Used a base class for CTCPServerConnection and COpenSSLServerConnection

Constructor & Destructor Documentation

◆ ServerConnection()

sptk::ServerConnection::ServerConnection ( TCPServer server,
SOCKET  connectionSocket,
Type  type,
const sockaddr_in *  connectionAddress,
const String taskName,
const ServerConnection::Function &  connectionFunction = {} 
)

Constructor

Parameters
serverServer that created this connection
connectionSocketAlready accepted by accept() function incoming connection socket
taskNameTask name
connectionFunctionConnection function processing this connection

Member Function Documentation

◆ address()

String sptk::ServerConnection::address ( ) const
inline

Get incoming connection address

Returns
incoming connection address

◆ run()

void sptk::ServerConnection::run ( )
inlineoverrideprotectedvirtual

Method that is executed by worker thread

Should be overwritten by derived class.

Implements sptk::Runable.

Reimplemented in sptk::WSConnection.

◆ serial()

size_t sptk::ServerConnection::serial ( ) const
inline

Get connection serial number

Returns
connection serial number

◆ server()

TCPServer & sptk::ServerConnection::server ( ) const

Parent TCP server reference

Returns

Referenced by sptk::SSLServerConnection::SSLServerConnection().

◆ setSocket()

void sptk::ServerConnection::setSocket ( const STCPSocket &  socket)
protected

Assign new socket

Parameters
socketSocket to assign

Referenced by sptk::SSLServerConnection::SSLServerConnection(), and sptk::TCPServerConnection::TCPServerConnection().

◆ socket()

TCPSocket & sptk::ServerConnection::socket ( ) const

Access to internal socket for derived classes

Returns
internal socket

Referenced by sptk::TCPServerConnection::TCPServerConnection(), and sptk::TCPServerConnection::terminate().


The documentation for this class was generated from the following file:

Fri Oct 14 2022 09:58:44: SPTK 5.4.1