Skip to content

Commit c9b3a29

Browse files
authored
Shrink unsafe block for the Async impl (#80)
1 parent 070d98b commit c9b3a29

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/lib.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -582,19 +582,20 @@ impl<T: AsRawSocket> Async<T> {
582582
let sock = io.as_raw_socket();
583583

584584
// Put the socket in non-blocking mode.
585-
unsafe {
586-
use winapi::ctypes;
587-
use winapi::um::winsock2;
588585

589-
let mut nonblocking = true as ctypes::c_ulong;
590-
let res = winsock2::ioctlsocket(
586+
use winapi::ctypes;
587+
use winapi::um::winsock2;
588+
589+
let mut nonblocking = true as ctypes::c_ulong;
590+
let res = unsafe {
591+
winsock2::ioctlsocket(
591592
sock as winsock2::SOCKET,
592593
winsock2::FIONBIO,
593594
&mut nonblocking,
594-
);
595-
if res != 0 {
596-
return Err(io::Error::last_os_error());
597-
}
595+
)
596+
};
597+
if res != 0 {
598+
return Err(io::Error::last_os_error());
598599
}
599600

600601
Ok(Async {

0 commit comments

Comments
 (0)