зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1806766 - Update net2 to 0.2.38. r=emilio,supply-chain-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D165474
This commit is contained in:
Родитель
b674972577
Коммит
2f918c58c2
|
@ -3687,9 +3687,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "net2"
|
||||
version = "0.2.37"
|
||||
version = "0.2.38"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae"
|
||||
checksum = "74d0df99cfcd2530b2e694f6e17e7f37b8e26bb23983ac530c0c97408837c631"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.999",
|
||||
"libc",
|
||||
|
|
|
@ -1122,6 +1122,11 @@ who = "Jim Blandy <jimb@red-bean.com>"
|
|||
criteria = "safe-to-deploy"
|
||||
delta = "0.9.0 -> 0.10.0"
|
||||
|
||||
[[audits.net2]]
|
||||
who = "Mike Hommey <mh+mozilla@glandium.org>"
|
||||
criteria = "safe-to-run"
|
||||
delta = "0.2.37 -> 0.2.38"
|
||||
|
||||
[[audits.new_debug_unreachable]]
|
||||
who = "Bobby Holley <bobbyholley@gmail.com>"
|
||||
criteria = "safe-to-deploy"
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"Cargo.toml":"3ef21068c8bd6d2afddf710600ae305511544f5e1ce86a8f715834ab9c3ff8b9","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"a99cb0401bd49e68c945f6a249175dd5c4a5117b2c8cc5d5fb7dea369002574e","src/ext.rs":"fd072307ebbaa01cfe1fd7553d7f42d27093b2bd32dd81d419d2e1c9423495a0","src/lib.rs":"a5e429c904fa13291dee5ed5df6c20adcebbaa56fc0312d475fd2056e9974153","src/socket.rs":"1468f54b4ce8ec2f94d8a23fba4c59752cbd2f447f29e7f0ae032785fdd916f4","src/sys/redox/impls.rs":"90059116f0514bd44dbf282a3e8d7b192c99e1a78a34ebacb00f2d325ca0f8b0","src/sys/redox/mod.rs":"137013d409fd174fed0ceb3eceb2c17d15f34a3af70c7d237c06dd3a144affc1","src/sys/unix/impls.rs":"05f123226e8fe7559317d50864021650b2455d25d01a9aff1c65c01ae26cf4ef","src/sys/unix/mod.rs":"e06b26bad48c815b9a2af4509d1873333e2aad0031980f6d2625f72542698d56","src/sys/wasi/impls.rs":"da4e95a27a765b64fbbebce55b860020ac891456085ed706d5f8f391e0d1cddf","src/sys/wasi/mod.rs":"e88b02f4d5e0ae558f093d49cc0bb1b3cdf86ede625d00ed9231f0ab414e483f","src/sys/windows/impls.rs":"bee70b7cd45055c4eaa1967f7aad7ec46639de458c71ed6f3e97a2f7b2c49281","src/sys/windows/mod.rs":"31a73007ea65a4905e93395f86105d2ef9fb84d3d795511c6cfdc8cba595cb0c","src/tcp.rs":"0bebf5cca75714151de30c8f2d7697ca519c57da065e93ba81796bce04673f8d","src/udp.rs":"8af5a55a4ae5e4120ffe18dcc4dc24072e18da34bf3591a02b18653e5d3e8ac8","src/unix.rs":"1156707694cb1f002a2eb2144bf205a73412e1661fd196a8a2a7bc8ea5aaad2d","src/utils.rs":"d31de5333a6fa2f5c99b64cc937be596888d9863264632e6bc6b36b30197fa5b"},"package":"391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae"}
|
||||
{"files":{"Cargo.toml":"fd3b1aa06b845c62754d8eaf1ca8a4cc07126b2fb76ed822a470a8881240f3db","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"a99cb0401bd49e68c945f6a249175dd5c4a5117b2c8cc5d5fb7dea369002574e","src/ext.rs":"08e78272ef677efcb4c029489214055ddb392f3163a931f260fccbd8a824eb51","src/lib.rs":"2f20b711078a365240f2c7683d9c34cac7c09bfd4756d89bf099bff56fb0de72","src/socket.rs":"f544539c94ccf8fc8710edbbf170d706a6037319e562b7d253aff2e1a75b7c48","src/sys/unix/impls.rs":"05f123226e8fe7559317d50864021650b2455d25d01a9aff1c65c01ae26cf4ef","src/sys/unix/mod.rs":"e06b26bad48c815b9a2af4509d1873333e2aad0031980f6d2625f72542698d56","src/sys/wasi/impls.rs":"da4e95a27a765b64fbbebce55b860020ac891456085ed706d5f8f391e0d1cddf","src/sys/wasi/mod.rs":"e88b02f4d5e0ae558f093d49cc0bb1b3cdf86ede625d00ed9231f0ab414e483f","src/sys/windows/impls.rs":"bee70b7cd45055c4eaa1967f7aad7ec46639de458c71ed6f3e97a2f7b2c49281","src/sys/windows/mod.rs":"31a73007ea65a4905e93395f86105d2ef9fb84d3d795511c6cfdc8cba595cb0c","src/tcp.rs":"0bebf5cca75714151de30c8f2d7697ca519c57da065e93ba81796bce04673f8d","src/udp.rs":"8af5a55a4ae5e4120ffe18dcc4dc24072e18da34bf3591a02b18653e5d3e8ac8","src/unix.rs":"1156707694cb1f002a2eb2144bf205a73412e1661fd196a8a2a7bc8ea5aaad2d","src/utils.rs":"d31de5333a6fa2f5c99b64cc937be596888d9863264632e6bc6b36b30197fa5b"},"package":"74d0df99cfcd2530b2e694f6e17e7f37b8e26bb23983ac530c0c97408837c631"}
|
|
@ -3,24 +3,32 @@
|
|||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g., crates.io) dependencies
|
||||
# to registry (e.g., crates.io) dependencies.
|
||||
#
|
||||
# If you believe there's an error in this file please file an
|
||||
# issue against the rust-lang/cargo repository. If you're
|
||||
# editing this file be aware that the upstream Cargo.toml
|
||||
# will likely look very different (and much more reasonable)
|
||||
# If you are reading this file be aware that the original Cargo.toml
|
||||
# will likely look very different (and much more reasonable).
|
||||
# See Cargo.toml.orig for the original contents.
|
||||
|
||||
[package]
|
||||
name = "net2"
|
||||
version = "0.2.37"
|
||||
version = "0.2.38"
|
||||
authors = ["Alex Crichton <alex@alexcrichton.com>"]
|
||||
include = ["Cargo.toml", "LICENSE-APACHE", "LICENSE-MIT", "README.md", "src/**/*.rs"]
|
||||
description = "Extensions to the standard library's networking types as proposed in RFC 1158.\n"
|
||||
include = [
|
||||
"Cargo.toml",
|
||||
"LICENSE-APACHE",
|
||||
"LICENSE-MIT",
|
||||
"README.md",
|
||||
"src/**/*.rs",
|
||||
]
|
||||
description = """
|
||||
Extensions to the standard library's networking types as proposed in RFC 1158.
|
||||
"""
|
||||
homepage = "https://github.com/deprecrated/net2-rs"
|
||||
documentation = "https://docs.rs/net2/~0.2"
|
||||
readme = "README.md"
|
||||
license = "MIT/Apache-2.0"
|
||||
repository = "https://github.com/deprecrated/net2-rs"
|
||||
|
||||
[dependencies.cfg-if]
|
||||
version = "0.1"
|
||||
|
||||
|
@ -28,8 +36,16 @@ version = "0.1"
|
|||
default = ["duration"]
|
||||
duration = []
|
||||
nightly = []
|
||||
[target."cfg(any(target_os=\"redox\", unix, target_os=\"wasi\"))".dependencies.libc]
|
||||
|
||||
[target."cfg(any(unix, target_os=\"wasi\"))".dependencies.libc]
|
||||
version = "0.2.54"
|
||||
|
||||
[target."cfg(windows)".dependencies.winapi]
|
||||
version = "0.3"
|
||||
features = ["handleapi", "winsock2", "ws2def", "ws2ipdef", "ws2tcpip"]
|
||||
features = [
|
||||
"handleapi",
|
||||
"winsock2",
|
||||
"ws2def",
|
||||
"ws2ipdef",
|
||||
"ws2tcpip",
|
||||
]
|
||||
|
|
|
@ -40,10 +40,9 @@ cfg_if! {
|
|||
|
||||
use std::time::Duration;
|
||||
|
||||
#[cfg(any(unix, target_os = "redox", target_os = "wasi"))] use libc::*;
|
||||
#[cfg(any(unix, target_os = "redox"))] use std::os::unix::prelude::*;
|
||||
#[cfg(any(unix, target_os = "wasi"))] use libc::*;
|
||||
#[cfg(any(unix))] use std::os::unix::prelude::*;
|
||||
#[cfg(target_os = "wasi")] use std::os::wasi::prelude::*;
|
||||
#[cfg(target_os = "redox")] pub type Socket = usize;
|
||||
#[cfg(unix)] pub type Socket = c_int;
|
||||
#[cfg(target_os = "wasi")] pub type Socket = std::os::wasi::io::RawFd;
|
||||
#[cfg(windows)] pub type Socket = SOCKET;
|
||||
|
@ -59,7 +58,7 @@ struct tcp_keepalive {
|
|||
keepaliveinterval: c_ulong,
|
||||
}
|
||||
|
||||
#[cfg(any(unix, target_os = "redox", target_os = "wasi"))] fn v(opt: c_int) -> c_int { opt }
|
||||
#[cfg(any(unix, target_os = "wasi"))] fn v(opt: c_int) -> c_int { opt }
|
||||
#[cfg(windows)] fn v(opt: IPPROTO) -> c_int { opt as c_int }
|
||||
|
||||
#[cfg(target_os = "wasi")]
|
||||
|
@ -73,8 +72,6 @@ pub fn set_opt<T: Copy>(sock: Socket, opt: c_int, val: c_int,
|
|||
payload: T) -> io::Result<()> {
|
||||
unsafe {
|
||||
let payload = &payload as *const T as *const c_void;
|
||||
#[cfg(target_os = "redox")]
|
||||
let sock = sock as c_int;
|
||||
try!(::cvt(setsockopt(sock, opt, val, payload as *const _,
|
||||
mem::size_of::<T>() as socklen_t)));
|
||||
}
|
||||
|
@ -90,8 +87,6 @@ pub fn get_opt<T: Copy>(sock: Socket, opt: c_int, val: c_int) -> io::Result<T> {
|
|||
unsafe {
|
||||
let mut slot: T = mem::zeroed();
|
||||
let mut len = mem::size_of::<T>() as socklen_t;
|
||||
#[cfg(target_os = "redox")]
|
||||
let sock = sock as c_int;
|
||||
try!(::cvt(getsockopt(sock, opt, val,
|
||||
&mut slot as *mut _ as *mut _,
|
||||
&mut len)));
|
||||
|
@ -656,7 +651,7 @@ pub trait AsSock {
|
|||
fn as_sock(&self) -> Socket;
|
||||
}
|
||||
|
||||
#[cfg(any(unix, target_os = "redox", target_os = "wasi"))]
|
||||
#[cfg(any(unix, target_os = "wasi"))]
|
||||
impl<T: AsRawFd> AsSock for T {
|
||||
fn as_sock(&self) -> Socket { self.as_raw_fd() }
|
||||
}
|
||||
|
@ -672,8 +667,6 @@ cfg_if! {
|
|||
use libc::SO_KEEPALIVE as KEEPALIVE_OPTION;
|
||||
} else if #[cfg(unix)] {
|
||||
use libc::TCP_KEEPIDLE as KEEPALIVE_OPTION;
|
||||
} else if #[cfg(target_os = "redox")] {
|
||||
use libc::TCP_KEEPIDLE as KEEPALIVE_OPTION;
|
||||
} else {
|
||||
// ...
|
||||
}
|
||||
|
@ -715,29 +708,6 @@ impl TcpStreamExt for TcpStream {
|
|||
self.keepalive_ms().map(|o| o.map(ms2dur))
|
||||
}
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
fn set_keepalive_ms(&self, keepalive: Option<u32>) -> io::Result<()> {
|
||||
try!(set_opt(self.as_sock(), SOL_SOCKET, SO_KEEPALIVE,
|
||||
keepalive.is_some() as c_int));
|
||||
if let Some(dur) = keepalive {
|
||||
try!(set_opt(self.as_sock(), v(IPPROTO_TCP), KEEPALIVE_OPTION,
|
||||
(dur / 1000) as c_int));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
fn keepalive_ms(&self) -> io::Result<Option<u32>> {
|
||||
let keepalive = try!(get_opt::<c_int>(self.as_sock(), SOL_SOCKET,
|
||||
SO_KEEPALIVE));
|
||||
if keepalive == 0 {
|
||||
return Ok(None)
|
||||
}
|
||||
let secs = try!(get_opt::<c_int>(self.as_sock(), v(IPPROTO_TCP),
|
||||
KEEPALIVE_OPTION));
|
||||
Ok(Some((secs as u32) * 1000))
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn set_keepalive_ms(&self, keepalive: Option<u32>) -> io::Result<()> {
|
||||
try!(set_opt(self.as_sock(), SOL_SOCKET, SO_KEEPALIVE,
|
||||
|
@ -893,7 +863,7 @@ impl TcpStreamExt for TcpStream {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "redox", unix, target_os = "wasi"))]
|
||||
#[cfg(any(unix, target_os = "wasi"))]
|
||||
fn ms2timeout(dur: Option<u32>) -> timeval {
|
||||
// TODO: be more rigorous
|
||||
match dur {
|
||||
|
@ -905,7 +875,7 @@ fn ms2timeout(dur: Option<u32>) -> timeval {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "redox", unix, target_os = "wasi"))]
|
||||
#[cfg(any(unix, target_os = "wasi"))]
|
||||
fn timeout2ms(dur: timeval) -> Option<u32> {
|
||||
if dur.tv_sec == 0 && dur.tv_usec == 0 {
|
||||
None
|
||||
|
@ -950,7 +920,7 @@ fn dur2linger(dur: Option<Duration>) -> linger {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "redox", unix, target_os = "wasi"))]
|
||||
#[cfg(any(unix, target_os = "wasi"))]
|
||||
fn dur2linger(dur: Option<Duration>) -> linger {
|
||||
match dur {
|
||||
Some(d) => {
|
||||
|
@ -1034,17 +1004,11 @@ impl UdpSocketExt for UdpSocket {
|
|||
}
|
||||
|
||||
fn set_multicast_hops_v6(&self, _hops: u32) -> io::Result<()> {
|
||||
#[cfg(target_os = "redox")]
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "Not implemented yet"));
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
set_opt(self.as_sock(), v(IPPROTO_IPV6), IPV6_MULTICAST_HOPS,
|
||||
_hops as c_int)
|
||||
}
|
||||
|
||||
fn multicast_hops_v6(&self) -> io::Result<u32> {
|
||||
#[cfg(target_os = "redox")]
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "Not implemented yet"));
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
get_opt::<c_int>(self.as_sock(), v(IPPROTO_IPV6), IPV6_MULTICAST_HOPS)
|
||||
.map(|b| b as u32)
|
||||
}
|
||||
|
@ -1059,30 +1023,18 @@ impl UdpSocketExt for UdpSocket {
|
|||
}
|
||||
|
||||
fn set_multicast_if_v4(&self, _interface: &Ipv4Addr) -> io::Result<()> {
|
||||
#[cfg(target_os = "redox")]
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "Not implemented yet"));
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
set_opt(self.as_sock(), IPPROTO_IP, IP_MULTICAST_IF, ip2in_addr(_interface))
|
||||
}
|
||||
|
||||
fn multicast_if_v4(&self) -> io::Result<Ipv4Addr> {
|
||||
#[cfg(target_os = "redox")]
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "Not implemented yet"));
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
get_opt(self.as_sock(), IPPROTO_IP, IP_MULTICAST_IF).map(in_addr2ip)
|
||||
}
|
||||
|
||||
fn set_multicast_if_v6(&self, _interface: u32) -> io::Result<()> {
|
||||
#[cfg(target_os = "redox")]
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "Not implemented yet"));
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
set_opt(self.as_sock(), v(IPPROTO_IPV6), IPV6_MULTICAST_IF, to_ipv6mr_interface(_interface))
|
||||
}
|
||||
|
||||
fn multicast_if_v6(&self) -> io::Result<u32> {
|
||||
#[cfg(target_os = "redox")]
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "Not implemented yet"));
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
get_opt::<c_int>(self.as_sock(), v(IPPROTO_IPV6), IPV6_MULTICAST_IF).map(|b| b as u32)
|
||||
}
|
||||
|
||||
|
@ -1096,16 +1048,10 @@ impl UdpSocketExt for UdpSocket {
|
|||
}
|
||||
|
||||
fn set_unicast_hops_v6(&self, _ttl: u32) -> io::Result<()> {
|
||||
#[cfg(target_os = "redox")]
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "Not implemented yet"));
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
set_opt(self.as_sock(), v(IPPROTO_IPV6), IPV6_UNICAST_HOPS, _ttl as c_int)
|
||||
}
|
||||
|
||||
fn unicast_hops_v6(&self) -> io::Result<u32> {
|
||||
#[cfg(target_os = "redox")]
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "Not implemented yet"));
|
||||
#[cfg(not(target_os = "redox"))]
|
||||
get_opt::<c_int>(self.as_sock(), IPPROTO_IP, IPV6_UNICAST_HOPS)
|
||||
.map(|b| b as u32)
|
||||
}
|
||||
|
@ -1200,13 +1146,6 @@ impl UdpSocketExt for UdpSocket {
|
|||
do_connect(self.as_sock(), addr)
|
||||
}
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
fn send(&self, buf: &[u8]) -> io::Result<usize> {
|
||||
unsafe {
|
||||
::cvt(write(self.as_sock() as c_int, buf.as_ptr() as *const _, buf.len())).map(|n| n as usize)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn send(&self, buf: &[u8]) -> io::Result<usize> {
|
||||
unsafe {
|
||||
|
@ -1240,14 +1179,6 @@ impl UdpSocketExt for UdpSocket {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
fn recv(&self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
unsafe {
|
||||
::cvt(read(self.as_sock() as c_int, buf.as_mut_ptr() as *mut _, buf.len()))
|
||||
.map(|n| n as usize)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn recv(&self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
unsafe {
|
||||
|
@ -1302,21 +1233,6 @@ fn do_connect<A: ToSocketAddrs>(sock: Socket, addr: A) -> io::Result<()> {
|
|||
return ret
|
||||
}
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
fn set_nonblocking(sock: Socket, nonblocking: bool) -> io::Result<()> {
|
||||
let mut flags = ::cvt(unsafe {
|
||||
fcntl(sock as c_int, F_GETFL)
|
||||
})?;
|
||||
if nonblocking {
|
||||
flags |= O_NONBLOCK;
|
||||
} else {
|
||||
flags &= !O_NONBLOCK;
|
||||
}
|
||||
::cvt(unsafe {
|
||||
fcntl(sock as c_int, F_SETFL, flags)
|
||||
}).and(Ok(()))
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn set_nonblocking(sock: Socket, nonblocking: bool) -> io::Result<()> {
|
||||
let mut nonblocking = nonblocking as c_ulong;
|
||||
|
@ -1338,17 +1254,6 @@ fn set_nonblocking(sock: Socket, nonblocking: bool) -> io::Result<()> {
|
|||
}).map(|_| ())
|
||||
}
|
||||
|
||||
#[cfg(target_os = "redox")]
|
||||
fn ip2in_addr(ip: &Ipv4Addr) -> in_addr {
|
||||
let oct = ip.octets();
|
||||
in_addr {
|
||||
s_addr: ::hton(((oct[0] as u32) << 24) |
|
||||
((oct[1] as u32) << 16) |
|
||||
((oct[2] as u32) << 8) |
|
||||
((oct[3] as u32) << 0)),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(unix, target_os = "wasi"))]
|
||||
fn ip2in_addr(ip: &Ipv4Addr) -> in_addr {
|
||||
let oct = ip.octets();
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
|
||||
#![cfg_attr(target_os = "wasi", feature(wasi_ext))]
|
||||
|
||||
#[cfg(any(target_os = "redox", target_os = "wasi", unix))] extern crate libc;
|
||||
#[cfg(any(target_os = "wasi", unix))] extern crate libc;
|
||||
|
||||
#[cfg(windows)] extern crate winapi;
|
||||
|
||||
|
@ -64,7 +64,6 @@ mod socket;
|
|||
mod ext;
|
||||
mod utils;
|
||||
|
||||
#[cfg(target_os="redox")] #[path = "sys/redox/mod.rs"] mod sys;
|
||||
#[cfg(unix)] #[path = "sys/unix/mod.rs"] mod sys;
|
||||
#[cfg(windows)] #[path = "sys/windows/mod.rs"] mod sys;
|
||||
#[cfg(target_os = "wasi")] #[path = "sys/wasi/mod.rs"] mod sys;
|
||||
|
|
|
@ -12,7 +12,7 @@ use std::fmt;
|
|||
use std::io;
|
||||
use std::mem;
|
||||
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
|
||||
#[cfg(any(unix, target_os = "redox", target_os = "wasi"))]
|
||||
#[cfg(any(unix, target_os = "wasi"))]
|
||||
use libc::c_int;
|
||||
#[cfg(windows)]
|
||||
use winapi::ctypes::c_int;
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
// 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.
|
||||
|
||||
use std::os::unix::io::{FromRawFd, AsRawFd};
|
||||
|
||||
use {TcpBuilder, UdpBuilder, FromInner, AsInner};
|
||||
use socket::Socket;
|
||||
use sys;
|
||||
|
||||
impl FromRawFd for TcpBuilder {
|
||||
unsafe fn from_raw_fd(fd: usize) -> TcpBuilder {
|
||||
let sock = sys::Socket::from_inner(fd);
|
||||
TcpBuilder::from_inner(Socket::from_inner(sock))
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRawFd for TcpBuilder {
|
||||
fn as_raw_fd(&self) -> usize {
|
||||
// TODO: this unwrap() is very bad
|
||||
self.as_inner().borrow().as_ref().unwrap().as_inner().raw() as usize
|
||||
}
|
||||
}
|
||||
|
||||
impl FromRawFd for UdpBuilder {
|
||||
unsafe fn from_raw_fd(fd: usize) -> UdpBuilder {
|
||||
let sock = sys::Socket::from_inner(fd);
|
||||
UdpBuilder::from_inner(Socket::from_inner(sock))
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRawFd for UdpBuilder {
|
||||
fn as_raw_fd(&self) -> usize {
|
||||
// TODO: this unwrap() is very bad
|
||||
self.as_inner().borrow().as_ref().unwrap().as_inner().raw() as usize
|
||||
}
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
// 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.
|
||||
|
||||
|
||||
use std::io;
|
||||
use std::mem;
|
||||
use std::net::{TcpListener, TcpStream, UdpSocket};
|
||||
use std::os::unix::io::FromRawFd;
|
||||
use libc::{self, c_int};
|
||||
|
||||
mod impls;
|
||||
|
||||
pub mod c {
|
||||
pub use libc::*;
|
||||
|
||||
pub fn sockaddr_in_u32(sa: &sockaddr_in) -> u32 {
|
||||
::ntoh((*sa).sin_addr.s_addr)
|
||||
}
|
||||
|
||||
pub fn in_addr_to_u32(addr: &in_addr) -> u32 {
|
||||
::ntoh(addr.s_addr)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Socket {
|
||||
fd: c_int,
|
||||
}
|
||||
|
||||
impl Socket {
|
||||
pub fn new(family: c_int, ty: c_int) -> io::Result<Socket> {
|
||||
unsafe {
|
||||
let fd = ::cvt(libc::socket(family, ty, 0))?;
|
||||
let mut flags = ::cvt(libc::fcntl(fd, libc::F_GETFD))?;
|
||||
flags |= libc::O_CLOEXEC;
|
||||
::cvt(libc::fcntl(fd, libc::F_SETFD, flags))?;
|
||||
Ok(Socket { fd: fd })
|
||||
}
|
||||
}
|
||||
|
||||
pub fn raw(&self) -> c_int { self.fd }
|
||||
|
||||
fn into_fd(self) -> c_int {
|
||||
let fd = self.fd;
|
||||
mem::forget(self);
|
||||
fd
|
||||
}
|
||||
|
||||
pub fn into_tcp_listener(self) -> TcpListener {
|
||||
unsafe { TcpListener::from_raw_fd(self.into_fd() as usize) }
|
||||
}
|
||||
|
||||
pub fn into_tcp_stream(self) -> TcpStream {
|
||||
unsafe { TcpStream::from_raw_fd(self.into_fd() as usize) }
|
||||
}
|
||||
|
||||
pub fn into_udp_socket(self) -> UdpSocket {
|
||||
unsafe { UdpSocket::from_raw_fd(self.into_fd() as usize) }
|
||||
}
|
||||
}
|
||||
|
||||
impl ::FromInner for Socket {
|
||||
type Inner = usize;
|
||||
fn from_inner(fd: usize) -> Socket {
|
||||
Socket { fd: fd as c_int }
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Socket {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
let _ = libc::close(self.fd);
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче