2015-02-06 00:50:11 +00:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2015-02-18 06:47:40 +00:00
|
|
|
use ffi::CStr;
|
2015-02-06 00:50:11 +00:00
|
|
|
use io;
|
2017-01-11 03:11:56 +00:00
|
|
|
use libc::{self, c_int, c_void, size_t, sockaddr, socklen_t, EAI_SYSTEM, MSG_PEEK};
|
|
|
|
use mem;
|
2015-11-03 00:23:22 +00:00
|
|
|
use net::{SocketAddr, Shutdown};
|
2015-02-06 00:50:11 +00:00
|
|
|
use str;
|
|
|
|
use sys::fd::FileDesc;
|
2015-07-16 06:31:24 +00:00
|
|
|
use sys_common::{AsInner, FromInner, IntoInner};
|
2017-01-11 03:11:56 +00:00
|
|
|
use sys_common::net::{getsockopt, setsockopt, sockaddr_to_addr};
|
2017-07-05 06:46:24 +00:00
|
|
|
use time::{Duration, Instant};
|
|
|
|
use cmp;
|
2015-02-06 00:50:11 +00:00
|
|
|
|
|
|
|
pub use sys::{cvt, cvt_r};
|
2016-02-02 09:39:59 +00:00
|
|
|
pub extern crate libc as netc;
|
2015-02-06 00:50:11 +00:00
|
|
|
|
|
|
|
pub type wrlen_t = size_t;
|
|
|
|
|
2016-02-04 21:30:24 +00:00
|
|
|
// See below for the usage of SOCK_CLOEXEC, but this constant is only defined on
|
|
|
|
// Linux currently (e.g. support doesn't exist on other platforms). In order to
|
|
|
|
// get name resolution to work and things to compile we just define a dummy
|
|
|
|
// SOCK_CLOEXEC here for other platforms. Note that the dummy constant isn't
|
|
|
|
// actually ever used (the blocks below are wrapped in `if cfg!` as well.
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
use libc::SOCK_CLOEXEC;
|
|
|
|
#[cfg(not(target_os = "linux"))]
|
|
|
|
const SOCK_CLOEXEC: c_int = 0;
|
|
|
|
|
2016-09-12 19:38:28 +00:00
|
|
|
// Another conditional contant for name resolution: Macos et iOS use
|
|
|
|
// SO_NOSIGPIPE as a setsockopt flag to disable SIGPIPE emission on socket.
|
|
|
|
// Other platforms do otherwise.
|
|
|
|
#[cfg(target_vendor = "apple")]
|
|
|
|
use libc::SO_NOSIGPIPE;
|
|
|
|
#[cfg(not(target_vendor = "apple"))]
|
|
|
|
const SO_NOSIGPIPE: c_int = 0;
|
|
|
|
|
2015-02-06 00:50:11 +00:00
|
|
|
pub struct Socket(FileDesc);
|
|
|
|
|
|
|
|
pub fn init() {}
|
|
|
|
|
|
|
|
pub fn cvt_gai(err: c_int) -> io::Result<()> {
|
2016-09-24 22:00:00 +00:00
|
|
|
if err == 0 {
|
|
|
|
return Ok(())
|
|
|
|
}
|
|
|
|
if err == EAI_SYSTEM {
|
|
|
|
return Err(io::Error::last_os_error())
|
|
|
|
}
|
2015-02-06 00:50:11 +00:00
|
|
|
|
|
|
|
let detail = unsafe {
|
2015-11-03 00:23:22 +00:00
|
|
|
str::from_utf8(CStr::from_ptr(libc::gai_strerror(err)).to_bytes()).unwrap()
|
2015-09-07 22:36:29 +00:00
|
|
|
.to_owned()
|
2015-02-06 00:50:11 +00:00
|
|
|
};
|
|
|
|
Err(io::Error::new(io::ErrorKind::Other,
|
2015-03-31 23:01:03 +00:00
|
|
|
&format!("failed to lookup address information: {}",
|
|
|
|
detail)[..]))
|
2015-02-06 00:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Socket {
|
|
|
|
pub fn new(addr: &SocketAddr, ty: c_int) -> io::Result<Socket> {
|
std: Stabilize the `net` module
This commit performs a stabilization pass over the std::net module,
incorporating the changes from RFC 923. Specifically, the following actions were
taken:
Stable functionality:
* `net` (the name)
* `Shutdown`
* `Shutdown::{Read, Write, Both}`
* `lookup_host`
* `LookupHost`
* `SocketAddr`
* `SocketAddr::{V4, V6}`
* `SocketAddr::port`
* `SocketAddrV4`
* `SocketAddrV4::{new, ip, port}`
* `SocketAddrV6`
* `SocketAddrV4::{new, ip, port, flowinfo, scope_id}`
* Common trait impls for socket addr structures
* `ToSocketAddrs`
* `ToSocketAddrs::Iter`
* `ToSocketAddrs::to_socket_addrs`
* `ToSocketAddrs for {SocketAddr*, (Ipv*Addr, u16), str, (str, u16)}`
* `Ipv4Addr`
* `Ipv4Addr::{new, octets, to_ipv6_compatible, to_ipv6_mapped}`
* `Ipv6Addr`
* `Ipv6Addr::{new, segments, to_ipv4}`
* `TcpStream`
* `TcpStream::connect`
* `TcpStream::{peer_addr, local_addr, shutdown, try_clone}`
* `{Read,Write} for {TcpStream, &TcpStream}`
* `TcpListener`
* `TcpListener::bind`
* `TcpListener::{local_addr, try_clone, accept, incoming}`
* `Incoming`
* `UdpSocket`
* `UdpSocket::bind`
* `UdpSocket::{recv_from, send_to, local_addr, try_clone}`
Unstable functionality:
* Extra methods on `Ipv{4,6}Addr` for various methods of inspecting the address
and determining qualities of it.
* Extra methods on `TcpStream` to configure various protocol options.
* Extra methods on `UdpSocket` to configure various protocol options.
Deprecated functionality:
* The `socket_addr` method has been renamed to `local_addr`
This commit is a breaking change due to the restructuring of the `SocketAddr`
type as well as the renaming of the `socket_addr` method. Migration should be
fairly straightforward, however, after accounting for the new level of
abstraction in `SocketAddr` (protocol distinction at the socket address level,
not the IP address).
[breaking-change]
2015-03-13 21:22:33 +00:00
|
|
|
let fam = match *addr {
|
|
|
|
SocketAddr::V4(..) => libc::AF_INET,
|
|
|
|
SocketAddr::V6(..) => libc::AF_INET6,
|
2015-02-06 00:50:11 +00:00
|
|
|
};
|
2016-03-17 03:50:45 +00:00
|
|
|
Socket::new_raw(fam, ty)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn new_raw(fam: c_int, ty: c_int) -> io::Result<Socket> {
|
2015-02-06 00:50:11 +00:00
|
|
|
unsafe {
|
2016-02-04 21:30:24 +00:00
|
|
|
// 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.
|
2016-07-21 00:26:12 +00:00
|
|
|
if cfg!(target_os = "linux") {
|
2016-02-04 21:30:24 +00:00
|
|
|
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),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-23 03:01:37 +00:00
|
|
|
let fd = cvt(libc::socket(fam, ty, 0))?;
|
2015-04-03 22:30:10 +00:00
|
|
|
let fd = FileDesc::new(fd);
|
2016-06-24 09:31:58 +00:00
|
|
|
fd.set_cloexec()?;
|
2016-09-12 19:38:28 +00:00
|
|
|
let socket = Socket(fd);
|
|
|
|
if cfg!(target_vendor = "apple") {
|
|
|
|
setsockopt(&socket, libc::SOL_SOCKET, SO_NOSIGPIPE, 1)?;
|
|
|
|
}
|
|
|
|
Ok(socket)
|
2015-02-06 00:50:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-17 03:50:45 +00:00
|
|
|
pub fn new_pair(fam: c_int, ty: c_int) -> io::Result<(Socket, Socket)> {
|
|
|
|
unsafe {
|
|
|
|
let mut fds = [0, 0];
|
|
|
|
|
|
|
|
// Like above, see if we can set cloexec atomically
|
2016-07-21 00:26:12 +00:00
|
|
|
if cfg!(target_os = "linux") {
|
2016-03-17 03:50:45 +00:00
|
|
|
match cvt(libc::socketpair(fam, ty | SOCK_CLOEXEC, 0, fds.as_mut_ptr())) {
|
|
|
|
Ok(_) => {
|
|
|
|
return Ok((Socket(FileDesc::new(fds[0])), Socket(FileDesc::new(fds[1]))));
|
|
|
|
}
|
|
|
|
Err(ref e) if e.raw_os_error() == Some(libc::EINVAL) => {},
|
|
|
|
Err(e) => return Err(e),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-23 03:01:37 +00:00
|
|
|
cvt(libc::socketpair(fam, ty, 0, fds.as_mut_ptr()))?;
|
2016-03-17 03:50:45 +00:00
|
|
|
let a = FileDesc::new(fds[0]);
|
|
|
|
let b = FileDesc::new(fds[1]);
|
2016-06-24 09:31:58 +00:00
|
|
|
a.set_cloexec()?;
|
|
|
|
b.set_cloexec()?;
|
2016-03-17 03:50:45 +00:00
|
|
|
Ok((Socket(a), Socket(b)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-05 06:46:24 +00:00
|
|
|
pub fn connect_timeout(&self, addr: &SocketAddr, timeout: Duration) -> io::Result<()> {
|
|
|
|
self.set_nonblocking(true)?;
|
|
|
|
let r = unsafe {
|
|
|
|
let (addrp, len) = addr.into_inner();
|
|
|
|
cvt(libc::connect(self.0.raw(), addrp, len))
|
|
|
|
};
|
|
|
|
self.set_nonblocking(false)?;
|
|
|
|
|
|
|
|
match r {
|
|
|
|
Ok(_) => return Ok(()),
|
|
|
|
// there's no ErrorKind for EINPROGRESS :(
|
|
|
|
Err(ref e) if e.raw_os_error() == Some(libc::EINPROGRESS) => {}
|
|
|
|
Err(e) => return Err(e),
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut pollfd = libc::pollfd {
|
|
|
|
fd: self.0.raw(),
|
|
|
|
events: libc::POLLOUT,
|
|
|
|
revents: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
if timeout.as_secs() == 0 && timeout.subsec_nanos() == 0 {
|
|
|
|
return Err(io::Error::new(io::ErrorKind::InvalidInput,
|
|
|
|
"cannot set a 0 duration timeout"));
|
|
|
|
}
|
|
|
|
|
|
|
|
let start = Instant::now();
|
|
|
|
|
|
|
|
loop {
|
|
|
|
let elapsed = start.elapsed();
|
|
|
|
if elapsed >= timeout {
|
|
|
|
return Err(io::Error::new(io::ErrorKind::TimedOut, "connection timed out"));
|
|
|
|
}
|
|
|
|
|
|
|
|
let timeout = timeout - elapsed;
|
|
|
|
let mut timeout = timeout.as_secs()
|
|
|
|
.saturating_mul(1_000)
|
|
|
|
.saturating_add(timeout.subsec_nanos() as u64 / 1_000_000);
|
|
|
|
if timeout == 0 {
|
|
|
|
timeout = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
let timeout = cmp::min(timeout, c_int::max_value() as u64) as c_int;
|
|
|
|
|
|
|
|
match unsafe { libc::poll(&mut pollfd, 1, timeout) } {
|
|
|
|
-1 => {
|
|
|
|
let err = io::Error::last_os_error();
|
|
|
|
if err.kind() != io::ErrorKind::Interrupted {
|
|
|
|
return Err(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
0 => {}
|
|
|
|
_ => {
|
|
|
|
if pollfd.revents & libc::POLLOUT == 0 {
|
|
|
|
if let Some(e) = self.take_error()? {
|
|
|
|
return Err(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-04 23:22:41 +00:00
|
|
|
pub fn accept(&self, storage: *mut sockaddr, len: *mut socklen_t)
|
|
|
|
-> io::Result<Socket> {
|
|
|
|
// Unfortunately the only known way right now to accept a socket and
|
|
|
|
// atomically set the CLOEXEC flag is to use the `accept4` syscall on
|
|
|
|
// Linux. This was added in 2.6.28, however, and because we support
|
|
|
|
// 2.6.18 we must detect this support dynamically.
|
|
|
|
if cfg!(target_os = "linux") {
|
|
|
|
weak! {
|
|
|
|
fn accept4(c_int, *mut sockaddr, *mut socklen_t, c_int) -> c_int
|
|
|
|
}
|
|
|
|
if let Some(accept) = accept4.get() {
|
|
|
|
let res = cvt_r(|| unsafe {
|
|
|
|
accept(self.0.raw(), storage, len, SOCK_CLOEXEC)
|
|
|
|
});
|
|
|
|
match res {
|
|
|
|
Ok(fd) => return Ok(Socket(FileDesc::new(fd))),
|
|
|
|
Err(ref e) if e.raw_os_error() == Some(libc::ENOSYS) => {}
|
|
|
|
Err(e) => return Err(e),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-23 03:01:37 +00:00
|
|
|
let fd = cvt_r(|| unsafe {
|
2015-02-06 00:50:11 +00:00
|
|
|
libc::accept(self.0.raw(), storage, len)
|
2016-03-23 03:01:37 +00:00
|
|
|
})?;
|
2015-04-03 22:30:10 +00:00
|
|
|
let fd = FileDesc::new(fd);
|
2016-06-24 09:31:58 +00:00
|
|
|
fd.set_cloexec()?;
|
2015-04-03 22:30:10 +00:00
|
|
|
Ok(Socket(fd))
|
2015-02-06 00:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn duplicate(&self) -> io::Result<Socket> {
|
2016-01-21 05:24:23 +00:00
|
|
|
self.0.duplicate().map(Socket)
|
2015-02-06 00:50:11 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 03:11:56 +00:00
|
|
|
fn recv_with_flags(&self, buf: &mut [u8], flags: c_int) -> io::Result<usize> {
|
|
|
|
let ret = cvt(unsafe {
|
|
|
|
libc::recv(self.0.raw(),
|
|
|
|
buf.as_mut_ptr() as *mut c_void,
|
|
|
|
buf.len(),
|
|
|
|
flags)
|
|
|
|
})?;
|
|
|
|
Ok(ret as usize)
|
|
|
|
}
|
|
|
|
|
2015-02-06 00:50:11 +00:00
|
|
|
pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
|
2017-01-11 03:11:56 +00:00
|
|
|
self.recv_with_flags(buf, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn peek(&self, buf: &mut [u8]) -> io::Result<usize> {
|
|
|
|
self.recv_with_flags(buf, MSG_PEEK)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn recv_from_with_flags(&self, buf: &mut [u8], flags: c_int)
|
|
|
|
-> io::Result<(usize, SocketAddr)> {
|
|
|
|
let mut storage: libc::sockaddr_storage = unsafe { mem::zeroed() };
|
|
|
|
let mut addrlen = mem::size_of_val(&storage) as libc::socklen_t;
|
|
|
|
|
|
|
|
let n = cvt(unsafe {
|
|
|
|
libc::recvfrom(self.0.raw(),
|
|
|
|
buf.as_mut_ptr() as *mut c_void,
|
|
|
|
buf.len(),
|
|
|
|
flags,
|
|
|
|
&mut storage as *mut _ as *mut _,
|
|
|
|
&mut addrlen)
|
|
|
|
})?;
|
|
|
|
Ok((n as usize, sockaddr_to_addr(&storage, addrlen as usize)?))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn recv_from(&self, buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
|
|
|
|
self.recv_from_with_flags(buf, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn peek_from(&self, buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
|
|
|
|
self.recv_from_with_flags(buf, MSG_PEEK)
|
2015-02-06 00:50:11 +00:00
|
|
|
}
|
2015-05-27 06:47:03 +00:00
|
|
|
|
2016-03-17 03:50:45 +00:00
|
|
|
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
|
|
|
|
self.0.write(buf)
|
|
|
|
}
|
|
|
|
|
2015-05-27 06:47:03 +00:00
|
|
|
pub fn set_timeout(&self, dur: Option<Duration>, kind: libc::c_int) -> io::Result<()> {
|
|
|
|
let timeout = match dur {
|
|
|
|
Some(dur) => {
|
2015-07-06 06:20:00 +00:00
|
|
|
if dur.as_secs() == 0 && dur.subsec_nanos() == 0 {
|
2015-05-27 06:47:03 +00:00
|
|
|
return Err(io::Error::new(io::ErrorKind::InvalidInput,
|
|
|
|
"cannot set a 0 duration timeout"));
|
|
|
|
}
|
|
|
|
|
2015-07-06 06:20:00 +00:00
|
|
|
let secs = if dur.as_secs() > libc::time_t::max_value() as u64 {
|
2015-05-27 06:47:03 +00:00
|
|
|
libc::time_t::max_value()
|
|
|
|
} else {
|
2015-07-06 06:20:00 +00:00
|
|
|
dur.as_secs() as libc::time_t
|
2015-05-27 06:47:03 +00:00
|
|
|
};
|
|
|
|
let mut timeout = libc::timeval {
|
|
|
|
tv_sec: secs,
|
2015-07-06 06:20:00 +00:00
|
|
|
tv_usec: (dur.subsec_nanos() / 1000) as libc::suseconds_t,
|
2015-05-27 06:47:03 +00:00
|
|
|
};
|
|
|
|
if timeout.tv_sec == 0 && timeout.tv_usec == 0 {
|
|
|
|
timeout.tv_usec = 1;
|
|
|
|
}
|
|
|
|
timeout
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
libc::timeval {
|
|
|
|
tv_sec: 0,
|
|
|
|
tv_usec: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
setsockopt(self, libc::SOL_SOCKET, kind, timeout)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn timeout(&self, kind: libc::c_int) -> io::Result<Option<Duration>> {
|
2016-03-23 03:01:37 +00:00
|
|
|
let raw: libc::timeval = getsockopt(self, libc::SOL_SOCKET, kind)?;
|
2015-05-27 06:47:03 +00:00
|
|
|
if raw.tv_sec == 0 && raw.tv_usec == 0 {
|
|
|
|
Ok(None)
|
|
|
|
} else {
|
|
|
|
let sec = raw.tv_sec as u64;
|
|
|
|
let nsec = (raw.tv_usec as u32) * 1000;
|
|
|
|
Ok(Some(Duration::new(sec, nsec)))
|
|
|
|
}
|
|
|
|
}
|
2015-11-03 00:23:22 +00:00
|
|
|
|
|
|
|
pub fn shutdown(&self, how: Shutdown) -> io::Result<()> {
|
|
|
|
let how = match how {
|
|
|
|
Shutdown::Write => libc::SHUT_WR,
|
|
|
|
Shutdown::Read => libc::SHUT_RD,
|
|
|
|
Shutdown::Both => libc::SHUT_RDWR,
|
|
|
|
};
|
2016-03-23 03:01:37 +00:00
|
|
|
cvt(unsafe { libc::shutdown(self.0.raw(), how) })?;
|
2015-11-03 00:23:22 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
2016-02-27 22:15:19 +00:00
|
|
|
|
2016-02-28 05:05:32 +00:00
|
|
|
pub fn set_nodelay(&self, nodelay: bool) -> io::Result<()> {
|
|
|
|
setsockopt(self, libc::IPPROTO_TCP, libc::TCP_NODELAY, nodelay as c_int)
|
2016-02-27 22:15:19 +00:00
|
|
|
}
|
|
|
|
|
2016-02-28 05:05:32 +00:00
|
|
|
pub fn nodelay(&self) -> io::Result<bool> {
|
2016-03-23 03:01:37 +00:00
|
|
|
let raw: c_int = getsockopt(self, libc::IPPROTO_TCP, libc::TCP_NODELAY)?;
|
2016-02-28 05:05:32 +00:00
|
|
|
Ok(raw != 0)
|
2016-02-27 22:15:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
|
2016-09-07 15:21:10 +00:00
|
|
|
let mut nonblocking = nonblocking as libc::c_int;
|
2016-02-27 22:15:19 +00:00
|
|
|
cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(|_| ())
|
|
|
|
}
|
2016-03-17 03:50:45 +00:00
|
|
|
|
|
|
|
pub fn take_error(&self) -> io::Result<Option<io::Error>> {
|
2016-03-23 03:01:37 +00:00
|
|
|
let raw: c_int = getsockopt(self, libc::SOL_SOCKET, libc::SO_ERROR)?;
|
2016-03-17 03:50:45 +00:00
|
|
|
if raw == 0 {
|
|
|
|
Ok(None)
|
|
|
|
} else {
|
|
|
|
Ok(Some(io::Error::from_raw_os_error(raw as i32)))
|
|
|
|
}
|
|
|
|
}
|
2015-02-06 00:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl AsInner<c_int> for Socket {
|
|
|
|
fn as_inner(&self) -> &c_int { self.0.as_inner() }
|
|
|
|
}
|
std: Stabilize parts of std::os::platform::io
This commit stabilizes the platform-specific `io` modules, specifically around
the traits having to do with the raw representation of each object on each
platform.
Specifically, the following material was stabilized:
* `AsRaw{Fd,Socket,Handle}`
* `RawFd` (renamed from `Fd`)
* `RawHandle` (renamed from `Handle`)
* `RawSocket` (renamed from `Socket`)
* `AsRaw{Fd,Socket,Handle}` implementations
* `std::os::{unix, windows}::io`
The following material was added as `#[unstable]`:
* `FromRaw{Fd,Socket,Handle}`
* Implementations for various primitives
There are a number of future improvements that are possible to make to this
module, but this should cover a good bit of functionality desired from these
modules for now. Some specific future additions may include:
* `IntoRawXXX` traits to consume the raw representation and cancel the
auto-destructor.
* `Fd`, `Socket`, and `Handle` abstractions that behave like Rust objects and
have nice methods for various syscalls.
At this time though, these are considered backwards-compatible extensions and
will not be stabilized at this time.
This commit is a breaking change due to the addition of `Raw` in from of the
type aliases in each of the platform-specific modules.
[breaking-change]
2015-03-26 23:18:29 +00:00
|
|
|
|
|
|
|
impl FromInner<c_int> for Socket {
|
|
|
|
fn from_inner(fd: c_int) -> Socket { Socket(FileDesc::new(fd)) }
|
|
|
|
}
|
2015-07-16 06:31:24 +00:00
|
|
|
|
|
|
|
impl IntoInner<c_int> for Socket {
|
|
|
|
fn into_inner(self) -> c_int { self.0.into_raw() }
|
|
|
|
}
|