@@ -26,7 +26,7 @@ use std::convert::Infallible;
2626use std:: fmt:: Debug ;
2727use std:: time:: Duration ;
2828
29- use anyhow:: { anyhow , bail} ;
29+ use anyhow:: bail;
3030use async_trait:: async_trait;
3131use bincode:: Options ;
3232use futures:: future;
@@ -243,9 +243,9 @@ where
243243#[ derive( Debug ) ]
244244struct Connection < Out , In > {
245245 /// Message sender connected to the send task.
246- msg_tx : mpsc:: Sender < Out > ,
246+ msg_tx : mpsc:: UnboundedSender < Out > ,
247247 /// Message receiver connected to the receive task.
248- msg_rx : mpsc:: Receiver < In > ,
248+ msg_rx : mpsc:: UnboundedReceiver < In > ,
249249 /// Receiver for errors encountered by connection tasks.
250250 error_rx : watch:: Receiver < String > ,
251251
@@ -289,8 +289,8 @@ impl<Out: Message, In: Message> Connection<Out, In> {
289289
290290 handshake ( & mut reader, & mut writer, version, server_fqdn) . await ?;
291291
292- let ( out_tx, out_rx) = mpsc:: channel ( 1024 ) ;
293- let ( in_tx, in_rx) = mpsc:: channel ( 1024 ) ;
292+ let ( out_tx, out_rx) = mpsc:: unbounded_channel ( ) ;
293+ let ( in_tx, in_rx) = mpsc:: unbounded_channel ( ) ;
294294 // Initialize the error channel with a default error to return if none of the tasks
295295 // produced an error.
296296 let ( error_tx, error_rx) = watch:: channel ( "connection closed" . into ( ) ) ;
@@ -314,7 +314,7 @@ impl<Out: Message, In: Message> Connection<Out, In> {
314314
315315 /// Enqueue a message for sending.
316316 async fn send ( & mut self , msg : Out ) -> anyhow:: Result < ( ) > {
317- match self . msg_tx . send ( msg) . await {
317+ match self . msg_tx . send ( msg) {
318318 Ok ( ( ) ) => Ok ( ( ) ) ,
319319 Err ( _) => bail ! ( self . collect_error( ) . await ) ,
320320 }
@@ -347,7 +347,7 @@ impl<Out: Message, In: Message> Connection<Out, In> {
347347 /// Run a connection's send task.
348348 async fn run_send_task < W : AsyncWrite + Unpin > (
349349 mut writer : W ,
350- mut msg_rx : mpsc:: Receiver < Out > ,
350+ mut msg_rx : mpsc:: UnboundedReceiver < Out > ,
351351 error_tx : watch:: Sender < String > ,
352352 mut metrics : impl Metrics < Out , In > ,
353353 ) {
@@ -383,7 +383,7 @@ impl<Out: Message, In: Message> Connection<Out, In> {
383383 /// Run a connection's recv task.
384384 async fn run_recv_task < R : AsyncRead + Unpin > (
385385 mut reader : R ,
386- msg_tx : mpsc:: Sender < In > ,
386+ msg_tx : mpsc:: UnboundedSender < In > ,
387387 error_tx : watch:: Sender < String > ,
388388 mut metrics : impl Metrics < Out , In > ,
389389 ) {
@@ -393,7 +393,7 @@ impl<Out: Message, In: Message> Connection<Out, In> {
393393 trace ! ( ?msg, "ctp: received message" ) ;
394394 metrics. message_received ( & msg) ;
395395
396- if msg_tx. send ( msg) . await . is_err ( ) {
396+ if msg_tx. send ( msg) . is_err ( ) {
397397 break ;
398398 }
399399 }
@@ -407,38 +407,6 @@ impl<Out: Message, In: Message> Connection<Out, In> {
407407 }
408408}
409409
410- /// A connection handler that simply forwards messages over channels.
411- #[ derive( Debug ) ]
412- pub struct ChannelHandler < In , Out > {
413- tx : mpsc:: UnboundedSender < In > ,
414- rx : mpsc:: UnboundedReceiver < Out > ,
415- }
416-
417- impl < In , Out > ChannelHandler < In , Out > {
418- pub fn new ( tx : mpsc:: UnboundedSender < In > , rx : mpsc:: UnboundedReceiver < Out > ) -> Self {
419- Self { tx, rx }
420- }
421- }
422-
423- #[ async_trait]
424- impl < In : Message , Out : Message > GenericClient < In , Out > for ChannelHandler < In , Out > {
425- async fn send ( & mut self , cmd : In ) -> anyhow:: Result < ( ) > {
426- let result = self . tx . send ( cmd) ;
427- result. map_err ( |_| anyhow ! ( "client channel disconnected" ) )
428- }
429-
430- /// # Cancel safety
431- ///
432- /// This method is cancel safe.
433- async fn recv ( & mut self ) -> anyhow:: Result < Option < Out > > {
434- // `mpsc::UnboundedReceiver::recv` is cancel safe.
435- match self . rx . recv ( ) . await {
436- Some ( resp) => Ok ( Some ( resp) ) ,
437- None => bail ! ( "client channel disconnected" ) ,
438- }
439- }
440- }
441-
442410/// Perform the CTP handshake.
443411///
444412/// To perform the handshake, each endpoint sends the protocol magic number, followed by a
0 commit comments