fastdo  0.6.16
ws::WsHttpServer类 参考

WebSocket服务器 更多...

#include <ws_websocket.hpp>

类 ws::WsHttpServer 继承关系图:
ws::WsHttpServer 的协作图:

Public 类型

using OpenHandlerFunction = std::function< void(winux::SharedPointer< WsHttpRequestCtx > requestCtxPtr) >
 
using MessageHandlerFunction = std::function< void(winux::SharedPointer< WsHttpRequestCtx > requestCtxPtr, winux::AnsiString const &data, int messageType) >
 
using CloseHandlerFunction = std::function< void(winux::SharedPointer< WsHttpRequestCtx > requestCtxPtr, winux::uint16 errCode, winux::AnsiString const &errStr) >
 
using ErrorHandlerFunction = std::function< void(winux::SharedPointer< WsHttpRequestCtx > requestCtxPtr, WebSocketErrorCode ec) >
 
- Public 类型 继承自 http::HttpServer
using CrossRouteHandlerFunction = CrossRouteHandlerFunctionT< HttpRequestCtx, Response >
 过径路由处理函数类型 更多...
 
using RouteHandlerFunction = RouteHandlerFunctionT< HttpRequestCtx, Response >
 普通路由处理函数类型 更多...
 
using CreateResponseHandlerFunction = std::function< Response *(Request &req, winux::SimplePointer< RspOutputMgr > outputMgr) >
 创建响应处理函数类型 更多...
 
- Public 类型 继承自 eiennet::Server
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 类型 继承自 http::UrlRouter
using CrossRouteHandlerFunction = CrossRouteHandlerFunctionT< http::Request, http::Response >
 
using RouteHandlerFunction = RouteHandlerFunctionT< http::Request, http::Response >
 
using WebMainHandlerFunction = std::function< void(winux::SharedPointer< http::Request > requestPtr, http::Response &rsp) >
 WebMain逻辑处理函数类型 更多...
 
using ExtensionHandlingHandlerFunction = std::function< bool(winux::String const &extName, winux::String const &fullPath, winux::SharedPointer< http::Request > requestPtr, http::Response &rsp) >
 特别扩展名处理函数类型 更多...
 

Public 成员函数

void onOpenHandler (OpenHandlerFunction handler)
 
void onMessageHandler (MessageHandlerFunction handler)
 
void onCloseHandler (CloseHandlerFunction handler)
 
void onErrorHandler (ErrorHandlerFunction handler)
 
- Public 成员函数 继承自 http::HttpServer
 HttpServer ()
 构造函数0 更多...
 
 HttpServer (winux::ConfigureSettings const &settings)
 构造函数1 更多...
 
 HttpServer (winux::ConfigureSettings const &settings, eiennet::ip::EndPoint const &ep, int threadCount=4, int backlog=0, double serverWait=0.002, double verboseInterval=0.01, eiennet::VerboseOutputType verbose=eiennet::votConsole, int cacheLifeTime=86400)
 构造函数2 更多...
 
bool init (winux::ConfigureSettings const &settings)
 初始化1 更多...
 
bool init (winux::ConfigureSettings const &settings, eiennet::ip::EndPoint const &ep, int threadCount=4, int backlog=0, double serverWait=0.002, double verboseInterval=0.01, eiennet::VerboseOutputType verbose=eiennet::votConsole, int cacheLifeTime=86400)
 初始化2 更多...
 
void crossRoute (winux::String const &method, winux::String const &path, CrossRouteHandlerFunction handler)
 注册过径路由处理器 更多...
 
void route (winux::String const &method, winux::String const &path, RouteHandlerFunction handler)
 注册普通路由处理器 更多...
 
virtual int run (void *runParam) override
 运行 更多...
 
void onCreateResponseHandler (CreateResponseHandlerFunction handler)
 
- Public 成员函数 继承自 eiennet::Server
 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)
 启动服务器 更多...
 
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)
 
- Public 成员函数 继承自 http::UrlRouter
 UrlRouter (http::HttpServerConfig *httpConfig=nullptr)
 构造函数 更多...
 
virtual ~UrlRouter ()
 析构函数 更多...
 
bool init (http::HttpServerConfig *httpConfig)
 初始化 更多...
 
