Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
sese::iocp::v1::IOCPServer Class Reference

IOCP server based on sese-event. More...

#include <IOCPServer_V1.h>

Public Types

using DeleteContextCallback = std::function<void(Context *data)>
 

Public Member Functions

virtual ~IOCPServer ()=default
 
 IOCPServer ()
 
bool init ()
 
void shutdown ()
 
void postConnect (const net::IPAddress::Ptr &to, const security::SSLContext::Ptr &cli_ctx, void *data=nullptr)
 
virtual void onAcceptCompleted (Context *ctx)
 
virtual void onPreRead (Context *ctx)
 
virtual void onReadCompleted (Context *ctx)
 
virtual void onWriteCompleted (Context *ctx)
 
virtual void onTimeout (Context *ctx)
 
virtual void onPreConnect (Context *ctx)
 
virtual void onConnected (Context *ctx)
 
virtual void onAlpnGet (Context *ctx, const uint8_t *in, uint32_t in_length)
 
int onAlpnSelect (const uint8_t **out, uint8_t *out_length, const uint8_t *in, uint32_t in_length)
 
void setAddress (const net::IPAddress::Ptr &addr)
 
void setThreads (size_t threads)
 
void setServCtx (const security::SSLContext::Ptr &ctx)
 
void setServProtos (const std::string &protos)
 
void setClientProtos (const std::string &protos)
 
void setDeleteContextCallback (const DeleteContextCallback &callback)
 
const security::SSLContext::PtrgetServCtx () const
 
const DeleteContextCallbackgetDeleteContextCallback () const
 
bool isActiveReleaseMode () const
 
void setAcceptTimeout (uint32_t seconds)
 
void setDispatchTimeout (uint32_t seconds)
 

Static Public Member Functions

static void postRead (Context *ctx)
 
static void postWrite (Context *ctx)
 
static void postClose (Context *ctx)
 
static void setTimeout (Context *ctx, int64_t seconds)
 
static void cancelTimeout (Context *ctx)
 
static void onDeleteContext (Context *)
 

Protected Member Functions

void preConnectCallback (int fd, sese::event::EventLoop *event_loop, Context *ctx)
 
void setActiveReleaseMode (bool enable)
 

Protected Attributes

DeleteContextCallback deleteContextCallback = onDeleteContext
 
security::SSLContext::Ptr sslCtx {}
 
std::string servProtos {}
 
std::string clientProtos {}
 
service::UserBalanceLoader balanceLoader
 

Private Attributes

bool activeReleaseMode = true
 

Detailed Description

IOCP server based on sese-event.

Member Typedef Documentation

◆ DeleteContextCallback

using sese::iocp::v1::IOCPServer::DeleteContextCallback = std::function<void(Context *data)>

Constructor & Destructor Documentation

◆ ~IOCPServer()

virtual sese::iocp::v1::IOCPServer::~IOCPServer ( )
virtualdefault

◆ IOCPServer()

Member Function Documentation

◆ cancelTimeout()

void IOCPServer::cancelTimeout ( Context * ctx)
static

◆ getDeleteContextCallback()

const DeleteContextCallback & sese::iocp::v1::IOCPServer::getDeleteContextCallback ( ) const
inlinenodiscard

Get the current operation context destruction callback function for the service

Returns
Callback function

References deleteContextCallback.

Referenced by sese::iocp::v1::IOCPService::releaseContext().

◆ getServCtx()

const security::SSLContext::Ptr & sese::iocp::v1::IOCPServer::getServCtx ( ) const
inlinenodiscard

Get the current SSL context for server listening

Returns
SSL context

References sslCtx.

Referenced by sese::iocp::v1::IOCPService::IOCPService(), and sese::iocp::v1::IOCPService::onAccept().

◆ init()

bool IOCPServer::init ( )

Initialize and start the server

Returns
Initialization result

References balanceLoader, sese::service::UserBalanceLoader::init(), and sese::service::UserBalanceLoader::start().

