@@ -15,7 +15,7 @@ use crate::{
15
15
as_bytes, as_bytes_mut,
16
16
frame:: { can_frame_default, canfd_frame_default, AsPtr } ,
17
17
id:: CAN_ERR_MASK ,
18
- CanAnyFrame , CanFdFrame , CanFrame , CanRawFrame , IoError , IoErrorKind , IoResult ,
18
+ CanAnyFrame , CanFdFrame , CanFrame , CanRawFrame , Error , IoError , IoErrorKind , IoResult , Result ,
19
19
} ;
20
20
pub use embedded_can:: {
21
21
self , blocking:: Can as BlockingCan , nb:: Can as NonBlockingCan , ExtendedId ,
@@ -25,7 +25,7 @@ use libc::{canid_t, socklen_t, AF_CAN, EINPROGRESS};
25
25
use socket2:: SockAddr ;
26
26
use std:: {
27
27
fmt,
28
- io:: { ErrorKind , Read , Write } ,
28
+ io:: { Read , Write } ,
29
29
mem:: { size_of, size_of_val} ,
30
30
os:: {
31
31
raw:: { c_int, c_void} ,
@@ -546,14 +546,14 @@ impl Socket for CanSocket {
546
546
547
547
impl embedded_can:: blocking:: Can for CanSocket {
548
548
type Frame =CanFrame ;
549
- type Error =crate :: Error ;
549
+ type Error =Error ;
550
550
551
551
/// Blocking call to receive the next frame from the bus.
552
552
///
553
553
/// This block and wait for the next frame to be received from the bus.
554
554
/// If an error frame is received, it will be converted to a `CanError`
555
555
/// and returned as an error.
556
- fn receive ( & mut self ) ->crate :: Result < Self :: Frame > {
556
+ fn receive ( & mut self ) ->Result < Self :: Frame > {
557
557
match self . read_frame ( ) {
558
558
Ok ( CanFrame :: Error ( frame) ) =>Err ( frame. into_error ( ) . into ( ) ) ,
559
559
Ok ( frame) =>Ok ( frame) ,
@@ -562,14 +562,17 @@ impl embedded_can::blocking::Can for CanSocket {
562
562
}
563
563
564
564
/// Blocking transmit of a frame to the bus.
565
- fn transmit ( & mut self , frame : & Self :: Frame ) ->crate :: Result < ( ) > {
566
- self . write_frame_insist ( frame) . map_err ( |err| err. into ( ) )
565
+ fn transmit ( & mut self , frame : & Self :: Frame ) ->Result < ( ) > {
566
+ self . write_frame_insist ( frame) ?;
567
+ Ok ( ( ) )
567
568
}
568
569
}
569
570
571
+ impl SocketOptions for CanSocket { }
572
+
570
573
impl embedded_can:: nb:: Can for CanSocket {
571
574
type Frame =CanFrame ;
572
- type Error =crate :: Error ;
575
+ type Error =Error ;
573
576
574
577
/// Non-blocking call to receive the next frame from the bus.
575
578
///
@@ -578,25 +581,23 @@ impl embedded_can::nb::Can for CanSocket {
578
581
/// If no frame is available, it returns a `WouldBlck` error.
579
582
fn receive ( & mut self ) -> nb:: Result < Self :: Frame , Self :: Error > {
580
583
match self . read_frame ( ) {
581
- Ok ( CanFrame :: Error ( frame) ) =>Err ( Self :: Error :: from ( frame. into_error ( ) ) . into ( ) ) ,
584
+ Ok ( CanFrame :: Error ( frame) ) =>Err ( Error :: from ( frame. into_error ( ) ) . into ( ) ) ,
582
585
Ok ( frame) =>Ok ( frame) ,
583
- Err ( err) if err. kind ( ) == ErrorKind :: WouldBlock =>Err ( nb:: Error :: WouldBlock ) ,
584
- Err ( err) =>Err ( crate :: Error :: from ( err) . into ( ) ) ,
586
+ Err ( err) if err. should_retry ( ) =>Err ( nb:: Error :: WouldBlock ) ,
587
+ Err ( err) =>Err ( Error :: from ( err) . into ( ) ) ,
585
588
}
586
589
}
587
590
588
591
/// Non-blocking transmit of a frame to the bus.
589
592
fn transmit ( & mut self , frame : & Self :: Frame ) -> nb:: Result < Option < Self :: Frame > , Self :: Error > {
590
593
match self . write_frame ( frame) {
591
594
Ok ( _) =>Ok ( None ) ,
592
- Err ( err) if err. kind ( ) == ErrorKind :: WouldBlock =>Err ( nb:: Error :: WouldBlock ) ,
593
- Err ( err) =>Err ( Self :: Error :: from ( err) . into ( ) ) ,
595
+ Err ( err) if err. should_retry ( ) =>Err ( nb:: Error :: WouldBlock ) ,
596
+ Err ( err) =>Err ( Error :: from ( err) . into ( ) ) ,
594
597
}
595
598
}
596
599
}
597
600
598
- impl SocketOptions for CanSocket { }
599
-
600
601
// Has no effect: #[deprecated(since = "3.1", note = "Use AsFd::as_fd() instead.")]
601
602
impl AsRawFd for CanSocket {
602
603
fn as_raw_fd ( & self ) ->RawFd {
@@ -743,14 +744,14 @@ impl SocketOptions for CanFdSocket {}
743
744
744
745
impl embedded_can:: blocking:: Can for CanFdSocket {
745
746
type Frame =CanAnyFrame ;
746
- type Error =crate :: Error ;
747
+ type Error =Error ;
747
748
748
749
/// Blocking call to receive the next frame from the bus.
749
750
///
750
751
/// This block and wait for the next frame to be received from the bus.
751
752
/// If an error frame is received, it will be converted to a `CanError`
752
753
/// and returned as an error.
753
- fn receive ( & mut self ) ->crate :: Result < Self :: Frame > {
754
+ fn receive ( & mut self ) ->Result < Self :: Frame > {
754
755
match self . read_frame ( ) {
755
756
Ok ( CanAnyFrame :: Error ( frame) ) =>Err ( frame. into_error ( ) . into ( ) ) ,
756
757
Ok ( frame) =>Ok ( frame) ,
@@ -759,14 +760,15 @@ impl embedded_can::blocking::Can for CanFdSocket {
759
760
}
760
761
761
762
/// Blocking transmit of a frame to the bus.
762
- fn transmit ( & mut self , frame : & Self :: Frame ) ->crate :: Result < ( ) > {
763
- self . write_frame_insist ( frame) . map_err ( |err| err. into ( ) )
763
+ fn transmit ( & mut self , frame : & Self :: Frame ) ->Result < ( ) > {
764
+ self . write_frame_insist ( frame) ?;
765
+ Ok ( ( ) )
764
766
}
765
767
}
766
768
767
769
impl embedded_can:: nb:: Can for CanFdSocket {
768
770
type Frame =CanAnyFrame ;
769
- type Error =crate :: Error ;
771
+ type Error =Error ;
770
772
771
773
/// Non-blocking call to receive the next frame from the bus.
772
774
///
@@ -775,19 +777,19 @@ impl embedded_can::nb::Can for CanFdSocket {
775
777
/// If no frame is available, it returns a `WouldBlck` error.
776
778
fn receive ( & mut self ) -> nb:: Result < Self :: Frame , Self :: Error > {
777
779
match self . read_frame ( ) {
778
- Ok ( CanAnyFrame :: Error ( frame) ) =>Err ( Self :: Error :: from ( frame. into_error ( ) ) . into ( ) ) ,
780
+ Ok ( CanAnyFrame :: Error ( frame) ) =>Err ( Error :: from ( frame. into_error ( ) ) . into ( ) ) ,
779
781
Ok ( frame) =>Ok ( frame) ,
780
- Err ( err) if err. kind ( ) == ErrorKind :: WouldBlock =>Err ( nb:: Error :: WouldBlock ) ,
781
- Err ( err) =>Err ( crate :: Error :: from ( err) . into ( ) ) ,
782
+ Err ( err) if err. should_retry ( ) =>Err ( nb:: Error :: WouldBlock ) ,
783
+ Err ( err) =>Err ( Error :: from ( err) . into ( ) ) ,
782
784
}
783
785
}
784
786
785
787
/// Non-blocking transmit of a frame to the bus.
786
788
fn transmit ( & mut self , frame : & Self :: Frame ) -> nb:: Result < Option < Self :: Frame > , Self :: Error > {
787
789
match self . write_frame ( frame) {
788
790
Ok ( _) =>Ok ( None ) ,
789
- Err ( err) if err. kind ( ) == ErrorKind :: WouldBlock =>Err ( nb:: Error :: WouldBlock ) ,
790
- Err ( err) =>Err ( Self :: Error :: from ( err) . into ( ) ) ,
791
+ Err ( err) if err. should_retry ( ) =>Err ( nb:: Error :: WouldBlock ) ,
792
+ Err ( err) =>Err ( Error :: from ( err) . into ( ) ) ,
791
793
}
792
794
}
793
795
}