Skip to content

Commit 7d3ae87

Browse files
committed
Add RawFd traits for net
1 parent 92c8e0f commit 7d3ae87

File tree

3 files changed

+64
-15
lines changed

3 files changed

+64
-15
lines changed

src/libstd/sys/redox/ext/io.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
#![stable(feature = "rust1", since = "1.0.0")]
1414

1515
use fs;
16+
use net;
1617
use sys;
17-
use sys_common::{AsInner, FromInner, IntoInner};
18+
use sys_common::{self, AsInner, FromInner, IntoInner};
1819

1920
/// Raw file descriptors.
2021
#[stable(feature = "rust1", since = "1.0.0")]
@@ -89,58 +90,62 @@ impl IntoRawFd for fs::File {
8990
}
9091
}
9192

92-
/*
9393
#[stable(feature = "rust1", since = "1.0.0")]
9494
impl AsRawFd for net::TcpStream {
95-
fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
95+
fn as_raw_fd(&self) -> RawFd {
96+
self.as_inner().as_inner().fd().raw()
97+
}
9698
}
9799
#[stable(feature = "rust1", since = "1.0.0")]
98100
impl AsRawFd for net::TcpListener {
99-
fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
101+
fn as_raw_fd(&self) -> RawFd {
102+
self.as_inner().as_inner().fd().raw()
103+
}
100104
}
101105
#[stable(feature = "rust1", since = "1.0.0")]
102106
impl AsRawFd for net::UdpSocket {
103-
fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() }
107+
fn as_raw_fd(&self) -> RawFd {
108+
self.as_inner().as_inner().fd().raw()
109+
}
104110
}
105111

106112
#[stable(feature = "from_raw_os", since = "1.1.0")]
107113
impl FromRawFd for net::TcpStream {
108114
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpStream {
109-
let socket = sys::net::Socket::from_inner(fd);
110-
net::TcpStream::from_inner(sys_common::net::TcpStream::from_inner(socket))
115+
let file = sys::fs::File::from_inner(fd);
116+
net::TcpStream::from_inner(sys_common::net::TcpStream::from_inner(file))
111117
}
112118
}
113119
#[stable(feature = "from_raw_os", since = "1.1.0")]
114120
impl FromRawFd for net::TcpListener {
115121
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpListener {
116-
let socket = sys::net::Socket::from_inner(fd);
117-
net::TcpListener::from_inner(sys_common::net::TcpListener::from_inner(socket))
122+
let file = sys::fs::File::from_inner(fd);
123+
net::TcpListener::from_inner(sys_common::net::TcpListener::from_inner(file))
118124
}
119125
}
120126
#[stable(feature = "from_raw_os", since = "1.1.0")]
121127
impl FromRawFd for net::UdpSocket {
122128
unsafe fn from_raw_fd(fd: RawFd) -> net::UdpSocket {
123-
let socket = sys::net::Socket::from_inner(fd);
124-
net::UdpSocket::from_inner(sys_common::net::UdpSocket::from_inner(socket))
129+
let file = sys::fs::File::from_inner(fd);
130+
net::UdpSocket::from_inner(sys_common::net::UdpSocket::from_inner(file))
125131
}
126132
}
127133

128134
#[stable(feature = "into_raw_os", since = "1.4.0")]
129135
impl IntoRawFd for net::TcpStream {
130136
fn into_raw_fd(self) -> RawFd {
131-
self.into_inner().into_socket().into_inner()
137+
self.into_inner().into_inner().into_fd().into_raw()
132138
}
133139
}
134140
#[stable(feature = "into_raw_os", since = "1.4.0")]
135141
impl IntoRawFd for net::TcpListener {
136142
fn into_raw_fd(self) -> RawFd {
137-
self.into_inner().into_socket().into_inner()
143+
self.into_inner().into_inner().into_fd().into_raw()
138144
}
139145
}
140146
#[stable(feature = "into_raw_os", since = "1.4.0")]
141147
impl IntoRawFd for net::UdpSocket {
142148
fn into_raw_fd(self) -> RawFd {
143-
self.into_inner().into_socket().into_inner()
149+
self.into_inner().into_inner().into_fd().into_raw()
144150
}
145151
}
146-
*/

src/libstd/sys/redox/net/tcp.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use io::{Error, ErrorKind, Result};
1212
use net::{SocketAddr, Shutdown};
1313
use path::Path;
1414
use sys::fs::{File, OpenOptions};
15+
use sys_common::{AsInner, FromInner, IntoInner};
1516
use time::Duration;
1617
use vec::Vec;
1718

@@ -112,6 +113,20 @@ impl TcpStream {
112113
}
113114
}
114115

116+
impl AsInner<File> for TcpStream {
117+
fn as_inner(&self) -> &File { &self.0 }
118+
}
119+
120+
impl FromInner<File> for TcpStream {
121+
fn from_inner(file: File) -> TcpStream {
122+
TcpStream(file)
123+
}
124+
}
125+
126+
impl IntoInner<File> for TcpStream {
127+
fn into_inner(self) -> File { self.0 }
128+
}
129+
115130
#[derive(Debug)]
116131
pub struct TcpListener(File);
117132

@@ -168,3 +183,17 @@ impl TcpListener {
168183
Err(Error::new(ErrorKind::Other, "TcpListener::set_ttl not implemented"))
169184
}
170185
}
186+
187+
impl AsInner<File> for TcpListener {
188+
fn as_inner(&self) -> &File { &self.0 }
189+
}
190+
191+
impl FromInner<File> for TcpListener {
192+
fn from_inner(file: File) -> TcpListener {
193+
TcpListener(file)
194+
}
195+
}
196+
197+
impl IntoInner<File> for TcpListener {
198+
fn into_inner(self) -> File { self.0 }
199+
}

src/libstd/sys/redox/net/udp.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use io::{Error, ErrorKind, Result};
1313
use net::{SocketAddr, Ipv4Addr, Ipv6Addr};
1414
use path::Path;
1515
use sys::fs::{File, OpenOptions};
16+
use sys_common::{AsInner, FromInner, IntoInner};
1617
use time::Duration;
1718

1819
use super::{path_to_peer_addr, path_to_local_addr};
@@ -171,3 +172,17 @@ impl UdpSocket {
171172
Err(Error::new(ErrorKind::Other, "UdpSocket::leave_multicast_v6 not implemented"))
172173
}
173174
}
175+
176+
impl AsInner<File> for UdpSocket {
177+
fn as_inner(&self) -> &File { &self.0 }
178+
}
179+
180+
impl FromInner<File> for UdpSocket {
181+
fn from_inner(file: File) -> UdpSocket {
182+
UdpSocket(file, UnsafeCell::new(None))
183+
}
184+
}
185+
186+
impl IntoInner<File> for UdpSocket {
187+
fn into_inner(self) -> File { self.0 }
188+
}

0 commit comments

Comments
 (0)