@@ -55,7 +55,7 @@ private Task<bool> TrafficOutflowProcessorAsync() => Task.Run(async () =>
55
55
if ( elapsed > TimeSpan . FromSeconds ( keepAlivePeriod ) )
56
56
{
57
57
// Send PingReq
58
- var writeResult = await this . writer . WriteAsync ( PingReqPacket . Encode ( ) ) . ConfigureAwait ( false ) ;
58
+ var writeResult = await this . WriteAsync ( PingReqPacket . Encode ( ) ) . ConfigureAwait ( false ) ;
59
59
this . OnPingReqSentEventLauncher ( new PingReqPacket ( ) ) ;
60
60
stopWatch . Restart ( ) ;
61
61
}
@@ -82,22 +82,22 @@ private Task<bool> TrafficOutflowProcessorAsync() => Task.Run(async () =>
82
82
// FIXME: Only one connect, subscribe or unsubscribe packet can be sent at a time.
83
83
case ConnectPacket connectPacket :
84
84
Trace . WriteLine ( "--> ConnectPacket" ) ;
85
- writeResult = await this . writer . WriteAsync ( connectPacket . Encode ( ) ) . ConfigureAwait ( false ) ;
85
+ writeResult = await this . WriteAsync ( connectPacket . Encode ( ) ) . ConfigureAwait ( false ) ;
86
86
this . OnConnectSentEventLauncher ( connectPacket ) ;
87
87
break ;
88
88
case DisconnectPacket disconnectPacket :
89
89
Trace . WriteLine ( "--> DisconnectPacket" ) ;
90
- writeResult = await this . writer . WriteAsync ( DisconnectPacket . Encode ( ) ) . ConfigureAwait ( false ) ;
90
+ writeResult = await this . WriteAsync ( disconnectPacket . Encode ( ) ) . ConfigureAwait ( false ) ;
91
91
this . OnDisconnectSentEventLauncher ( disconnectPacket ) ;
92
92
break ;
93
93
case SubscribePacket subscribePacket :
94
94
Trace . WriteLine ( "--> SubscribePacket" ) ;
95
- writeResult = await this . writer . WriteAsync ( subscribePacket . Encode ( ) ) . ConfigureAwait ( false ) ;
95
+ writeResult = await this . WriteAsync ( subscribePacket . Encode ( ) ) . ConfigureAwait ( false ) ;
96
96
this . OnSubscribeSentEventLauncher ( subscribePacket ) ;
97
97
break ;
98
98
case UnsubscribePacket unsubscribePacket :
99
99
Trace . WriteLine ( "--> UnsubscribePacket" ) ;
100
- writeResult = await this . writer . WriteAsync ( unsubscribePacket . Encode ( ) ) . ConfigureAwait ( false ) ;
100
+ writeResult = await this . WriteAsync ( unsubscribePacket . Encode ( ) ) . ConfigureAwait ( false ) ;
101
101
this . OnUnsubscribeSentEventLauncher ( unsubscribePacket ) ;
102
102
break ;
103
103
case PublishPacket publishPacket :
@@ -112,38 +112,39 @@ private Task<bool> TrafficOutflowProcessorAsync() => Task.Run(async () =>
112
112
}
113
113
}
114
114
115
- writeResult = await this . writer . WriteAsync ( publishPacket . Encode ( ) ) . ConfigureAwait ( false ) ;
115
+ writeResult = await this . WriteAsync ( publishPacket . Encode ( ) ) . ConfigureAwait ( false ) ;
116
116
117
117
this . OnPublishSentEventLauncher ( publishPacket ) ;
118
118
break ;
119
119
case PubAckPacket pubAckPacket :
120
120
// This is in response to a received Publish packet. Communication chain management
121
121
// was done in the receiver code. Just send the response.
122
122
Trace . WriteLine ( "--> PubAckPacket" ) ;
123
- writeResult = await this . writer . WriteAsync ( pubAckPacket . Encode ( ) ) . ConfigureAwait ( false ) ;
123
+ writeResult = await this . WriteAsync ( pubAckPacket . Encode ( ) ) . ConfigureAwait ( false ) ;
124
124
this . OnPubAckSentEventLauncher ( pubAckPacket ) ;
125
125
break ;
126
126
case PubRecPacket pubRecPacket :
127
127
// This is in response to a received Publish packet. Communication chain management
128
128
// was done in the receiver code. Just send the response.
129
129
Trace . WriteLine ( "--> PubRecPacket" ) ;
130
- writeResult = await this . writer . WriteAsync ( pubRecPacket . Encode ( ) ) . ConfigureAwait ( false ) ;
130
+ writeResult = await this . WriteAsync ( pubRecPacket . Encode ( ) ) . ConfigureAwait ( false ) ;
131
131
this . OnPubRecSentEventLauncher ( pubRecPacket ) ;
132
132
break ;
133
133
case PubRelPacket pubRelPacket :
134
134
// This is in response to a received PubRec packet. Communication chain management
135
135
// was done in the receiver code. Just send the response.
136
136
Trace . WriteLine ( "--> PubRelPacket" ) ;
137
- writeResult = await this . writer . WriteAsync ( pubRelPacket . Encode ( ) ) . ConfigureAwait ( false ) ;
137
+ writeResult = await this . WriteAsync ( pubRelPacket . Encode ( ) ) . ConfigureAwait ( false ) ;
138
138
this . OnPubRelSentEventLauncher ( pubRelPacket ) ;
139
139
break ;
140
140
case PubCompPacket pubCompPacket :
141
141
// This is in response to a received PubRel packet. Communication chain management
142
142
// was done in the receiver code. Just send the response.
143
143
Trace . WriteLine ( "--> PubCompPacket" ) ;
144
- writeResult = await this . writer . WriteAsync ( pubCompPacket . Encode ( ) ) . ConfigureAwait ( false ) ;
144
+ writeResult = await this . WriteAsync ( pubCompPacket . Encode ( ) ) . ConfigureAwait ( false ) ;
145
145
this . OnPubCompSentEventLauncher ( pubCompPacket ) ;
146
146
break ;
147
+
147
148
/* case AuthPacket authPacket:
148
149
/* writeResult = await this.writer.WriteAsync(authPacket.Encode()).ConfigureAwait(false);
149
150
/* this.OnAuthSentEventLauncher(authPacket);
@@ -174,7 +175,7 @@ private Task<bool> TrafficInflowProcessorAsync() => Task.Run(async () =>
174
175
175
176
while ( this . connectState is ConnectState . Connecting or ConnectState . Connected )
176
177
{
177
- readResult = await this . reader . ReadAsync ( ) . ConfigureAwait ( false ) ;
178
+ readResult = await this . ReadAsync ( ) . ConfigureAwait ( false ) ;
178
179
179
180
if ( readResult . IsCanceled )
180
181
{
@@ -350,4 +351,22 @@ private Task<bool> TrafficInflowProcessorAsync() => Task.Run(async () =>
350
351
351
352
return true ;
352
353
} ) ;
354
+
355
+ internal ValueTask < FlushResult > WriteAsync ( ReadOnlyMemory < byte > source , CancellationToken cancellationToken = default )
356
+ {
357
+ if ( this . writer is null )
358
+ {
359
+ throw new HiveMQttClientException ( "Writer is null" ) ;
360
+ }
361
+ return this . writer . WriteAsync ( source , cancellationToken ) ;
362
+ }
363
+
364
+ internal ValueTask < ReadResult > ReadAsync ( CancellationToken cancellationToken = default )
365
+ {
366
+ if ( this . reader is null )
367
+ {
368
+ throw new HiveMQttClientException ( "Reader is null" ) ;
369
+ }
370
+ return this . reader . ReadAsync ( cancellationToken ) ;
371
+ }
353
372
}
0 commit comments