◆ isActiveReleaseMode()

bool sese::iocp::v1::IOCPServer::isActiveReleaseMode ( ) const
inlinenodiscard

Get the status of the active release mode

Returns
Status of the active release mode

References activeReleaseMode.

◆ onAcceptCompleted()

virtual void sese::iocp::v1::IOCPServer::onAcceptCompleted ( Context * ctx)
inlinevirtual

Handshake completed callback function

Parameters
ctxOperation context

Referenced by sese::iocp::v1::IOCPService::onAcceptCompleted().

◆ onAlpnGet()

virtual void sese::iocp::v1::IOCPServer::onAlpnGet ( Context * ctx,
const uint8_t * in,
uint32_t in_length )
inlinevirtual

ALPN protocol negotiation completion callback function

Parameters
ctxContext
inNegotiation content
in_lengthLength of negotiation content

Referenced by sese::iocp::v1::IOCPService::onAlpnGet().

◆ onAlpnSelect()

int IOCPServer::onAlpnSelect ( const uint8_t ** out,
uint8_t * out_length,
const uint8_t * in,
uint32_t in_length )

ALPN negotiation callback function

Parameters
outExpected content from the other side
out_lengthLength of expected content from the other side
inResponse content
in_lengthLength of response content
Returns
ALPN status code

References in(), and servProtos.

Referenced by sese::iocp::v1::IOCPService::alpnCallbackFunction().

◆ onConnected()

virtual void sese::iocp::v1::IOCPServer::onConnected ( Context * ctx)
inlinevirtual

Connection event callback function

Parameters
ctxOperation context

Referenced by sese::iocp::v1::IOCPService::onConnected().

◆ onDeleteContext()

static void sese::iocp::v1::IOCPServer::onDeleteContext ( Context * )
inlinestatic

Default context release callback function

◆ onPreConnect()

virtual void sese::iocp::v1::IOCPServer::onPreConnect ( Context * ctx)
inlinevirtual

Connection pre-event callback function

Parameters
ctxOperation context

Referenced by preConnectCallback().

◆ onPreRead()

virtual void sese::iocp::v1::IOCPServer::onPreRead ( Context * ctx)
inlinevirtual

Callback function triggered by a read event

Parameters
ctxOperation context

Referenced by sese::iocp::v1::IOCPService::onPreRead().

◆ onReadCompleted()

virtual void sese::iocp::v1::IOCPServer::onReadCompleted ( Context * ctx)
inlinevirtual

Callback function for completion of a read event

Parameters
ctxOperation context

Referenced by sese::iocp::v1::IOCPService::onReadCompleted().

◆ onTimeout()

virtual void sese::iocp::v1::IOCPServer::onTimeout ( Context * ctx)
inlinevirtual

Timeout event callback function

Parameters
ctxOperation context

Referenced by sese::iocp::v1::IOCPService::onTimeout().

◆ onWriteCompleted()

virtual void sese::iocp::v1::IOCPServer::onWriteCompleted ( Context * ctx)
inlinevirtual

Write event completed callback function

Parameters
ctxOperation context

Referenced by sese::iocp::v1::IOCPService::onWriteCompleted().

◆ postClose()

void IOCPServer::postClose ( Context * ctx)
static

Post a close event

Parameters
ctxOperation context

References sese::iocp::v1::Context::client, and sese::iocp::v1::IOCPService::postClose().

◆ postConnect()

void IOCPServer::postConnect ( const net::IPAddress::Ptr & to,
const security::SSLContext::Ptr & cli_ctx,
void * data = nullptr )

◆ postRead()

void IOCPServer::postRead ( Context * ctx)
static

Post a read event

Parameters
ctxOperation context

References sese::iocp::v1::Context::client, and sese::iocp::v1::IOCPService::postRead().

◆ postWrite()

void IOCPServer::postWrite ( Context * ctx)
static

Post a write event

Parameters
ctxOperation context

