Compare commits
13 Commits
Author | SHA1 | Date |
---|---|---|
|
383bafc58d | 6 months ago |
|
44b8759b0e | 6 months ago |
|
788111abe5 | 6 months ago |
|
a7cb38990c | 6 months ago |
|
1c5d07c884 | 6 months ago |
|
027a83d95e | 6 months ago |
|
ff54d8f020 | 6 months ago |
|
dc043d541d | 6 months ago |
|
78ec66ff4f | 6 months ago |
|
f28954beae | 7 months ago |
|
e40867a24d | 7 months ago |
|
5b5972a172 | 7 months ago |
|
e4b163747e | 7 months ago |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1 @@
|
||||
[1217/001811.230:ERROR:registration_protocol_win.cc(108)] CreateFile: 系统找不到指定的文件。 (0x2)
|
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.6) # 设置 CMake 的最低版本要求为 3.6
|
||||
project(server) # 定义项目名称为 "server"
|
||||
|
||||
# 设置源文件列表
|
||||
set(SRC
|
||||
WFServer.cc # 添加 WFServer.cc 文件到源文件列表
|
||||
)
|
||||
|
||||
# 如果 MySQL 配置未被设置为 "n"
|
||||
if (NOT MYSQL STREQUAL "n")
|
||||
set(SRC
|
||||
${SRC} # 保留原有的源文件
|
||||
WFMySQLServer.cc # 添加 WFMySQLServer.cc 文件到源文件列表
|
||||
)
|
||||
endif ()
|
||||
|
||||
# 将源文件列表构建为一个对象库
|
||||
add_library(${PROJECT_NAME} OBJECT ${SRC}) # 生成名为 "server" 的对象库
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
Copyright (c) 2021 Sogou, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Authors: Liu Kai (liukaidx@sogou-inc.com)
|
||||
*/
|
||||
|
||||
#ifndef _WFDNSSERVER_H_
|
||||
#define _WFDNSSERVER_H_
|
||||
|
||||
#include "DnsMessage.h" // 引入 DNS 消息相关的头文件
|
||||
#include "WFServer.h" // 引入服务器功能的头文件
|
||||
#include "WFTaskFactory.h" // 引入任务工厂以创建 DNS 任务
|
||||
|
||||
// 定义一个 dns_process_t 类型,它是一个接受 WFDnsTask 指针并返回 void 的函数对象
|
||||
using dns_process_t = std::function<void (WFDnsTask *)>;
|
||||
|
||||
// 定义 WFDnsServer 类型,基于 WFServer 模板类,使用 DnsRequest 和 DnsResponse 作为协议
|
||||
using WFDnsServer = WFServer<protocol::DnsRequest, protocol::DnsResponse>;
|
||||
|
||||
// 设置 DNS 服务器的默认参数
|
||||
static constexpr struct WFServerParams DNS_SERVER_PARAMS_DEFAULT =
|
||||
{
|
||||
.transport_type = TT_UDP, // 传输类型为 UDP
|
||||
.max_connections = 2000, // 最大连接数
|
||||
.peer_response_timeout = 10 * 1000, // 对端响应超时时间
|
||||
.receive_timeout = -1, // 接收超时时间,-1 表示不超时
|
||||
.keep_alive_timeout = 300 * 1000, // 保持连接的超时时间
|
||||
.request_size_limit = (size_t)-1, // 请求大小限制,-1 表示无限制
|
||||
.ssl_accept_timeout = 5000, // SSL 接受超时时间
|
||||
};
|
||||
|
||||
// WFDnsServer 构造函数的特化模板
|
||||
template<> inline
|
||||
WFDnsServer::WFServer(dns_process_t proc) :
|
||||
WFServerBase(&DNS_SERVER_PARAMS_DEFAULT), // 调用基类构造函数,传入默认参数
|
||||
process(std::move(proc)) // 移动构造函数以提高性能
|
||||
{
|
||||
}
|
||||
|
||||
// 创建新的会话,重写基类方法
|
||||
template<> inline
|
||||
CommSession *WFDnsServer::new_session(long long seq, CommConnection *conn)
|
||||
{
|
||||
WFDnsTask *task;
|
||||
|
||||
// 使用任务工厂创建一个新的 DNS 任务
|
||||
task = WFServerTaskFactory::create_dns_task(this, this->process);
|
||||
// 设置保持连接的超时时间
|
||||
task->set_keep_alive(this->params.keep_alive_timeout);
|
||||
// 设置接收超时时间
|
||||
task->set_receive_timeout(this->params.receive_timeout);
|
||||
// 设置请求大小限制
|
||||
task->get_req()->set_size_limit(this->params.request_size_limit);
|
||||
|
||||
return task; // 返回创建的任务
|
||||
}
|
||||
|
||||
#endif // _WFDNSSERVER_H_
|
@ -0,0 +1,10 @@
|
||||
-- 定义一个 xmake 目标,名为 server
|
||||
target("server")
|
||||
set_kind("object") -- 设置目标类型为对象文件
|
||||
|
||||
add_files("*.cc") -- 添加当前目录下所有的 .cc 文件到目标中
|
||||
|
||||
-- 检查是否未定义 MySQL 配置
|
||||
if not has_config("mysql") then
|
||||
remove_files("WFMySQLServer.cc") -- 如果未定义 MySQL 配置,则移除 MySQL 服务器相关的源文件
|
||||
end
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,27 @@
|
||||
cmake_minimum_required(VERSION 3.6)
|
||||
project(kernel)
|
||||
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
|
||||
set(IOSERVICE_FILE IOService_linux.cc)
|
||||
elseif (UNIX)
|
||||
set(IOSERVICE_FILE IOService_thread.cc)
|
||||
else ()
|
||||
message(FATAL_ERROR "IOService unsupported.")
|
||||
endif ()
|
||||
|
||||
set(SRC
|
||||
${IOSERVICE_FILE}
|
||||
mpoller.c
|
||||
poller.c
|
||||
rbtree.c
|
||||
msgqueue.c
|
||||
thrdpool.c
|
||||
CommRequest.cc
|
||||
CommScheduler.cc
|
||||
Communicator.cc
|
||||
Executor.cc
|
||||
SubTask.cc
|
||||
)
|
||||
|
||||
add_library(${PROJECT_NAME} OBJECT ${SRC})
|
||||
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
Copyright (c) 2019 Sogou, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
Authors: Xie Han (xiehan@sogou-inc.com)
|
||||
*/
|
||||
|
||||
#ifndef _WFHTTPSERVER_H_
|
||||
#define _WFHTTPSERVER_H_
|
||||
|
||||
#include <utility> // 引入标准库中的工具函数
|
||||
#include "HttpMessage.h" // 引入 HTTP 消息相关的头文件
|
||||
#include "WFServer.h" // 引入服务器功能的头文件
|
||||
#include "WFTaskFactory.h" // 引入任务工厂以创建 HTTP 任务
|
||||
|
||||
// 定义一个 http_process_t 类型,它是一个接受 WFHttpTask 指针并返回 void 的函数对象
|
||||
using http_process_t = std::function<void (WFHttpTask *)>;
|
||||
|
||||
// 定义 WFHttpServer 类型,基于 WFServer 模板类,使用 HttpRequest 和 HttpResponse 作为协议
|
||||
using WFHttpServer = WFServer<protocol::HttpRequest, protocol::HttpResponse>;
|
||||
|
||||
// 设置 HTTP 服务器的默认参数
|
||||
static constexpr struct WFServerParams HTTP_SERVER_PARAMS_DEFAULT =
|
||||
{
|
||||
.transport_type = TT_TCP, // 传输类型为 TCP
|
||||
.max_connections = 2000, // 最大连接数
|
||||
.peer_response_timeout = 10 * 1000, // 对端响应超时时间
|
||||
.receive_timeout = -1, // 接收超时时间,-1 表示不超时
|
||||
.keep_alive_timeout = 60 * 1000, // 保持连接的超时时间
|
||||
.request_size_limit = (size_t)-1, // 请求大小限制,-1 表示无限制
|
||||
.ssl_accept_timeout = 10 * 1000, // SSL 接受超时时间
|
||||
};
|
||||
|
||||
// WFHttpServer 构造函数的特化模板
|
||||
template<> inline
|
||||
WFHttpServer::WFServer(http_process_t proc) :
|
||||
WFServerBase(&HTTP_SERVER_PARAMS_DEFAULT), // 调用基类构造函数,传入默认参数
|
||||
process(std::move(proc)) // 移动构造函数以提高性能
|
||||
{
|
||||
}
|
||||
|
||||
// 创建新的会话,重写基类的方法
|
||||
template<> inline
|
||||
CommSession *WFHttpServer::new_session(long long seq, CommConnection *conn)
|
||||
{
|
||||
WFHttpTask *task; // 声明一个 HTTP 任务指针
|
||||
|
||||
// 使用任务工厂创建一个新的 HTTP 任务
|
||||
task = WFServerTaskFactory::create_http_task(this, this->process);
|
||||
// 设置保持连接的超时时间
|
||||
task->set_keep_alive(this->params.keep_alive_timeout);
|
||||
// 设置接收超时时间
|
||||
task->set_receive_timeout(this->params.receive_timeout);
|
||||
// 设置请求大小限制
|
||||
task->get_req()->set_size_limit(this->params.request_size_limit);
|
||||
|
||||
return task; // 返回创建的任务
|
||||
}
|
||||
|
||||
#endif // _WFHTTPSERVER_H_
|
Binary file not shown.
Loading…
Reference in new issue