1
- use crate :: errors_internal:: { Error , InternalStreamError } ;
1
+ use crate :: errors_internal:: { Error , InternalChannelError , InternalStreamError } ;
2
2
use crate :: protobufs;
3
3
use crate :: types:: EncodedToRadioPacketWithHeader ;
4
4
use log:: { debug, error, trace} ;
@@ -16,7 +16,7 @@ pub fn spawn_read_handler<R>(
16
16
cancellation_token : CancellationToken ,
17
17
read_stream : R ,
18
18
read_output_tx : UnboundedSender < IncomingStreamData > ,
19
- ) -> JoinHandle < ( ) >
19
+ ) -> JoinHandle < Result < ( ) , Error > >
20
20
where
21
21
R : AsyncReadExt + Send + Unpin + ' static ,
22
22
{
27
27
tokio:: select! {
28
28
_ = cancellation_token. cancelled( ) => {
29
29
debug!( "Read handler cancelled" ) ;
30
+ Ok ( ( ) )
30
31
}
31
32
e = handle => {
32
33
error!( "Read handler unexpectedly terminated: {:#?}" , e) ;
34
+ e
33
35
}
34
36
}
35
37
} )
@@ -82,7 +84,7 @@ pub fn spawn_write_handler<W>(
82
84
cancellation_token : CancellationToken ,
83
85
write_stream : W ,
84
86
write_input_rx : tokio:: sync:: mpsc:: UnboundedReceiver < EncodedToRadioPacketWithHeader > ,
85
- ) -> JoinHandle < ( ) >
87
+ ) -> JoinHandle < Result < ( ) , Error > >
86
88
where
87
89
W : AsyncWriteExt + Send + Unpin + ' static ,
88
90
{
@@ -91,10 +93,14 @@ where
91
93
spawn ( async move {
92
94
tokio:: select! {
93
95
_ = cancellation_token. cancelled( ) => {
94
- debug!( "Write handler cancelled" ) ;
96
+ debug!( "Write handler cancelled" ) ;
97
+ Ok ( ( ) )
95
98
}
96
- _ = handle => {
97
- error!( "Write handler unexpectedly terminated" ) ;
99
+ write_result = handle => {
100
+ if let Err ( e) = & write_result {
101
+ error!( "Write handler unexpectedly terminated {e:?}" ) ;
102
+ }
103
+ write_result
98
104
}
99
105
}
100
106
} )
@@ -132,16 +138,18 @@ pub fn spawn_processing_handler(
132
138
cancellation_token : CancellationToken ,
133
139
read_output_rx : UnboundedReceiver < IncomingStreamData > ,
134
140
decoded_packet_tx : UnboundedSender < protobufs:: FromRadio > ,
135
- ) -> JoinHandle < ( ) > {
141
+ ) -> JoinHandle < Result < ( ) , Error > > {
136
142
let handle = start_processing_handler ( read_output_rx, decoded_packet_tx) ;
137
143
138
144
spawn ( async move {
139
145
tokio:: select! {
140
146
_ = cancellation_token. cancelled( ) => {
141
- debug!( "Message processing handler cancelled" ) ;
147
+ debug!( "Message processing handler cancelled" ) ;
148
+ Ok ( ( ) )
142
149
}
143
150
_ = handle => {
144
- error!( "Message processing handler unexpectedly terminated" ) ;
151
+ error!( "Message processing handler unexpectedly terminated" ) ;
152
+ Err ( Error :: InternalChannelError ( InternalChannelError :: ChannelClosedEarly { } ) )
145
153
}
146
154
}
147
155
} )
@@ -150,7 +158,7 @@ pub fn spawn_processing_handler(
150
158
async fn start_processing_handler (
151
159
mut read_output_rx : tokio:: sync:: mpsc:: UnboundedReceiver < IncomingStreamData > ,
152
160
decoded_packet_tx : UnboundedSender < protobufs:: FromRadio > ,
153
- ) -> Result < ( ) , Error > {
161
+ ) {
154
162
trace ! ( "Started message processing handler" ) ;
155
163
156
164
let mut buffer = StreamBuffer :: new ( decoded_packet_tx) ;
@@ -161,6 +169,4 @@ async fn start_processing_handler(
161
169
}
162
170
163
171
trace ! ( "Processing read_output_rx channel closed" ) ;
164
-
165
- Ok ( ( ) )
166
172
}
0 commit comments