@@ -332,6 +332,7 @@ where
332
332
}
333
333
334
334
#[ derive( Debug ) ]
335
+ #[ cfg_attr( feature = "defmt" , derive( defmt:: Format ) ) ]
335
336
pub enum HandlerError < T , E > {
336
337
Io ( T ) ,
337
338
Connection ( Error < T > ) ,
@@ -466,22 +467,26 @@ pub async fn handle_connection<H, T, const N: usize>(
466
467
T : Read + Write + Readable + TcpSplit + TcpShutdown ,
467
468
{
468
469
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
+ ) ;
470
474
471
475
if let Some ( keepalive_timeout_ms) = keepalive_timeout_ms {
472
476
let wait_data = with_timeout ( keepalive_timeout_ms, io. readable ( ) ) . await ;
473
477
match wait_data {
474
478
Err ( WithTimeoutError :: Timeout ) => {
475
479
info ! (
476
480
"Handler task {}: Closing connection due to inactivity" ,
477
- task_id
481
+ display2format! ( task_id)
478
482
) ;
479
483
break true ;
480
484
}
481
485
Err ( e) => {
482
486
warn ! (
483
487
"Handler task {}: Error when handling request: {:?}" ,
484
- task_id, e
488
+ display2format!( task_id) ,
489
+ debug2format!( e)
485
490
) ;
486
491
break true ;
487
492
}
@@ -493,25 +498,32 @@ pub async fn handle_connection<H, T, const N: usize>(
493
498
494
499
match result {
495
500
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
+ ) ;
497
505
break false ;
498
506
}
499
507
Err ( e) => {
500
508
warn ! (
501
509
"Handler task {}: Error when handling request: {:?}" ,
502
- task_id, e
510
+ display2format!( task_id) ,
511
+ debug2format!( e)
503
512
) ;
504
513
break true ;
505
514
}
506
515
Ok ( needs_close) => {
507
516
if needs_close {
508
517
debug ! (
509
518
"Handler task {}: Request complete; closing connection" ,
510
- task_id
519
+ display2format! ( task_id)
511
520
) ;
512
521
break true ;
513
522
} else {
514
- debug ! ( "Handler task {}: Request complete" , task_id) ;
523
+ debug ! (
524
+ "Handler task {}: Request complete" ,
525
+ display2format!( task_id)
526
+ ) ;
515
527
}
516
528
}
517
529
}
@@ -521,7 +533,8 @@ pub async fn handle_connection<H, T, const N: usize>(
521
533
if let Err ( e) = io. close ( Close :: Both ) . await {
522
534
warn ! (
523
535
"Handler task {}: Error when closing the socket: {:?}" ,
524
- task_id, e
536
+ display2format!( task_id) ,
537
+ debug2format!( e)
525
538
) ;
526
539
}
527
540
} else {
@@ -557,6 +570,20 @@ where
557
570
}
558
571
}
559
572
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
+
560
587
impl < C , E > embedded_io_async:: Error for HandleRequestError < C , E >
561
588
where
562
589
C : Debug + embedded_io_async:: Error ,
@@ -690,15 +717,21 @@ impl<const P: usize, const B: usize, const N: usize> Server<P, B, N> {
690
717
unwrap ! ( tasks
691
718
. push( async move {
692
719
loop {
693
- debug!( "Handler task {}: Waiting for connection" , task_id) ;
720
+ debug!(
721
+ "Handler task {}: Waiting for connection" ,
722
+ display2format!( task_id)
723
+ ) ;
694
724
695
725
let io = {
696
726
let _guard = mutex. lock( ) . await ;
697
727
698
728
acceptor. accept( ) . await . map_err( Error :: Io ) ?. 1
699
729
} ;
700
730
701
- debug!( "Handler task {}: Got connection request" , task_id) ;
731
+ debug!(
732
+ "Handler task {}: Got connection request" ,
733
+ display2format!( task_id)
734
+ ) ;
702
735
703
736
handle_connection:: <_, _, N >(
704
737
io,
@@ -715,7 +748,10 @@ impl<const P: usize, const B: usize, const N: usize> Server<P, B, N> {
715
748
716
749
let ( result, _) = embassy_futures:: select:: select_slice ( & mut tasks) . await ;
717
750
718
- warn ! ( "Server processing loop quit abruptly: {:?}" , result) ;
751
+ warn ! (
752
+ "Server processing loop quit abruptly: {:?}" ,
753
+ debug2format!( result)
754
+ ) ;
719
755
720
756
result
721
757
}
0 commit comments