|
fastdo
0.6.16
|
基础服务器类 更多...
#include <eiennet_socket.hpp>


Public 类型 | |
| using | ClientDataNotifyHandlerFunction = std::function< void(winux::SharedPointer< ClientCtx > clientCtxPtr, size_t readableSize) > |
客户数据通知,当Server::_isAutoReadData为false时有效 更多... | |
| using | ClientDataArrivedHandlerFunction = std::function< void(winux::SharedPointer< ClientCtx > clientCtxPtr, winux::Buffer &data) > |
客户数据到达,当Server::_isAutoReadData为true时有效 更多... | |
| using | CreateClientHandlerFunction = std::function< ClientCtx *(winux::uint64 clientId, winux::String const &clientEpStr, winux::SharedPointer< ip::tcp::Socket > clientSockPtr) > |
| 创建客户连接对象 更多... | |
Public 成员函数 | |
| Server () | |
构造函数0,不会启动服务,必须手动调用startup() 更多... | |
| Server (bool autoReadData, ip::EndPoint const &ep, int threadCount=4, int backlog=0, double serverWait=0.002, double verboseInterval=0.01, VerboseOutputType verbose=votConsole) | |
| 构造函数1,会启动服务 更多... | |
| virtual | ~Server () |
| bool | startup (bool autoReadData, ip::EndPoint const &ep, int threadCount=4, int backlog=0, double serverWait=0.002, double verboseInterval=0.01, VerboseOutputType verbose=votConsole) |
| 启动服务器 更多... | |
| virtual int | run (void *runParam) |
| 运行 更多... | |
| void | stop (bool b=true) |
| 是否停止服务运行 更多... | |
| size_t | getClientsCount () const |
| 获取客户连接数 更多... | |
| void | removeClient (winux::uint64 clientId) |
| 移除客户连接 更多... | |
| void | onClientDataNotifyHandler (ClientDataNotifyHandlerFunction handler) |
| void | onClientDataArrivedHandler (ClientDataArrivedHandlerFunction handler) |
| void | onCreateClientHandler (CreateClientHandlerFunction handler) |
Protected 成员函数 | |
| virtual bool | _canAddClient (ClientCtx *clientCtx) |
| 是否添加一个客户连接。返回true添加,返回false不添加 更多... | |
| bool | _addClient (ip::EndPoint const &clientEp, winux::SharedPointer< ip::tcp::Socket > clientSockPtr, winux::SharedPointer< ClientCtx > **ppClientCtxPtr) |
添加一个客户连接,会触发调用onCreateClient()创建客户场景对象,会调用_canAddClient()判断是否添加到服务器客户列表 更多... | |
| template<typename _Fx , typename... _ArgType> | |
| void | _postTask (winux::SharedPointer< ClientCtx > clientCtxPtr, _Fx fn, _ArgType &&...arg) |
| 往线程池投递任务 更多... | |
| virtual void | onClientDataNotify (winux::SharedPointer< ClientCtx > clientCtxPtr, size_t readableSize) |
| virtual void | onClientDataArrived (winux::SharedPointer< ClientCtx > clientCtxPtr, winux::Buffer &data) |
| virtual ClientCtx * | onCreateClient (winux::uint64 clientId, winux::String const &clientEpStr, winux::SharedPointer< ip::tcp::Socket > clientSockPtr) |
Protected 属性 | |
| ClientDataNotifyHandlerFunction | _ClientDataNotifyHandler |
| ClientDataArrivedHandlerFunction | _ClientDataArrivedHandler |
| CreateClientHandlerFunction | _CreateClientHandler |
| winux::ThreadPool | _pool |
| 线程池 更多... | |
| winux::RecursiveMutex | _mtxServer |
| 互斥量保护服务器共享数据 更多... | |
| ip::tcp::Socket | _servSockA |
| 服务器监听套接字A 更多... | |
| ip::tcp::Socket | _servSockB |
| 服务器监听套接字B 更多... | |
| std::map< winux::uint64, winux::SharedPointer< ClientCtx > > | _clients |
| 客户映射表 更多... | |
| winux::uint64 | _cumulativeClientId |
| 客户唯一标识 更多... | |
| bool | _stop |
| 是否停止 更多... | |
| bool | _servSockAIsListening |
| servSockA是否处于监听中 更多... | |
| bool | _servSockBIsListening |
| servSockB是否处于监听中 更多... | |
| bool | _isAutoReadData |
| 是否自动读取客户到达的数据。当为true时,客户数据达到时调用ClientDataArrived事件,否则调用ClientDataNotify事件 更多... | |
| double | _serverWait |
| 服务器IO等待时间间隔(秒) 更多... | |
| double | _verboseInterval |
| Verbose信息刷新间隔(秒) 更多... | |
| VerboseOutputType | _verbose |
| 提示信息输出方式 更多... | |
友元 | |
| class | ClientCtx |
基础服务器类
直接使用时,需要给定事件处理;继承时需要override相应的事件虚函数。
事件:
ClientDataNotify/ClientDataArrived - 客户数据通知/客户数据到达
CreateClient - 创建客户场景时
在文件 eiennet_socket.hpp 第 1083 行定义.
| using eiennet::Server::ClientDataNotifyHandlerFunction = std::function< void ( winux::SharedPointer<ClientCtx> clientCtxPtr, size_t readableSize ) > |
客户数据通知,当Server::_isAutoReadData为false时有效
| clientCtxPtr | 客户场景 |
| readableSize | 可无阻塞读取的数据量 |
在文件 eiennet_socket.hpp 第 1153 行定义.
| using eiennet::Server::ClientDataArrivedHandlerFunction = std::function< void ( winux::SharedPointer<ClientCtx> clientCtxPtr, winux::Buffer & data ) > |
客户数据到达,当Server::_isAutoReadData为true时有效
| clientCtxPtr | 客户场景 |
| data | 数据 |
在文件 eiennet_socket.hpp 第 1164 行定义.
| using eiennet::Server::CreateClientHandlerFunction = std::function< ClientCtx * ( winux::uint64 clientId, winux::String const & clientEpStr, winux::SharedPointer<ip::tcp::Socket> clientSockPtr ) > |
创建客户连接对象
| clientId | 客户唯一标识(64位数字) |
| clientEpStr | ip::EndPoint字符串 |
| clientSockPtr | 客户套接字 |
在文件 eiennet_socket.hpp 第 1176 行定义.
| eiennet::Server::Server | ( | ) |
构造函数0,不会启动服务,必须手动调用startup()
| eiennet::Server::Server | ( | bool | autoReadData, |
| ip::EndPoint const & | ep, | ||
| int | threadCount = 4, |
||
| int | backlog = 0, |
||
| double | serverWait = 0.002, |
||
| double | verboseInterval = 0.01, |
||
| VerboseOutputType | verbose = votConsole |
||
| ) |
构造函数1,会启动服务
| autoReadData | 是否自动读取数据。当为true时,客户数据达到时调用ClientDataArrived事件,否则调用ClientDataNotify事件 |
| ep | 服务监听的EndPoint |
| threadCount | 线程池线程数量 |
| backlog | listen(backlog) |
| serverWait | 服务器IO等待时间 |
| verboseInterval | verbose信息刷新间隔 |
| verbose | 输出提示信息方式 |
|
virtual |
| bool eiennet::Server::startup | ( | bool | autoReadData, |
| ip::EndPoint const & | ep, | ||
| int | threadCount = 4, |
||
| int | backlog = 0, |
||
| double | serverWait = 0.002, |
||
| double | verboseInterval = 0.01, |
||
| VerboseOutputType | verbose = votConsole |
||
| ) |
启动服务器
| autoReadData | 是否自动读取数据。当为true时,客户数据达到时调用ClientDataArrived事件,否则调用ClientDataNotify事件 |
| ep | 服务监听的EndPoint |
| threadCount | 线程池线程数量 |
| backlog | listen(backlog) |
| serverWait | 服务器IO等待时间 |
| verboseInterval | verbose信息刷新间隔 |
| verbose | 输出提示信息方式 |
|
virtual |
运行
被 eienwebx::HttpApp , 以及 http::HttpServer 重载.
| void eiennet::Server::stop | ( | bool | b = true | ) |
是否停止服务运行
| size_t eiennet::Server::getClientsCount | ( | ) | const |
获取客户连接数
| void eiennet::Server::removeClient | ( | winux::uint64 | clientId | ) |
移除客户连接
|
protectedvirtual |
是否添加一个客户连接。返回true添加,返回false不添加
|
protected |
添加一个客户连接,会触发调用onCreateClient()创建客户场景对象,会调用_canAddClient()判断是否添加到服务器客户列表
|
inlineprotected |
往线程池投递任务
在文件 eiennet_socket.hpp 第 1132 行定义.
|
inline |
在文件 eiennet_socket.hpp 第 1153 行定义.
|
inlineprotectedvirtual |
在文件 eiennet_socket.hpp 第 1153 行定义.
|
inline |
在文件 eiennet_socket.hpp 第 1164 行定义.
|
inlineprotectedvirtual |
被 http::HttpServer 重载.
在文件 eiennet_socket.hpp 第 1164 行定义.
|
inline |
在文件 eiennet_socket.hpp 第 1176 行定义.
|
protectedvirtual |
被 eienwebx::HttpApp , 以及 http::HttpServer 重载.
|
friend |
在文件 eiennet_socket.hpp 第 1195 行定义.
|
protected |
在文件 eiennet_socket.hpp 第 1153 行定义.
|
protected |
在文件 eiennet_socket.hpp 第 1164 行定义.
|
protected |
在文件 eiennet_socket.hpp 第 1176 行定义.
|
protected |
线程池
在文件 eiennet_socket.hpp 第 1179 行定义.
|
protected |
互斥量保护服务器共享数据
在文件 eiennet_socket.hpp 第 1180 行定义.
|
protected |
服务器监听套接字A
在文件 eiennet_socket.hpp 第 1181 行定义.
|
protected |
服务器监听套接字B
在文件 eiennet_socket.hpp 第 1182 行定义.
|
protected |
客户映射表
在文件 eiennet_socket.hpp 第 1183 行定义.
|
protected |
客户唯一标识
在文件 eiennet_socket.hpp 第 1185 行定义.
|
protected |
是否停止
在文件 eiennet_socket.hpp 第 1186 行定义.
|
protected |
servSockA是否处于监听中
在文件 eiennet_socket.hpp 第 1187 行定义.
|
protected |
servSockB是否处于监听中
在文件 eiennet_socket.hpp 第 1188 行定义.
|
protected |
是否自动读取客户到达的数据。当为true时,客户数据达到时调用ClientDataArrived事件,否则调用ClientDataNotify事件
在文件 eiennet_socket.hpp 第 1189 行定义.
|
protected |
服务器IO等待时间间隔(秒)
在文件 eiennet_socket.hpp 第 1191 行定义.
|
protected |
Verbose信息刷新间隔(秒)
在文件 eiennet_socket.hpp 第 1192 行定义.
|
protected |
提示信息输出方式
在文件 eiennet_socket.hpp 第 1193 行定义.