std: Add a net
module for TCP/UDP
This commit is an implementation of [RFC 807][rfc] which adds a `std::net` module for basic neworking based on top of `std::io`. This module serves as a replacement for the `std::old_io::net` module and networking primitives in `old_io`. [rfc]: fillmein The major focus of this redesign is to cut back on the level of abstraction to the point that each of the networking types is just a bare socket. To this end functionality such as timeouts and cloning has been removed (although cloning can be done through `duplicate`, it may just yield an error). With this `net` module comes a new implementation of `SocketAddr` and `IpAddr`. This work is entirely based on #20785 and the only changes were to alter the in-memory representation to match the `libc`-expected variants and to move from public fields to accessors.
This commit is contained in:
parent
a954663db6
commit
395709ca6d
18 changed files with 3214 additions and 6 deletions
|
@ -32,8 +32,8 @@
|
|||
#![unstable(feature = "std_misc")]
|
||||
|
||||
use ffi::{OsStr, OsString};
|
||||
use fs::{Permissions, OpenOptions};
|
||||
use fs;
|
||||
use fs::{self, Permissions, OpenOptions};
|
||||
use net;
|
||||
use libc;
|
||||
use mem;
|
||||
use sys::os_str::Buf;
|
||||
|
@ -111,6 +111,16 @@ impl AsRawFd for old_io::net::udp::UdpSocket {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsRawFd for net::TcpStream {
|
||||
fn as_raw_fd(&self) -> Fd { *self.as_inner().socket().as_inner() }
|
||||
}
|
||||
impl AsRawFd for net::TcpListener {
|
||||
fn as_raw_fd(&self) -> Fd { *self.as_inner().socket().as_inner() }
|
||||
}
|
||||
impl AsRawFd for net::UdpSocket {
|
||||
fn as_raw_fd(&self) -> Fd { *self.as_inner().socket().as_inner() }
|
||||
}
|
||||
|
||||
// Unix-specific extensions to `OsString`.
|
||||
pub trait OsStringExt {
|
||||
/// Create an `OsString` from a byte vector.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue