fastdo  0.6.16
http::HttpServer类 参考

HTTP服务器 更多...

#include <http_HttpServer.hpp>

类 http::HttpServer 继承关系图:
http::HttpServer 的协作图:

Public 类型

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 成员函数

 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)
 

Public 属性

HttpServerConfig httpConfig
 HTTP服务器配置对象 更多...
 

Protected 成员函数

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 bool _beginRouting (winux::SharedPointer< http::HttpRequestCtx > requestCtxPtr, http::UrlPathPartData const &urlData, http::Response &rsp)
 开始路由。返回false表示不路由 更多...
 
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 属性

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
 

友元

class HttpRequestCtx
 

详细描述

HTTP服务器

在文件 http_HttpServer.hpp6 行定义.

成员类型定义说明

过径路由处理函数类型

参数
requestCtxPtr请求场景对象
rsp响应对象
urlPathPartArrURL路径部分数组
i当前URL路径部分的索引
返回
bool
返回值
false终止过径路由继续
true继续检测其他路由响应

在文件 http_HttpServer.hpp18 行定义.

普通路由处理函数类型

参数
requestCtxPtr请求场景对象
rsp响应对象

在文件 http_HttpServer.hpp24 行定义.

创建响应处理函数类型

参数
req请求对象
outputMgr响应输出管理器

在文件 http_HttpServer.hpp140 行定义.

构造及析构函数说明

http::HttpServer::HttpServer ( )

构造函数0

http::HttpServer::HttpServer ( winux::ConfigureSettings const &  settings)

构造函数1

参数
settings配置设置
http::HttpServer::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

参数
settings配置设置
ep服务监听的EndPoint
threadCount线程池线程数量
backloglisten(backlog)
serverWait服务器IO等待时间
verboseIntervalverbose信息刷新间隔
verbose是否显示提示信息
cacheLifeTime静态文件缓存时间

成员函数说明

bool http::HttpServer::init ( winux::ConfigureSettings const &  settings)

初始化1

参数
settings配置设置
返回
bool
bool http::HttpServer::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

参数
settings配置设置
ep服务监听的EndPoint
threadCount线程池线程数量
backloglisten(backlog)
serverWait服务器IO等待时间
verboseIntervalverbose信息刷新间隔
verbose是否显示提示信息
cacheLifeTime静态文件缓存时间
返回
bool
void http::HttpServer::crossRoute ( winux::String const &  method,
winux::String const &  path,
CrossRouteHandlerFunction  handler 
)

注册过径路由处理器

参数
methodmethod为半角逗号','分隔的HTTP方法名字符串,可以是"*"表示通配所有HTTP方法
pathpath需以'/'开头
handler处理器函数
void http::HttpServer::route ( winux::String const &  method,
winux::String const &  path,
RouteHandlerFunction  handler 
)

注册普通路由处理器

参数
methodmethod为半角逗号','分隔的HTTP方法名字符串,可以是"*"表示通配所有HTTP方法
pathpath需以'/'开头
handler处理器函数
virtual int http::HttpServer::run ( void *  runParam)
overridevirtual

运行

重载 eiennet::Server .

eienwebx::HttpApp 重载.

virtual eiennet::ClientCtx* http::HttpServer::onCreateClient ( winux::uint64  clientId,
winux::String const &  clientEpStr,
winux::SharedPointer< eiennet::ip::tcp::Socket clientSockPtr 
)
overrideprotectedvirtual

重载 eiennet::Server .

eienwebx::HttpApp 重载.

virtual void http::HttpServer::onClientDataArrived ( winux::SharedPointer< eiennet::ClientCtx clientCtxPtr,
winux::Buffer data 
)
overrideprotectedvirtual

重载 eiennet::Server .

void http::HttpServer::_onHttpRequestInternal ( winux::SharedPointer< HttpRequestCtx requestCtxPtr)
protected

处理一次HTTP请求

virtual bool http::HttpServer::_beginHttpRequest ( winux::SharedPointer< http::HttpRequestCtx requestCtxPtr,
http::UrlPathPartData urlData 
)
protectedvirtual

开始HTTP请求处理,初始化一些数据

eienwebx::HttpApp 重载.

virtual void http::HttpServer::_endHttpRequest ( winux::SharedPointer< http::HttpRequestCtx requestCtxPtr)
protectedvirtual

HTTP请求处理完,进行一些收尾

virtual bool http::HttpServer::_beginRouting ( winux::SharedPointer< http::HttpRequestCtx requestCtxPtr,
http::UrlPathPartData const &  urlData,
http::Response rsp 
)
inlineprotectedvirtual

开始路由。返回false表示不路由

ws::WsHttpServer 重载.

在文件 http_HttpServer.hpp115 行定义.

virtual void http::HttpServer::_endRouting ( winux::SharedPointer< http::HttpRequestCtx requestCtxPtr,
http::UrlPathPartData const &  urlData,
http::Response rsp 
)
inlineprotectedvirtual

结束路由

在文件 http_HttpServer.hpp117 行定义.

virtual void http::HttpServer::_whatNextTask ( winux::SharedPointer< HttpRequestCtx requestCtxPtr)
protectedvirtual

下一次要做的任务

virtual void http::HttpServer::_doTask ( winux::SharedPointer< http::HttpRequestCtx requestCtxPtr)
protectedvirtual

执行客户任务

void http::HttpServer::_doRecvRequestHeaderTask ( winux::SharedPointer< HttpRequestCtx requestCtxPtr)
protected

接收请求头任务

void http::HttpServer::_doRecvRequestBodyTask ( winux::SharedPointer< HttpRequestCtx requestCtxPtr)
protected

接收请求体任务

void http::HttpServer::onCreateResponseHandler ( CreateResponseHandlerFunction  handler)
inline

在文件 http_HttpServer.hpp140 行定义.

virtual Response* http::HttpServer::onCreateResponse ( Request req,
winux::SimplePointer< RspOutputMgr outputMgr 
)
protectedvirtual

eienwebx::HttpApp 重载.

友元及相关函数文档

friend class HttpRequestCtx
friend

在文件 http_HttpServer.hpp142 行定义.

类成员变量说明

HttpServerConfig http::HttpServer::httpConfig

HTTP服务器配置对象

在文件 http_HttpServer.hpp101 行定义.

CreateResponseHandlerFunction http::HttpServer::_CreateResponseHandler
protected

在文件 http_HttpServer.hpp140 行定义.


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