References sese::iocp::v1::Context::client, and sese::iocp::v1::IOCPService::postWrite().

Referenced by preConnectCallback().

◆ preConnectCallback()

void IOCPServer::preConnectCallback ( int fd,
sese::event::EventLoop * event_loop,
Context * ctx )
protected

◆ setAcceptTimeout()

void sese::iocp::v1::IOCPServer::setAcceptTimeout ( uint32_t seconds)
inline

Set the connection access timeout duration. This function is only for IOCP implementations based on sese-event

Parameters
secondsConnection access timeout duration

References balanceLoader, and sese::service::UserBalanceLoader::setAcceptTimeout().

◆ setActiveReleaseMode()

void sese::iocp::v1::IOCPServer::setActiveReleaseMode ( bool enable)
inlineprotected

Set active release mode

Parameters
enableEnable or disable

References activeReleaseMode.

◆ setAddress()

void sese::iocp::v1::IOCPServer::setAddress ( const net::IPAddress::Ptr & addr)
inline

Set the IP address to which the current service is bound. Setting this option will make the server automatically listen to the corresponding port of the address

Parameters
addrTarget IP

References balanceLoader, and sese::service::UserBalanceLoader::setAddress().

◆ setClientProtos()

void sese::iocp::v1::IOCPServer::setClientProtos ( const std::string & protos)
inline

Set the ALPN negotiation content for the client

Parameters
protosProtocol negotiation content

References clientProtos.

◆ setDeleteContextCallback()

void sese::iocp::v1::IOCPServer::setDeleteContextCallback ( const DeleteContextCallback & callback)
inline

Set the server operation context destruction callback function

Parameters
callbackCallback function

References callback(), and deleteContextCallback.

◆ setDispatchTimeout()

void sese::iocp::v1::IOCPServer::setDispatchTimeout ( uint32_t seconds)
inline

Set the connection dispatch timeout duration. This function is only for IOCP implementations based on sese-event

Parameters
secondsConnection dispatch timeout duration

References balanceLoader, and sese::service::UserBalanceLoader::setDispatchTimeout().

◆ setServCtx()

void sese::iocp::v1::IOCPServer::setServCtx ( const security::SSLContext::Ptr & ctx)
inline

Set the SSL context used for server listening

Parameters
ctxSSL context

References sslCtx.

◆ setServProtos()

void sese::iocp::v1::IOCPServer::setServProtos ( const std::string & protos)
inline

Set the ALPN negotiation content for the server

Parameters
protosProtocol negotiation content

References servProtos.

◆ setThreads()

void sese::iocp::v1::IOCPServer::setThreads ( size_t threads)
inline

Set the desired number of threads for the service

Parameters
threadsNumber of threads

References balanceLoader, and sese::service::UserBalanceLoader::setThreads().

◆ setTimeout()

void IOCPServer::setTimeout ( Context * ctx,
int64_t seconds )
static

◆ shutdown()

void IOCPServer::shutdown ( )

Terminate worker threads, release system resources, and shut down the server

References balanceLoader, and sese::service::UserBalanceLoader::stop().

Member Data Documentation

◆ activeReleaseMode

bool sese::iocp::v1::IOCPServer::activeReleaseMode = true
private

◆ balanceLoader

service::UserBalanceLoader sese::iocp::v1::IOCPServer::balanceLoader
protected

◆ clientProtos

std::string sese::iocp::v1::IOCPServer::clientProtos {}
protected

Referenced by postConnect(), and setClientProtos().

◆ deleteContextCallback

DeleteContextCallback sese::iocp::v1::IOCPServer::deleteContextCallback = onDeleteContext
protected

◆ servProtos

std::string sese::iocp::v1::IOCPServer::servProtos {}
protected

Referenced by onAlpnSelect(), and setServProtos().

◆ sslCtx

security::SSLContext::Ptr sese::iocp::v1::IOCPServer::sslCtx {}
protected

Referenced by getServCtx(), and setServCtx().


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