void crossRoute (winux::String const &method, winux::String const &path, CrossRouteHandlerFunction handler)
 注册过径路由处理器 更多...
 
void route (winux::String const &method, winux::String const &path, RouteHandlerFunction handler)
 注册普通路由处理器 更多...
 
void onWebMainHandler (WebMainHandlerFunction handler)
 
void onExtensionHandlingHandler (ExtensionHandlingHandlerFunction handler)
 

Protected 成员函数

virtual bool _beginRouting (winux::SharedPointer< http::HttpRequestCtx > requestCtxPtr, http::UrlPathPartData const &urlData, http::Response &rsp) override
 开始路由。返回false表示不路由(在此判断是否升级为WebSocket) 更多...
 
virtual void onOpen (winux::SharedPointer< WsHttpRequestCtx > requestCtxPtr)
 
virtual void onMessage (winux::SharedPointer< WsHttpRequestCtx > requestCtxPtr, winux::AnsiString const &data, int messageType)
 
virtual void onClose (winux::SharedPointer< WsHttpRequestCtx > requestCtxPtr, winux::uint16 errCode, winux::AnsiString const &errStr)
 
virtual void onError (winux::SharedPointer< WsHttpRequestCtx > requestCtxPtr, WebSocketErrorCode ec)
 
- Protected 成员函数 继承自 http::HttpServer
virtual eiennet::ClientCtxonCreateClient (winux::uint64 clientId, winux::String const &clientEpStr, winux::SharedPointer< eiennet::ip::tcp::Socket > clientSockPtr) override
 
virtual void onClientDataArrived (winux::SharedPointer< eiennet::ClientCtx > clientCtxPtr, winux::Buffer &data) override
 
void _onHttpRequestInternal (winux::SharedPointer< HttpRequestCtx > requestCtxPtr)
 处理一次HTTP请求 更多...
 
virtual bool _beginHttpRequest (winux::SharedPointer< http::HttpRequestCtx > requestCtxPtr, http::UrlPathPartData *urlData)
 开始HTTP请求处理,初始化一些数据 更多...
 
virtual void _endHttpRequest (winux::SharedPointer< http::HttpRequestCtx > requestCtxPtr)
 HTTP请求处理完,进行一些收尾 更多...
 
virtual void _endRouting (winux::SharedPointer< http::HttpRequestCtx > requestCtxPtr, http::UrlPathPartData const &urlData, http::Response &rsp)
 结束路由 更多...
 
virtual void _whatNextTask (winux::SharedPointer< HttpRequestCtx > requestCtxPtr)
 下一次要做的任务 更多...
 
virtual void _doTask (winux::SharedPointer< http::HttpRequestCtx > requestCtxPtr)
 执行客户任务 更多...
 
void _doRecvRequestHeaderTask (winux::SharedPointer< HttpRequestCtx > requestCtxPtr)
 接收请求头任务 更多...
 
void _doRecvRequestBodyTask (winux::SharedPointer< HttpRequestCtx > requestCtxPtr)
 接收请求体任务 更多...
 
virtual ResponseonCreateResponse (Request &req, winux::SimplePointer< RspOutputMgr > outputMgr)
 
- Protected 成员函数 继承自 eiennet::Server
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)
 
- Protected 成员函数 继承自 http::UrlRouter
virtual void routing (winux::SharedPointer< http::Request > requestPtr, http::UrlPathPartData const &urlData, http::Response &rsp)
 路由处理 更多...
 
virtual void onWebMain (winux::SharedPointer< http::Request > requestPtr, http::Response &rsp)
 
virtual bool onExtensionHandling (winux::String const &extName, winux::String const &fullPath, winux::SharedPointer< http::Request > requestPtr, http::Response &rsp)
 

Protected 属性

OpenHandlerFunction _OpenHandler
 
MessageHandlerFunction _MessageHandler
 
CloseHandlerFunction _CloseHandler
 
ErrorHandlerFunction _ErrorHandler
 
- Protected 属性 继承自 http::HttpServer
CreateResponseHandlerFunction _CreateResponseHandler
 
- Protected 属性 继承自 eiennet::Server
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
 提示信息输出方式 更多...
 
