Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
旷野亮光
engine2.0
提交
85d05359
E
engine2.0
项目概览
旷野亮光
/
engine2.0
与 Fork 源项目一致
Fork自
xc13262215230 / engine2.0
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine2.0
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
85d05359
编写于
4月 11, 2023
作者:
X
xuchi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
解决方案新增项目:http_server
上级
04cbcc1f
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
226 addition
and
26 deletion
+226
-26
engine2.0/engine2.0/Depends/include/Client.hpp
engine2.0/engine2.0/Depends/include/Client.hpp
+21
-18
engine2.0/engine2.0/Depends/include/Config.hpp
engine2.0/engine2.0/Depends/include/Config.hpp
+1
-1
engine2.0/engine2.0/Depends/include/Log.hpp
engine2.0/engine2.0/Depends/include/Log.hpp
+1
-2
engine2.0/engine2.0/Doc/Record.txt
engine2.0/engine2.0/Doc/Record.txt
+2
-0
engine2.0/engine2.0/EasyServer/server.cpp
engine2.0/engine2.0/EasyServer/server.cpp
+3
-3
engine2.0/engine2.0/HelloCpp/HelloCpp.log.txt
engine2.0/engine2.0/HelloCpp/HelloCpp.log.txt
+6
-0
engine2.0/engine2.0/HelloCpp/main.cpp
engine2.0/engine2.0/HelloCpp/main.cpp
+3
-2
engine2.0/engine2.0/HelloHttp/HelloHttp.vcxproj
engine2.0/engine2.0/HelloHttp/HelloHttp.vcxproj
+80
-0
engine2.0/engine2.0/HelloHttp/HelloHttp.vcxproj.filters
engine2.0/engine2.0/HelloHttp/HelloHttp.vcxproj.filters
+22
-0
engine2.0/engine2.0/HelloHttp/HelloHttp.vcxproj.user
engine2.0/engine2.0/HelloHttp/HelloHttp.vcxproj.user
+4
-0
engine2.0/engine2.0/HelloHttp/Server.cpp
engine2.0/engine2.0/HelloHttp/Server.cpp
+77
-0
engine2.0/engine2.0/engine2.0.sdf
engine2.0/engine2.0/engine2.0.sdf
+0
-0
engine2.0/engine2.0/engine2.0.sln
engine2.0/engine2.0/engine2.0.sln
+6
-0
engine2.0/engine2.0/engine2.0.v12.suo
engine2.0/engine2.0/engine2.0.v12.suo
+0
-0
未找到文件。
engine2.0/engine2.0/Depends/include/Client.hpp
浏览文件 @
85d05359
...
...
@@ -150,6 +150,26 @@ namespace doyou {
return
false
;
}
// 设置客户端IP地址
void
SetIp
(
char
*
ip
)
{
if
(
nullptr
==
ip
)
{
return
;
}
// 分析:如果src传入实际字串长度小于para3, 会将src字串拷贝至dest,不足para3长度用空字符填充
// 如果src传入实际字串长度等于para3, 将src字串拷贝至dest
// 如果src传入实际字串长度大于para3, 只将para3指定长度拷贝至dest, 避免数据溢出
strncpy
(
_ip
,
ip
,
INET6_ADDRSTRLEN
);
// 比strcpy函数更安全,para3-要复制的字符个数。如果源字符串的长度小于n个字符,则目标字符串将被用空字符填充直到其长度为n个字符。
}
// 返回客户端IP地址
char
*
GetIp
()
{
return
_ip
;
// 指针变量间值拷贝,通过指针变量的值可以间接访问指针变量值指向的对象
}
// Iocp网络模型特有代码块
#ifdef CELL_USE_IOCP
// 分析:使用Iocp比使用其它网络模型要多两个IO_DATA_BASE部分,方法有两个
...
...
@@ -205,24 +225,7 @@ namespace doyou {
return
(
_isPostRecv
||
_isPostSend
);
// 逻辑或:只要有一个及其以上为真,则为真
}
// 设置客户端IP地址
void
SetIp
(
char
*
ip
)
{
if
(
nullptr
==
ip
)
{
return
;
}
// 分析:如果src传入实际字串长度小于para3, 会将src字串拷贝至dest,不足para3长度用空字符填充
// 如果src传入实际字串长度等于para3, 将src字串拷贝至dest
// 如果src传入实际字串长度大于para3, 只将para3指定长度拷贝至dest, 避免数据溢出
strncpy
(
_ip
,
ip
,
INET6_ADDRSTRLEN
);
// 比strcpy函数更安全,para3-要复制的字符个数。如果源字符串的长度小于n个字符,则目标字符串将被用空字符填充直到其长度为n个字符。
}
// 返回客户端IP地址
char
*
GetIp
()
{
return
_ip
;
// 指针变量间值拷贝,通过指针变量的值可以间接访问指针变量值指向的对象
}
#endif // CELL_USE_IOCP
...
...
engine2.0/engine2.0/Depends/include/Config.hpp
浏览文件 @
85d05359
...
...
@@ -6,7 +6,7 @@
*/
#include<string>
#include<map>
#include"Log.hpp" // 分析:在
celllog.hpp里面不能用cell
config.hpp, 存在循环引用问题(这也是将声明和定义写在同一文件的弊端),会出现重定义问题。如果将声明和定义份文件写,就可以互相引用了,因为可以重复声明。
#include"Log.hpp" // 分析:在
log.hpp里面不能用
config.hpp, 存在循环引用问题(这也是将声明和定义写在同一文件的弊端),会出现重定义问题。如果将声明和定义份文件写,就可以互相引用了,因为可以重复声明。
namespace
doyou
{
namespace
io
{
// 增加两层命令空间,避免在其它项目应用时类名出现冲突
...
...
engine2.0/engine2.0/Depends/include/Log.hpp
浏览文件 @
85d05359
#
ifndef
_CELL_LOG_HPP_
#define _CELL_LOG_HPP_
//
#include"CELL.hpp"
#include"CELL.hpp"
#include "Task.hpp"
#include <ctime>
//#include <stdio.h>
namespace
doyou
{
namespace
io
{
// 增加两层命令空间,避免在其它项目应用时类名出现冲突
...
...
engine2.0/engine2.0/Doc/Record.txt
浏览文件 @
85d05359
...
...
@@ -76,5 +76,7 @@ IP直接存入黑名单中,所以,服务端获取客户端IP地址很有意
实际记录本地文件或终端输出是另一个线程,如果调用接口线程传入的是一个临时变量,在具体
输出日志线程在访问变量是很可能已经被系统回收,从而记录日志为乱码。
24.在一个进程中,主线程已经退出,子线程还没有退出,子线程会被破退出,同时可能出现系统错误。
engine2.0/engine2.0/EasyServer/server.cpp
浏览文件 @
85d05359
// 高性能服务器可采用的网络通信模型三选一:select/epoll/iocp/
//
#include "TcpSelectServer.hpp" // using select, both linux and windows.
#include "TcpSelectServer.hpp" // using select, both linux and windows.
//#include "TcpEpollServer.hpp" // using epoll, only linux.
#include "TcpIocpServer.hpp" // using iocp, only windows.
//
#include "TcpIocpServer.hpp" // using iocp, only windows.
#include "MsgStream.hpp"
#include "Config.hpp"
...
...
@@ -11,7 +11,7 @@
using
namespace
doyou
::
io
;
// 使用名称空间
// 可使用服务模型(三选一):1-TcpSelectServer 2-TcpEpollServer 3-TcpIocpServer
class
MyServer
:
public
Tcp
Iocp
Server
class
MyServer
:
public
Tcp
Select
Server
{
public:
MyServer
()
...
...
engine2.0/engine2.0/HelloCpp/HelloCpp.log.txt
0 → 100644
浏览文件 @
85d05359
Info [2023-4-11 23:18:10]Log::setLogPath success,<HelloCpp.log.txt,w>
Info [2023-4-11 23:18:10]a=500
Info [2023-4-11 23:18:10]the first string.
Info [2023-4-11 23:18:10]the second string.
Info [2023-4-11 23:18:10]the third string.
Info [2023-4-11 23:18:10]the four string.
engine2.0/engine2.0/HelloCpp/main.cpp
浏览文件 @
85d05359
#include "TcpIocpServer.hpp"
//#include "Log.hpp"
#include "Log.hpp"
#include "Config.hpp"
using
namespace
doyou
::
io
;
// 使用名称空间
...
...
engine2.0/engine2.0/HelloHttp/HelloHttp.vcxproj
0 → 100644
浏览文件 @
85d05359
<?xml version="1.0" encoding="utf-8"?>
<Project
DefaultTargets=
"Build"
ToolsVersion=
"12.0"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<ItemGroup
Label=
"ProjectConfigurations"
>
<ProjectConfiguration
Include=
"Debug|Win32"
>
<Configuration>
Debug
</Configuration>
<Platform>
Win32
</Platform>
</ProjectConfiguration>
<ProjectConfiguration
Include=
"Release|Win32"
>
<Configuration>
Release
</Configuration>
<Platform>
Win32
</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup
Label=
"Globals"
>
<ProjectGuid>
{3B0734CE-4E91-498A-9621-AB0385F7AB98}
</ProjectGuid>
<RootNamespace>
HelloHttp
</RootNamespace>
</PropertyGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.Default.props"
/>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
Label=
"Configuration"
>
<ConfigurationType>
Application
</ConfigurationType>
<UseDebugLibraries>
true
</UseDebugLibraries>
<PlatformToolset>
v120
</PlatformToolset>
<CharacterSet>
MultiByte
</CharacterSet>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
Label=
"Configuration"
>
<ConfigurationType>
Application
</ConfigurationType>
<UseDebugLibraries>
false
</UseDebugLibraries>
<PlatformToolset>
v120
</PlatformToolset>
<WholeProgramOptimization>
true
</WholeProgramOptimization>
<CharacterSet>
MultiByte
</CharacterSet>
</PropertyGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.props"
/>
<ImportGroup
Label=
"ExtensionSettings"
>
</ImportGroup>
<ImportGroup
Label=
"PropertySheets"
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
</ImportGroup>
<ImportGroup
Label=
"PropertySheets"
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
<Import
Project=
"$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition=
"exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')"
Label=
"LocalAppDataPlatform"
/>
</ImportGroup>
<PropertyGroup
Label=
"UserMacros"
/>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
<OutDir>
$(SolutionDir)../bin/$(Configuration)\
</OutDir>
<IntDir>
$(SolutionDir)../tmp/$(Configuration)\
</IntDir>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
<OutDir>
$(SolutionDir)../bin/$(Configuration)\
</OutDir>
<IntDir>
$(SolutionDir)../tmp/$(Configuration)\
</IntDir>
</PropertyGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
<ClCompile>
<WarningLevel>
Level3
</WarningLevel>
<Optimization>
Disabled
</Optimization>
<SDLCheck>
false
</SDLCheck>
<AdditionalIncludeDirectories>
..\Depends\include
</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<GenerateDebugInformation>
true
</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
<ClCompile>
<WarningLevel>
Level3
</WarningLevel>
<Optimization>
MaxSpeed
</Optimization>
<FunctionLevelLinking>
true
</FunctionLevelLinking>
<IntrinsicFunctions>
true
</IntrinsicFunctions>
<SDLCheck>
false
</SDLCheck>
</ClCompile>
<Link>
<GenerateDebugInformation>
true
</GenerateDebugInformation>
<EnableCOMDATFolding>
true
</EnableCOMDATFolding>
<OptimizeReferences>
true
</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile
Include=
"Server.cpp"
/>
</ItemGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.targets"
/>
<ImportGroup
Label=
"ExtensionTargets"
>
</ImportGroup>
</Project>
\ No newline at end of file
engine2.0/engine2.0/HelloHttp/HelloHttp.vcxproj.filters
0 → 100644
浏览文件 @
85d05359
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"4.0"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<ItemGroup>
<Filter
Include=
"源文件"
>
<UniqueIdentifier>
{4FC737F1-C7A5-4376-A066-2A32D752A2FF}
</UniqueIdentifier>
<Extensions>
cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
</Extensions>
</Filter>
<Filter
Include=
"头文件"
>
<UniqueIdentifier>
{93995380-89BD-4b04-88EB-625FBE52EBFB}
</UniqueIdentifier>
<Extensions>
h;hh;hpp;hxx;hm;inl;inc;xsd
</Extensions>
</Filter>
<Filter
Include=
"资源文件"
>
<UniqueIdentifier>
{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
</UniqueIdentifier>
<Extensions>
rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile
Include=
"Server.cpp"
>
<Filter>
源文件
</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
engine2.0/engine2.0/HelloHttp/HelloHttp.vcxproj.user
0 → 100644
浏览文件 @
85d05359
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"12.0"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<PropertyGroup
/>
</Project>
\ No newline at end of file
engine2.0/engine2.0/HelloHttp/Server.cpp
0 → 100644
浏览文件 @
85d05359
#pragma execution_character_set("utf-8")
#include "Log.hpp"
#include "Config.hpp"
//#include "TcpSelectServer.hpp"
//#include "TcpEpollServer.hpp"
#include "TcpIocpServer.hpp" // 在windows系统下面首选iocp网络模型
using
namespace
doyou
::
io
;
// 命名空间
// 可使用服务模型(三选一):1-TcpSelectServer 2-TcpEpollServer 3-TcpIocpServer
class
MyServer
:
public
TcpIocpServer
{
public:
private:
};
int
main
(
int
argc
,
char
*
args
[])
{
// 设置运行日志名称
Log
::
Instance
().
setLogPath
(
"ServerLog"
,
"w"
,
false
);
Config
::
Instance
().
Init
(
argc
,
args
);
// 解析配置
const
char
*
strIP
=
Config
::
Instance
().
getStr
(
"strIP"
,
"any"
);
uint16_t
nPort
=
Config
::
Instance
().
getInt
(
"nPort"
,
4567
);
int
nThread
=
Config
::
Instance
().
getInt
(
"nThread"
,
1
);
if
(
strcmp
(
strIP
,
"any"
)
==
0
)
{
strIP
=
nullptr
;
}
MyServer
server
;
// 在栈空间实例化对象
if
(
Config
::
Instance
().
hasKey
(
"-ipv6"
))
{
CELLLog_Info
(
"-ipv6"
);
server
.
InitSocket
(
AF_INET6
);
}
else
{
CELLLog_Info
(
"-ipv4"
);
server
.
InitSocket
();
}
server
.
Bind
(
strIP
,
nPort
);
// 分析:服务器同一时刻能监听的最大客户端数量,可以提高服务器连接客户端的效率
server
.
Listen
(
SOMAXCONN
);
// 64
server
.
Start
(
nThread
);
// 在主线程中等待用户输入命令
while
(
true
)
{
char
cmdBuf
[
256
]
=
{};
scanf
(
"%s"
,
cmdBuf
);
// 等待用户输入,当前函数为阻塞函数
if
(
0
==
strcmp
(
cmdBuf
,
"exit"
))
{
server
.
Close
();
break
;
}
else
{
CELLLog_Info
(
"undefine cmd"
);
}
}
CELLLog_Info
(
"exit."
);
return
0
;
}
engine2.0/engine2.0/engine2.0.sdf
浏览文件 @
85d05359
无法预览此类型文件
engine2.0/engine2.0/engine2.0.sln
浏览文件 @
85d05359
...
...
@@ -18,6 +18,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestDemo", "TestDemo\TestDe
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HelloCpp", "HelloCpp\HelloCpp.vcxproj", "{14149BAD-FE3D-45FB-8DB8-831E4198C72D}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HelloHttp", "HelloHttp\HelloHttp.vcxproj", "{3B0734CE-4E91-498A-9621-AB0385F7AB98}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
...
...
@@ -44,6 +46,10 @@ Global
{14149BAD-FE3D-45FB-8DB8-831E4198C72D}.Debug|Win32.Build.0 = Debug|Win32
{14149BAD-FE3D-45FB-8DB8-831E4198C72D}.Release|Win32.ActiveCfg = Release|Win32
{14149BAD-FE3D-45FB-8DB8-831E4198C72D}.Release|Win32.Build.0 = Release|Win32
{3B0734CE-4E91-498A-9621-AB0385F7AB98}.Debug|Win32.ActiveCfg = Debug|Win32
{3B0734CE-4E91-498A-9621-AB0385F7AB98}.Debug|Win32.Build.0 = Debug|Win32
{3B0734CE-4E91-498A-9621-AB0385F7AB98}.Release|Win32.ActiveCfg = Release|Win32
{3B0734CE-4E91-498A-9621-AB0385F7AB98}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
...
...
engine2.0/engine2.0/engine2.0.v12.suo
浏览文件 @
85d05359
无法预览此类型文件
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录