Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
MQTTnet
提交
9b20e0a4
MQTTnet
项目概览
dotNET Platform
/
MQTTnet
10 个月 前同步成功
通知
0
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
MQTTnet
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
9b20e0a4
编写于
11月 28, 2022
作者:
C
Christian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor code
上级
41df2ec5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
29 addition
and
30 deletion
+29
-30
Source/MQTTnet.AspnetCore/MQTTnet.AspNetCore.csproj
Source/MQTTnet.AspnetCore/MQTTnet.AspNetCore.csproj
+1
-0
Source/MQTTnet.AspnetCore/MqttConnectionContext.cs
Source/MQTTnet.AspnetCore/MqttConnectionContext.cs
+28
-30
未找到文件。
Source/MQTTnet.AspnetCore/MQTTnet.AspNetCore.csproj
浏览文件 @
9b20e0a4
...
...
@@ -33,6 +33,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>1591</NoWarn>
<LangVersion>7.3</LangVersion>
</PropertyGroup>
<ItemGroup>
...
...
Source/MQTTnet.AspnetCore/MqttConnectionContext.cs
浏览文件 @
9b20e0a4
...
...
@@ -2,6 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using
System
;
using
System.IO.Pipelines
;
using
System.Security.Cryptography.X509Certificates
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Connections
;
using
Microsoft.AspNetCore.Http.Connections.Features
;
using
MQTTnet.Adapter
;
...
...
@@ -10,18 +15,13 @@ using MQTTnet.Exceptions;
using
MQTTnet.Formatter
;
using
MQTTnet.Internal
;
using
MQTTnet.Packets
;
using
System
;
using
System.IO.Pipelines
;
using
System.Security.Cryptography.X509Certificates
;
using
System.Threading
;
using
System.Threading.Tasks
;
namespace
MQTTnet.AspNetCore
{
public
sealed
class
MqttConnectionContext
:
IMqttChannelAdapter
{
readonly
AsyncLock
_writerLock
=
new
AsyncLock
();
readonly
bool
?
_isOverWebSocket
;
readonly
AsyncLock
_writerLock
=
new
AsyncLock
();
PipeReader
_input
;
PipeWriter
_output
;
...
...
@@ -31,18 +31,23 @@ namespace MQTTnet.AspNetCore
Connection
=
connection
??
throw
new
ArgumentNullException
(
nameof
(
connection
));
var
feature
=
connection
.
Features
.
Get
<
IHttpContextFeature
>();
if
(
feature
!=
null
&&
feature
.
HttpContext
!=
null
)
if
(
feature
?
.
HttpContext
!=
null
)
{
_isOverWebSocket
=
feature
.
HttpContext
.
WebSockets
.
IsWebSocketRequest
;
}
if
(
Connection
.
Transport
!=
null
)
{
_input
=
Connection
.
Transport
.
Input
;
_output
=
Connection
.
Transport
.
Output
;
}
_input
=
Connection
.
Transport
.
Input
;
_output
=
Connection
.
Transport
.
Output
;
}
public
long
BytesReceived
{
get
;
private
set
;
}
public
long
BytesSent
{
get
;
private
set
;
}
public
X509Certificate2
ClientCertificate
=>
Http
?.
HttpContext
?.
Connection
?.
ClientCertificate
;
public
ConnectionContext
Connection
{
get
;
}
public
string
Endpoint
{
get
...
...
@@ -63,20 +68,12 @@ namespace MQTTnet.AspNetCore
}
}
public
bool
IsSecureConnection
=>
Http
?.
HttpContext
?.
Request
?.
IsHttps
??
false
;
public
X509Certificate2
ClientCertificate
=>
Http
?.
HttpContext
?.
Connection
?.
ClientCertificate
;
public
bool
IsReadingPacket
{
get
;
private
set
;
}
public
ConnectionContext
Connection
{
get
;
}
public
bool
IsSecureConnection
=>
Http
?.
HttpContext
?.
Request
.
IsHttps
??
false
;
public
MqttPacketFormatterAdapter
PacketFormatterAdapter
{
get
;
}
public
long
BytesSent
{
get
;
set
;
}
public
long
BytesReceived
{
get
;
set
;
}
public
bool
IsReadingPacket
{
get
;
private
set
;
}
IHttpContextFeature
Http
=>
Connection
.
Features
.
Get
<
IHttpContextFeature
>();
public
async
Task
ConnectAsync
(
CancellationToken
cancellationToken
)
...
...
@@ -98,6 +95,10 @@ namespace MQTTnet.AspNetCore
return
Task
.
CompletedTask
;
}
public
void
Dispose
()
{
}
public
async
Task
<
MqttPacket
>
ReceivePacketAsync
(
CancellationToken
cancellationToken
)
{
var
input
=
Connection
.
Transport
.
Input
;
...
...
@@ -151,11 +152,11 @@ namespace MQTTnet.AspNetCore
}
}
}
catch
(
Exception
e
)
catch
(
Exception
e
xception
)
{
// completing the channel makes sure that there is no more data read after a protocol error
_input
?.
Complete
(
e
);
_output
?.
Complete
(
e
);
_input
?.
Complete
(
e
xception
);
_output
?.
Complete
(
e
xception
);
throw
;
}
finally
...
...
@@ -180,6 +181,7 @@ namespace MQTTnet.AspNetCore
try
{
var
buffer
=
PacketFormatterAdapter
.
Encode
(
packet
);
if
(
_isOverWebSocket
==
false
)
{
await
_output
.
WriteAsync
(
buffer
.
Packet
,
cancellationToken
).
ConfigureAwait
(
false
);
...
...
@@ -202,9 +204,5 @@ namespace MQTTnet.AspNetCore
}
}
}
public
void
Dispose
()
{
}
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录