@@ -332,6 +332,7 @@ where
332332}
333333
334334#[ derive( Debug ) ]
335+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
335336pub enum HandlerError < T , E > {
336337 Io ( T ) ,
337338 Connection ( Error < T > ) ,
@@ -466,22 +467,26 @@ pub async fn handle_connection<H, T, const N: usize>(
466467 T : Read + Write + Readable + TcpSplit + TcpShutdown ,
467468{
468469 let close = loop {
469- debug ! ( "Handler task {}: Waiting for a new request" , task_id) ;
470+ debug ! (
471+ "Handler task {}: Waiting for a new request" ,
472+ display2format!( task_id)
473+ ) ;
470474
471475 if let Some ( keepalive_timeout_ms) = keepalive_timeout_ms {
472476 let wait_data = with_timeout ( keepalive_timeout_ms, io. readable ( ) ) . await ;
473477 match wait_data {
474478 Err ( WithTimeoutError :: Timeout ) => {
475479 info ! (
476480 "Handler task {}: Closing connection due to inactivity" ,
477- task_id
481+ display2format! ( task_id)
478482 ) ;
479483 break true ;
480484 }
481485 Err ( e) => {
482486 warn ! (
483487 "Handler task {}: Error when handling request: {:?}" ,
484- task_id, e
488+ display2format!( task_id) ,
489+ debug2format!( e)
485490 ) ;
486491 break true ;
487492 }
@@ -493,25 +498,32 @@ pub async fn handle_connection<H, T, const N: usize>(
493498
494499 match result {
495500 Err ( HandlerError :: Connection ( Error :: ConnectionClosed ) ) => {
496- debug ! ( "Handler task {}: Connection closed" , task_id) ;
501+ debug ! (
502+ "Handler task {}: Connection closed" ,
503+ display2format!( task_id)
504+ ) ;
497505 break false ;
498506 }
499507 Err ( e) => {
500508 warn ! (
501509 "Handler task {}: Error when handling request: {:?}" ,
502- task_id, e
510+ display2format!( task_id) ,
511+ debug2format!( e)
503512 ) ;
504513 break true ;
505514 }
506515 Ok ( needs_close) => {
507516 if needs_close {
508517 debug ! (
509518 "Handler task {}: Request complete; closing connection" ,
510- task_id
519+ display2format! ( task_id)
511520 ) ;
512521 break true ;
513522 } else {
514- debug ! ( "Handler task {}: Request complete" , task_id) ;
523+ debug ! (
524+ "Handler task {}: Request complete" ,
525+ display2format!( task_id)
526+ ) ;
515527 }
516528 }
517529 }
@@ -521,7 +533,8 @@ pub async fn handle_connection<H, T, const N: usize>(
521533 if let Err ( e) = io. close ( Close :: Both ) . await {
522534 warn ! (
523535 "Handler task {}: Error when closing the socket: {:?}" ,
524- task_id, e
536+ display2format!( task_id) ,
537+ debug2format!( e)
525538 ) ;
526539 }
527540 } else {
@@ -557,6 +570,20 @@ where
557570 }
558571}
559572
573+ #[ cfg( feature = "defmt" ) ]
574+ impl < C , E > defmt:: Format for HandleRequestError < C , E >
575+ where
576+ C : defmt:: Format ,
577+ E : defmt:: Format ,
578+ {
579+ fn format ( & self , f : defmt:: Formatter < ' _ > ) {
580+ match self {
581+ Self :: Connection ( e) => defmt:: write!( f, "Connection error: {}" , e) ,
582+ Self :: Handler ( e) => defmt:: write!( f, "Handler error: {}" , e) ,
583+ }
584+ }
585+ }
586+
560587impl < C , E > embedded_io_async:: Error for HandleRequestError < C , E >
561588where
562589 C : Debug + embedded_io_async:: Error ,
@@ -690,15 +717,21 @@ impl<const P: usize, const B: usize, const N: usize> Server<P, B, N> {
690717 unwrap ! ( tasks
691718 . push( async move {
692719 loop {
693- debug!( "Handler task {}: Waiting for connection" , task_id) ;
720+ debug!(
721+ "Handler task {}: Waiting for connection" ,
722+ display2format!( task_id)
723+ ) ;
694724
695725 let io = {
696726 let _guard = mutex. lock( ) . await ;
697727
698728 acceptor. accept( ) . await . map_err( Error :: Io ) ?. 1
699729 } ;
700730
701- debug!( "Handler task {}: Got connection request" , task_id) ;
731+ debug!(
732+ "Handler task {}: Got connection request" ,
733+ display2format!( task_id)
734+ ) ;
702735
703736 handle_connection:: <_, _, N >(
704737 io,
@@ -715,7 +748,10 @@ impl<const P: usize, const B: usize, const N: usize> Server<P, B, N> {
715748
716749 let ( result, _) = embassy_futures:: select:: select_slice ( & mut tasks) . await ;
717750
718- warn ! ( "Server processing loop quit abruptly: {:?}" , result) ;
751+ warn ! (
752+ "Server processing loop quit abruptly: {:?}" ,
753+ debug2format!( result)
754+ ) ;
719755
720756 result
721757 }
0 commit comments