Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbed64af

Browse files
committed
Minor cleanup of sockets code
1 parent403e004 commitbed64af

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

‎src/socket.rs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
as_bytes, as_bytes_mut,
1616
frame::{can_frame_default, canfd_frame_default,AsPtr},
1717
id::CAN_ERR_MASK,
18-
CanAnyFrame,CanFdFrame,CanFrame,CanRawFrame,IoError,IoErrorKind,IoResult,
18+
CanAnyFrame,CanFdFrame,CanFrame,CanRawFrame,Error,IoError,IoErrorKind,IoResult,Result,
1919
};
2020
pubuse embedded_can::{
2121
self, blocking::CanasBlockingCan, nb::CanasNonBlockingCan,ExtendedId,
@@ -25,7 +25,7 @@ use libc::{canid_t, socklen_t, AF_CAN, EINPROGRESS};
2525
use socket2::SockAddr;
2626
use std::{
2727
fmt,
28-
io::{ErrorKind,Read,Write},
28+
io::{Read,Write},
2929
mem::{size_of, size_of_val},
3030
os::{
3131
raw::{c_int, c_void},
@@ -546,14 +546,14 @@ impl Socket for CanSocket {
546546

547547
impl embedded_can::blocking::CanforCanSocket{
548548
typeFrame =CanFrame;
549-
typeError =crate::Error;
549+
typeError =Error;
550550

551551
/// Blocking call to receive the next frame from the bus.
552552
///
553553
/// This block and wait for the next frame to be received from the bus.
554554
/// If an error frame is received, it will be converted to a `CanError`
555555
/// and returned as an error.
556-
fnreceive(&mutself) ->crate::Result<Self::Frame>{
556+
fnreceive(&mutself) ->Result<Self::Frame>{
557557
matchself.read_frame(){
558558
Ok(CanFrame::Error(frame)) =>Err(frame.into_error().into()),
559559
Ok(frame) =>Ok(frame),
@@ -562,14 +562,17 @@ impl embedded_can::blocking::Can for CanSocket {
562562
}
563563

564564
/// Blocking transmit of a frame to the bus.
565-
fntransmit(&mutself,frame:&Self::Frame) ->crate::Result<()>{
566-
self.write_frame_insist(frame).map_err(|err| err.into())
565+
fntransmit(&mutself,frame:&Self::Frame) ->Result<()>{
566+
self.write_frame_insist(frame)?;
567+
Ok(())
567568
}
568569
}
569570

571+
implSocketOptionsforCanSocket{}
572+
570573
impl embedded_can::nb::CanforCanSocket{
571574
typeFrame =CanFrame;
572-
typeError =crate::Error;
575+
typeError =Error;
573576

574577
/// Non-blocking call to receive the next frame from the bus.
575578
///
@@ -578,25 +581,23 @@ impl embedded_can::nb::Can for CanSocket {
578581
/// If no frame is available, it returns a `WouldBlck` error.
579582
fnreceive(&mutself) -> nb::Result<Self::Frame,Self::Error>{
580583
matchself.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()),
582585
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()),
585588
}
586589
}
587590

588591
/// Non-blocking transmit of a frame to the bus.
589592
fntransmit(&mutself,frame:&Self::Frame) -> nb::Result<Option<Self::Frame>,Self::Error>{
590593
matchself.write_frame(frame){
591594
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()),
594597
}
595598
}
596599
}
597600

598-
implSocketOptionsforCanSocket{}
599-
600601
// Has no effect: #[deprecated(since = "3.1", note = "Use AsFd::as_fd() instead.")]
601602
implAsRawFdforCanSocket{
602603
fnas_raw_fd(&self) ->RawFd{
@@ -743,14 +744,14 @@ impl SocketOptions for CanFdSocket {}
743744

744745
impl embedded_can::blocking::CanforCanFdSocket{
745746
typeFrame =CanAnyFrame;
746-
typeError =crate::Error;
747+
typeError =Error;
747748

748749
/// Blocking call to receive the next frame from the bus.
749750
///
750751
/// This block and wait for the next frame to be received from the bus.
751752
/// If an error frame is received, it will be converted to a `CanError`
752753
/// and returned as an error.
753-
fnreceive(&mutself) ->crate::Result<Self::Frame>{
754+
fnreceive(&mutself) ->Result<Self::Frame>{
754755
matchself.read_frame(){
755756
Ok(CanAnyFrame::Error(frame)) =>Err(frame.into_error().into()),
756757
Ok(frame) =>Ok(frame),
@@ -759,14 +760,15 @@ impl embedded_can::blocking::Can for CanFdSocket {
759760
}
760761

761762
/// Blocking transmit of a frame to the bus.
762-
fntransmit(&mutself,frame:&Self::Frame) ->crate::Result<()>{
763-
self.write_frame_insist(frame).map_err(|err| err.into())
763+
fntransmit(&mutself,frame:&Self::Frame) ->Result<()>{
764+
self.write_frame_insist(frame)?;
765+
Ok(())
764766
}
765767
}
766768

767769
impl embedded_can::nb::CanforCanFdSocket{
768770
typeFrame =CanAnyFrame;
769-
typeError =crate::Error;
771+
typeError =Error;
770772

771773
/// Non-blocking call to receive the next frame from the bus.
772774
///
@@ -775,19 +777,19 @@ impl embedded_can::nb::Can for CanFdSocket {
775777
/// If no frame is available, it returns a `WouldBlck` error.
776778
fnreceive(&mutself) -> nb::Result<Self::Frame,Self::Error>{
777779
matchself.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()),
779781
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()),
782784
}
783785
}
784786

785787
/// Non-blocking transmit of a frame to the bus.
786788
fntransmit(&mutself,frame:&Self::Frame) -> nb::Result<Option<Self::Frame>,Self::Error>{
787789
matchself.write_frame(frame){
788790
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()),
791793
}
792794
}
793795
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp