-
Notifications
You must be signed in to change notification settings - Fork 15
fix: match name with the std's & socket2's set_nonblocking
#33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -137,10 +137,10 @@ impl Socket { | |||||||||||||||
| // when building with --features smol we don't need this | ||||||||||||||||
| #[allow(dead_code)] | ||||||||||||||||
| /// Make this socket non-blocking | ||||||||||||||||
| pub fn set_non_blocking(&self, non_blocking: bool) -> Result<()> { | ||||||||||||||||
| let mut non_blocking = non_blocking as libc::c_int; | ||||||||||||||||
| pub fn set_nonblocking(&self, nonblocking: bool) -> Result<()> { | ||||||||||||||||
| let mut nonblocking = nonblocking as libc::c_int; | ||||||||||||||||
| let res = unsafe { | ||||||||||||||||
| libc::ioctl(self.as_raw_fd(), libc::FIONBIO, &mut non_blocking) | ||||||||||||||||
| libc::ioctl(self.as_raw_fd(), libc::FIONBIO, &mut nonblocking) | ||||||||||||||||
|
Comment on lines
+141
to
+143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To improve clarity and avoid shadowing the
Suggested change
|
||||||||||||||||
| }; | ||||||||||||||||
| if res < 0 { | ||||||||||||||||
| return Err(Error::last_os_error()); | ||||||||||||||||
|
|
@@ -689,10 +689,10 @@ mod test { | |||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| #[test] | ||||||||||||||||
| fn set_non_blocking() { | ||||||||||||||||
| fn set_nonblocking() { | ||||||||||||||||
| let sock = Socket::new(NETLINK_ROUTE).unwrap(); | ||||||||||||||||
| sock.set_non_blocking(true).unwrap(); | ||||||||||||||||
| sock.set_non_blocking(false).unwrap(); | ||||||||||||||||
| sock.set_nonblocking(true).unwrap(); | ||||||||||||||||
| sock.set_nonblocking(false).unwrap(); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| #[test] | ||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ pub struct TokioSocket(AsyncFd<Socket>); | |
| impl FromRawFd for TokioSocket { | ||
| unsafe fn from_raw_fd(fd: RawFd) -> Self { | ||
| let socket = Socket::from_raw_fd(fd); | ||
| socket.set_non_blocking(true).unwrap(); | ||
| socket.set_nonblocking(true).unwrap(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| TokioSocket(AsyncFd::new(socket).unwrap()) | ||
| } | ||
| } | ||
|
|
@@ -41,7 +41,7 @@ impl AsyncSocket for TokioSocket { | |
|
|
||
| fn new(protocol: isize) -> io::Result<Self> { | ||
| let socket = Socket::new(protocol)?; | ||
| socket.set_non_blocking(true)?; | ||
| socket.set_nonblocking(true)?; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| Ok(Self(AsyncFd::new(socket)?)) | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The call to
socket.set_nonblocking(true)is redundant becauseasync_io::Async::new()already sets the file descriptor to non-blocking mode. Removing this line also eliminates a potential panic from the use of.unwrap().