Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sunxiaotianmg
Mozi.HttpEmbedded
提交
a220f6aa
M
Mozi.HttpEmbedded
项目概览
sunxiaotianmg
/
Mozi.HttpEmbedded
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
Mozi.HttpEmbedded
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a220f6aa
编写于
9月 25, 2021
作者:
JasonWcx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
InvokeAfterReceiveEnd增加try catch
上级
94f8da09
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
39 addition
and
27 deletion
+39
-27
Mozi.HttpEmbedded.Test/Program.cs
Mozi.HttpEmbedded.Test/Program.cs
+1
-1
Mozi.HttpEmbedded/HttpRequest.cs
Mozi.HttpEmbedded/HttpRequest.cs
+4
-4
Mozi.HttpEmbedded/SocketServer.cs
Mozi.HttpEmbedded/SocketServer.cs
+34
-22
未找到文件。
Mozi.HttpEmbedded.Test/Program.cs
浏览文件 @
a220f6aa
...
...
@@ -27,7 +27,7 @@ namespace Mozi.HttpEmbedded.Test
//启用HTTPS
//hs.UseHttps().LoadCert(AppDomain.CurrentDomain.BaseDirectory + @"Cert\ServerCert.pfx", "12345678");
//配置端口并启动服务器
hs
.
SetPort
(
900
0
).
Start
();
hs
.
SetPort
(
808
0
).
Start
();
//开启认证
//hs.UseAuth(AuthorizationType.Basic).SetUser("admin", "admin");
...
...
Mozi.HttpEmbedded/HttpRequest.cs
浏览文件 @
a220f6aa
...
...
@@ -151,7 +151,7 @@ namespace Mozi.HttpEmbedded
int
posCaret
=
0
;
int
count
=
0
;
int
ind
ex
=
0
;
int
ind
Line
=
0
;
int
dataLength
=
data
.
Length
;
while
((
posCR
<
dataLength
)
&&
Array
.
IndexOf
(
data
,
ASCIICode
.
CR
,
posCR
+
1
)
>
0
)
{
...
...
@@ -160,7 +160,7 @@ namespace Mozi.HttpEmbedded
//连续两个CR
byte
[]
fragement
=
new
byte
[
posCR
-
posCaret
];
Array
.
Copy
(
data
,
posCaret
,
fragement
,
0
,
posCR
-
posCaret
);
if
(
ind
ex
==
0
)
if
(
ind
Line
==
0
)
{
ParseRequestLine
(
ref
req
,
fragement
);
}
...
...
@@ -175,7 +175,7 @@ namespace Mozi.HttpEmbedded
}
//跳过分割字节段
posCaret
=
posCR
+
2
;
ind
ex
++;
ind
Line
++;
//TODO 置空对象
}
...
...
@@ -594,7 +594,7 @@ namespace Mozi.HttpEmbedded
req
.
Method
=
rm
;
//判断方法是否是已知方法
if
(
object
.
Equals
(
req
.
Method
,
null
))
if
(
Equals
(
req
.
Method
,
null
))
{
req
.
Method
=
new
RequestMethod
(
sMethod
);
}
...
...
Mozi.HttpEmbedded/SocketServer.cs
浏览文件 @
a220f6aa
...
...
@@ -160,25 +160,32 @@ namespace Mozi.HttpEmbedded
Socket
client
=
so
.
WorkSocket
;
if
(
client
.
Connected
)
{
int
iByteRead
=
client
.
EndReceive
(
iar
);
if
(
iByteRead
>
0
)
try
{
//置空数据缓冲区
so
.
ResetBuffer
(
iByteRead
);
if
(
client
.
Available
>
0
)
int
iByteRead
=
client
.
EndReceive
(
iar
);
if
(
iByteRead
>
0
)
{
//Thread.Sleep(10);
client
.
BeginReceive
(
so
.
Buffer
,
0
,
so
.
Buffer
.
Length
,
SocketFlags
.
None
,
CallbackReceived
,
so
);
//置空数据缓冲区
so
.
ResetBuffer
(
iByteRead
);
if
(
client
.
Available
>
0
)
{
//Thread.Sleep(10);
client
.
BeginReceive
(
so
.
Buffer
,
0
,
so
.
Buffer
.
Length
,
SocketFlags
.
None
,
CallbackReceived
,
so
);
}
else
{
InvokeAfterReceiveEnd
(
so
,
client
);
}
}
else
{
InvokeAfterReceiveEnd
(
so
,
client
);
}
}
else
finally
{
InvokeAfterReceiveEnd
(
so
,
client
);
}
}
else
...
...
@@ -188,19 +195,24 @@ namespace Mozi.HttpEmbedded
}
private
void
InvokeAfterReceiveEnd
(
StateObject
so
,
Socket
client
)
{
RemoveClientSocket
(
so
);
if
(
AfterReceiveEnd
!=
null
)
try
{
AfterReceiveEnd
(
this
,
new
DataTransferArgs
()
{
Data
=
so
.
Data
.
ToArray
(),
IP
=
so
.
IP
,
Port
=
so
.
RemotePort
,
Socket
=
so
.
WorkSocket
,
Client
=
client
,
State
=
so
});
RemoveClientSocket
(
so
);
if
(
AfterReceiveEnd
!=
null
)
{
AfterReceiveEnd
(
this
,
new
DataTransferArgs
()
{
Data
=
so
.
Data
.
ToArray
(),
IP
=
so
.
IP
,
Port
=
so
.
RemotePort
,
Socket
=
so
.
WorkSocket
,
Client
=
client
,
State
=
so
});
}
}
finally
{
}
}
//TODO 此处开启Socket状态监听,对断开的链接进行关闭销毁
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录