- Protected 属性 继承自 http::UrlRouter
http::StaticFileMemoryCache _staticFileCache
 静态文件缓存 更多...
 
std::vector< std::unordered_map< winux::String, std::unordered_map< winux::String, CrossRouteHandlerFunction > > > _crossRouter
 过径路由器 更多...
 
std::unordered_map< winux::String, std::unordered_map< winux::String, RouteHandlerFunction > > _router
 普通路由器 更多...
 
WebMainHandlerFunction _WebMainHandler
 
ExtensionHandlingHandlerFunction _ExtensionHandlingHandler
 

额外继承的成员函数

- Public 属性 继承自 http::HttpServer
HttpServerConfig httpConfig
 HTTP服务器配置对象 更多...
 

详细描述

WebSocket服务器

在文件 ws_websocket.hpp281 行定义.

成员类型定义说明

using ws::WsHttpServer::OpenHandlerFunction = std::function< void ( winux::SharedPointer<WsHttpRequestCtx> requestCtxPtr ) >

在文件 ws_websocket.hpp290 行定义.

using ws::WsHttpServer::MessageHandlerFunction = std::function< void ( winux::SharedPointer<WsHttpRequestCtx> requestCtxPtr, winux::AnsiString const & data, int messageType ) >

在文件 ws_websocket.hpp291 行定义.

using ws::WsHttpServer::CloseHandlerFunction = std::function< void ( winux::SharedPointer<WsHttpRequestCtx> requestCtxPtr, winux::uint16 errCode, winux::AnsiString const & errStr ) >

在文件 ws_websocket.hpp292 行定义.

在文件 ws_websocket.hpp293 行定义.

成员函数说明

virtual bool ws::WsHttpServer::_beginRouting ( winux::SharedPointer< http::HttpRequestCtx requestCtxPtr,
http::UrlPathPartData const &  urlData,
http::Response rsp 
)
overrideprotectedvirtual

开始路由。返回false表示不路由(在此判断是否升级为WebSocket)

重载 http::HttpServer .

void ws::WsHttpServer::onOpenHandler ( OpenHandlerFunction  handler)
inline

在文件 ws_websocket.hpp290 行定义.

virtual void ws::WsHttpServer::onOpen ( winux::SharedPointer< WsHttpRequestCtx requestCtxPtr)
inlineprotectedvirtual

在文件 ws_websocket.hpp290 行定义.

void ws::WsHttpServer::onMessageHandler ( MessageHandlerFunction  handler)
inline

在文件 ws_websocket.hpp291 行定义.

virtual void ws::WsHttpServer::onMessage ( winux::SharedPointer< WsHttpRequestCtx requestCtxPtr,
winux::AnsiString const &  data,
int  messageType 
)
inlineprotectedvirtual

在文件 ws_websocket.hpp291 行定义.

void ws::WsHttpServer::onCloseHandler ( CloseHandlerFunction  handler)
inline

在文件 ws_websocket.hpp292 行定义.

virtual void ws::WsHttpServer::onClose ( winux::SharedPointer< WsHttpRequestCtx requestCtxPtr,
winux::uint16  errCode,
winux::AnsiString const &  errStr 
)
inlineprotectedvirtual

在文件 ws_websocket.hpp292 行定义.

void ws::WsHttpServer::onErrorHandler ( ErrorHandlerFunction  handler)
inline

在文件 ws_websocket.hpp293 行定义.

virtual void ws::WsHttpServer::onError ( winux::SharedPointer< WsHttpRequestCtx requestCtxPtr,
WebSocketErrorCode  ec 
)
inlineprotectedvirtual

在文件 ws_websocket.hpp293 行定义.

类成员变量说明

OpenHandlerFunction ws::WsHttpServer::_OpenHandler
protected

在文件 ws_websocket.hpp290 行定义.

MessageHandlerFunction ws::WsHttpServer::_MessageHandler
protected

在文件 ws_websocket.hpp291 行定义.

CloseHandlerFunction ws::WsHttpServer::_CloseHandler
protected

在文件 ws_websocket.hpp292 行定义.

ErrorHandlerFunction ws::WsHttpServer::_ErrorHandler
protected

在文件 ws_websocket.hpp293 行定义.


该类的文档由以下文件生成: