Sese Framework
2.3.0
A cross-platform framework
|
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::Ptr & | getServCtx () const |
const DeleteContextCallback & | getDeleteContextCallback () 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 |
IOCP server based on sese-event.
using sese::iocp::v1::IOCPServer::DeleteContextCallback = std::function<void(Context *data)> |
|
virtualdefault |
IOCPServer::IOCPServer | ( | ) |
|
static |
Cancel the timeout event
ctx | Operation context |
References sese::service::v2::TimerableService::cancelTimeoutEvent(), sese::iocp::v1::Context::client, and sese::iocp::v1::Context::timeoutEvent.
|
inlinenodiscard |
Get the current operation context destruction callback function for the service
References deleteContextCallback.
Referenced by sese::iocp::v1::IOCPService::releaseContext().
|
inlinenodiscard |
Get the current SSL context for server listening
References sslCtx.
Referenced by sese::iocp::v1::IOCPService::IOCPService(), and sese::iocp::v1::IOCPService::onAccept().
bool IOCPServer::init | ( | ) |
Initialize and start the server
References balanceLoader, sese::service::UserBalanceLoader::init(), and sese::service::UserBalanceLoader::start().
|
inlinenodiscard |
Get the status of the active release mode
References activeReleaseMode.
|
inlinevirtual |
Handshake completed callback function
ctx | Operation context |
Referenced by sese::iocp::v1::IOCPService::onAcceptCompleted().
|
inlinevirtual |
ALPN protocol negotiation completion callback function
ctx | Context |
in | Negotiation content |
in_length | Length of negotiation content |
Referenced by sese::iocp::v1::IOCPService::onAlpnGet().
int IOCPServer::onAlpnSelect | ( | const uint8_t ** | out, |
uint8_t * | out_length, | ||
const uint8_t * | in, | ||
uint32_t | in_length ) |
ALPN negotiation callback function
out | Expected content from the other side |
out_length | Length of expected content from the other side |
in | Response content |
in_length | Length of response content |
References in(), and servProtos.
Referenced by sese::iocp::v1::IOCPService::alpnCallbackFunction().
|
inlinevirtual |
Connection event callback function
ctx | Operation context |
Referenced by sese::iocp::v1::IOCPService::onConnected().
|
inlinestatic |
Default context release callback function
|
inlinevirtual |
Connection pre-event callback function
ctx | Operation context |
Referenced by preConnectCallback().
|
inlinevirtual |
Callback function triggered by a read event
ctx | Operation context |
Referenced by sese::iocp::v1::IOCPService::onPreRead().
|
inlinevirtual |
Callback function for completion of a read event
ctx | Operation context |
Referenced by sese::iocp::v1::IOCPService::onReadCompleted().
|
inlinevirtual |
Timeout event callback function
ctx | Operation context |
Referenced by sese::iocp::v1::IOCPService::onTimeout().
|
inlinevirtual |
Write event completed callback function
ctx | Operation context |
Referenced by sese::iocp::v1::IOCPService::onWriteCompleted().
|
static |
Post a close event
ctx | Operation context |
References sese::iocp::v1::Context::client, and sese::iocp::v1::IOCPService::postClose().
void IOCPServer::postConnect | ( | const net::IPAddress::Ptr & | to, |
const security::SSLContext::Ptr & | cli_ctx, | ||
void * | data = nullptr ) |
Post a connection event
to | Connection address |
cli_ctx | SSL client context |
data | Additional data |
References balanceLoader, clientProtos, CTX, sese::service::UserBalanceLoader::dispatchSocket(), EINPROGRESS, sese::iocp::v1::Context::fd, sese::net::getNetworkError(), sese::net::Socket::setNonblocking(), and sese::net::Socket::socket().
|
static |
Post a read event
ctx | Operation context |
References sese::iocp::v1::Context::client, and sese::iocp::v1::IOCPService::postRead().
|
static |
Post a write event
ctx | Operation context |
References sese::iocp::v1::Context::client, and sese::iocp::v1::IOCPService::postWrite().
Referenced by preConnectCallback().
|
protected |
References sese::iocp::v1::Context::client, onPreConnect(), and postWrite().
Referenced by IOCPServer().
|
inline |
Set the connection access timeout duration. This function is only for IOCP implementations based on sese-event
seconds | Connection access timeout duration |
References balanceLoader, and sese::service::UserBalanceLoader::setAcceptTimeout().
|
inlineprotected |
|
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
addr | Target IP |
References balanceLoader, and sese::service::UserBalanceLoader::setAddress().
|
inline |
Set the ALPN negotiation content for the client
protos | Protocol negotiation content |
References clientProtos.
|
inline |
Set the server operation context destruction callback function
callback | Callback function |
References callback(), and deleteContextCallback.
|
inline |
Set the connection dispatch timeout duration. This function is only for IOCP implementations based on sese-event
seconds | Connection dispatch timeout duration |
References balanceLoader, and sese::service::UserBalanceLoader::setDispatchTimeout().
|
inline |
|
inline |
Set the ALPN negotiation content for the server
protos | Protocol negotiation content |
References servProtos.
|
inline |
Set the desired number of threads for the service
threads | Number of threads |
References balanceLoader, and sese::service::UserBalanceLoader::setThreads().
|
static |
Set a timeout event
ctx | Operation context |
seconds | Timeout duration |
References sese::service::v2::TimerableService::cancelTimeoutEvent(), sese::iocp::v1::Context::client, sese::service::v2::TimeoutEvent::data, sese::service::v2::TimerableService::setTimeoutEvent(), and sese::iocp::v1::Context::timeoutEvent.
void IOCPServer::shutdown | ( | ) |
Terminate worker threads, release system resources, and shut down the server
References balanceLoader, and sese::service::UserBalanceLoader::stop().
|
private |
Referenced by isActiveReleaseMode(), and setActiveReleaseMode().
|
protected |
Referenced by init(), IOCPServer(), postConnect(), setAcceptTimeout(), setAddress(), setDispatchTimeout(), setThreads(), and shutdown().
|
protected |
Referenced by postConnect(), and setClientProtos().
|
protected |
Referenced by getDeleteContextCallback(), and setDeleteContextCallback().
|
protected |
Referenced by onAlpnSelect(), and setServProtos().
|
protected |
Referenced by getServCtx(), and setServCtx().