File tree Expand file tree Collapse file tree 5 files changed +13
-4
lines changed Expand file tree Collapse file tree 5 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
11
11
12
12
* ` size() ` method on ` Packet ` calculates size once serialized.
13
13
* ` read() ` and ` write() ` methods on ` Packet ` .
14
+ * ` ConnectionAborted ` variant on ` StateError ` type to denote abrupt end to a connection
14
15
15
16
### Changed
16
17
Original file line number Diff line number Diff line change @@ -38,8 +38,9 @@ impl Network {
38
38
pub async fn read ( & mut self ) -> Result < Incoming , StateError > {
39
39
match self . framed . next ( ) . await {
40
40
Some ( Ok ( packet) ) => Ok ( packet) ,
41
- Some ( Err ( mqttbytes:: Error :: InsufficientBytes ( _) ) ) | None => unreachable ! ( ) ,
41
+ Some ( Err ( mqttbytes:: Error :: InsufficientBytes ( _) ) ) => unreachable ! ( ) ,
42
42
Some ( Err ( e) ) => Err ( StateError :: Deserialization ( e) ) ,
43
+ None => Err ( StateError :: ConnectionAborted ) ,
43
44
}
44
45
}
45
46
@@ -61,8 +62,9 @@ impl Network {
61
62
break ;
62
63
}
63
64
}
64
- Some ( Err ( mqttbytes:: Error :: InsufficientBytes ( _) ) ) | None => unreachable ! ( ) ,
65
+ Some ( Err ( mqttbytes:: Error :: InsufficientBytes ( _) ) ) => unreachable ! ( ) ,
65
66
Some ( Err ( e) ) => return Err ( StateError :: Deserialization ( e) ) ,
67
+ None => return Err ( StateError :: ConnectionAborted ) ,
66
68
}
67
69
// do not wait for subsequent reads
68
70
match self . framed . next ( ) . now_or_never ( ) {
Original file line number Diff line number Diff line change @@ -29,6 +29,8 @@ pub enum StateError {
29
29
EmptySubscription ,
30
30
#[ error( "Mqtt serialization/deserialization error: {0}" ) ]
31
31
Deserialization ( #[ from] mqttbytes:: Error ) ,
32
+ #[ error( "Connection closed by peer abruptly" ) ]
33
+ ConnectionAborted ,
32
34
}
33
35
34
36
/// State of the mqtt connection.
Original file line number Diff line number Diff line change @@ -40,8 +40,9 @@ impl Network {
40
40
pub async fn read ( & mut self ) -> Result < Incoming , StateError > {
41
41
match self . framed . next ( ) . await {
42
42
Some ( Ok ( packet) ) => Ok ( packet) ,
43
- Some ( Err ( mqttbytes:: Error :: InsufficientBytes ( _) ) ) | None => unreachable ! ( ) ,
43
+ Some ( Err ( mqttbytes:: Error :: InsufficientBytes ( _) ) ) => unreachable ! ( ) ,
44
44
Some ( Err ( e) ) => Err ( StateError :: Deserialization ( e) ) ,
45
+ None => Err ( StateError :: ConnectionAborted ) ,
45
46
}
46
47
}
47
48
@@ -63,8 +64,9 @@ impl Network {
63
64
break ;
64
65
}
65
66
}
66
- Some ( Err ( mqttbytes:: Error :: InsufficientBytes ( _) ) ) | None => unreachable ! ( ) ,
67
+ Some ( Err ( mqttbytes:: Error :: InsufficientBytes ( _) ) ) => unreachable ! ( ) ,
67
68
Some ( Err ( e) ) => return Err ( StateError :: Deserialization ( e) ) ,
69
+ None => return Err ( StateError :: ConnectionAborted ) ,
68
70
}
69
71
// do not wait for subsequent reads
70
72
match self . framed . next ( ) . now_or_never ( ) {
Original file line number Diff line number Diff line change @@ -64,6 +64,8 @@ pub enum StateError {
64
64
PubCompFail { reason : PubCompReason } ,
65
65
#[ error( "Connection failed with reason '{reason:?}' " ) ]
66
66
ConnFail { reason : ConnectReturnCode } ,
67
+ #[ error( "Connection closed by peer abruptly" ) ]
68
+ ConnectionAborted
67
69
}
68
70
69
71
impl From < mqttbytes:: Error > for StateError {
You can’t perform that action at this time.
0 commit comments