pub fn new_raw(fam: c_int, ty: c_int) -> io::Result<Socket> {
unsafe {
- // On linux we first attempt to pass the SOCK_CLOEXEC flag to
- // atomically create the socket and set it as CLOEXEC. Support for
- // this option, however, was added in 2.6.27, and we still support
- // 2.6.18 as a kernel, so if the returned error is EINVAL we
- // fallthrough to the fallback.
- if cfg!(target_os = "linux") {
- match cvt(libc::socket(fam, ty | SOCK_CLOEXEC, 0)) {
- Ok(fd) => return Ok(Socket(FileDesc::new(fd))),
- Err(ref e) if e.raw_os_error() == Some(libc::EINVAL) => {}
- Err(e) => return Err(e),
- }
- }
-
let fd = cvt(libc::socket(fam, ty, 0))?;
let fd = FileDesc::new(fd);
fd.set_cloexec()?;