Skip to content

Commit fb84707

Browse files
authored
Rollup merge of rust-lang#146432 - hermit-os:hermit-take_error, r=joboet
Implement `Socket::take_error` for Hermit This PR fixes an unused-imports compilation error introduced in 845311a and implements `Socket::take_error` for Hermit. Hermit's `Socket::take_error` implementation works exactly like the one for Unix. r? joboet
2 parents 1ea2b71 + af5355c commit fb84707

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

library/std/src/sys/net/connection/socket/hermit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ impl Socket {
304304
}
305305

306306
pub fn take_error(&self) -> io::Result<Option<io::Error>> {
307-
unimplemented!()
307+
let raw: c_int = getsockopt(self, libc::SOL_SOCKET, libc::SO_ERROR)?;
308+
if raw == 0 { Ok(None) } else { Ok(Some(io::Error::from_raw_os_error(raw as i32))) }
308309
}
309310

310311
// This is used by sys_common code to abstract over Windows and Unix.

library/std/src/sys/pal/hermit/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::ffi::{OsStr, OsString};
33
use crate::marker::PhantomData;
44
use crate::path::{self, PathBuf};
55
use crate::sys::unsupported;
6-
use crate::{fmt, io, str};
6+
use crate::{fmt, io};
77

88
pub fn errno() -> i32 {
99
unsafe { hermit_abi::get_errno() }

0 commit comments

Comments
 (0)