]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/wasm/net.rs
Refactor net::each_addr/lookup_host to forward error from resolve
[rust.git] / src / libstd / sys / wasm / net.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use fmt;
12 use io;
13 use net::{SocketAddr, Shutdown, Ipv4Addr, Ipv6Addr};
14 use time::Duration;
15 use sys::{unsupported, Void};
16 use convert::TryFrom;
17
18 pub struct TcpStream(Void);
19
20 impl TcpStream {
21     pub fn connect(_: io::Result<&SocketAddr>) -> io::Result<TcpStream> {
22         unsupported()
23     }
24
25     pub fn connect_timeout(_: &SocketAddr, _: Duration) -> io::Result<TcpStream> {
26         unsupported()
27     }
28
29     pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
30         match self.0 {}
31     }
32
33     pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
34         match self.0 {}
35     }
36
37     pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
38         match self.0 {}
39     }
40
41     pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
42         match self.0 {}
43     }
44
45     pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
46         match self.0 {}
47     }
48
49     pub fn read(&self, _: &mut [u8]) -> io::Result<usize> {
50         match self.0 {}
51     }
52
53     pub fn write(&self, _: &[u8]) -> io::Result<usize> {
54         match self.0 {}
55     }
56
57     pub fn peer_addr(&self) -> io::Result<SocketAddr> {
58         match self.0 {}
59     }
60
61     pub fn socket_addr(&self) -> io::Result<SocketAddr> {
62         match self.0 {}
63     }
64
65     pub fn shutdown(&self, _: Shutdown) -> io::Result<()> {
66         match self.0 {}
67     }
68
69     pub fn duplicate(&self) -> io::Result<TcpStream> {
70         match self.0 {}
71     }
72
73     pub fn set_nodelay(&self, _: bool) -> io::Result<()> {
74         match self.0 {}
75     }
76
77     pub fn nodelay(&self) -> io::Result<bool> {
78         match self.0 {}
79     }
80
81     pub fn set_ttl(&self, _: u32) -> io::Result<()> {
82         match self.0 {}
83     }
84
85     pub fn ttl(&self) -> io::Result<u32> {
86         match self.0 {}
87     }
88
89     pub fn take_error(&self) -> io::Result<Option<io::Error>> {
90         match self.0 {}
91     }
92
93     pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
94         match self.0 {}
95     }
96 }
97
98 impl fmt::Debug for TcpStream {
99     fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
100         match self.0 {}
101     }
102 }
103
104 pub struct TcpListener(Void);
105
106 impl TcpListener {
107     pub fn bind(_: io::Result<&SocketAddr>) -> io::Result<TcpListener> {
108         unsupported()
109     }
110
111     pub fn socket_addr(&self) -> io::Result<SocketAddr> {
112         match self.0 {}
113     }
114
115     pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
116         match self.0 {}
117     }
118
119     pub fn duplicate(&self) -> io::Result<TcpListener> {
120         match self.0 {}
121     }
122
123     pub fn set_ttl(&self, _: u32) -> io::Result<()> {
124         match self.0 {}
125     }
126
127     pub fn ttl(&self) -> io::Result<u32> {
128         match self.0 {}
129     }
130
131     pub fn set_only_v6(&self, _: bool) -> io::Result<()> {
132         match self.0 {}
133     }
134
135     pub fn only_v6(&self) -> io::Result<bool> {
136         match self.0 {}
137     }
138
139     pub fn take_error(&self) -> io::Result<Option<io::Error>> {
140         match self.0 {}
141     }
142
143     pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
144         match self.0 {}
145     }
146 }
147
148 impl fmt::Debug for TcpListener {
149     fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
150         match self.0 {}
151     }
152 }
153
154 pub struct UdpSocket(Void);
155
156 impl UdpSocket {
157     pub fn bind(_: io::Result<&SocketAddr>) -> io::Result<UdpSocket> {
158         unsupported()
159     }
160
161     pub fn socket_addr(&self) -> io::Result<SocketAddr> {
162         match self.0 {}
163     }
164
165     pub fn recv_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
166         match self.0 {}
167     }
168
169     pub fn peek_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
170         match self.0 {}
171     }
172
173     pub fn send_to(&self, _: &[u8], _: &SocketAddr) -> io::Result<usize> {
174         match self.0 {}
175     }
176
177     pub fn duplicate(&self) -> io::Result<UdpSocket> {
178         match self.0 {}
179     }
180
181     pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
182         match self.0 {}
183     }
184
185     pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
186         match self.0 {}
187     }
188
189     pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
190         match self.0 {}
191     }
192
193     pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
194         match self.0 {}
195     }
196
197     pub fn set_broadcast(&self, _: bool) -> io::Result<()> {
198         match self.0 {}
199     }
200
201     pub fn broadcast(&self) -> io::Result<bool> {
202         match self.0 {}
203     }
204
205     pub fn set_multicast_loop_v4(&self, _: bool) -> io::Result<()> {
206         match self.0 {}
207     }
208
209     pub fn multicast_loop_v4(&self) -> io::Result<bool> {
210         match self.0 {}
211     }
212
213     pub fn set_multicast_ttl_v4(&self, _: u32) -> io::Result<()> {
214         match self.0 {}
215     }
216
217     pub fn multicast_ttl_v4(&self) -> io::Result<u32> {
218         match self.0 {}
219     }
220
221     pub fn set_multicast_loop_v6(&self, _: bool) -> io::Result<()> {
222         match self.0 {}
223     }
224
225     pub fn multicast_loop_v6(&self) -> io::Result<bool> {
226         match self.0 {}
227     }
228
229     pub fn join_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr)
230                          -> io::Result<()> {
231         match self.0 {}
232     }
233
234     pub fn join_multicast_v6(&self, _: &Ipv6Addr, _: u32)
235                          -> io::Result<()> {
236         match self.0 {}
237     }
238
239     pub fn leave_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr)
240                           -> io::Result<()> {
241         match self.0 {}
242     }
243
244     pub fn leave_multicast_v6(&self, _: &Ipv6Addr, _: u32)
245                           -> io::Result<()> {
246         match self.0 {}
247     }
248
249     pub fn set_ttl(&self, _: u32) -> io::Result<()> {
250         match self.0 {}
251     }
252
253     pub fn ttl(&self) -> io::Result<u32> {
254         match self.0 {}
255     }
256
257     pub fn take_error(&self) -> io::Result<Option<io::Error>> {
258         match self.0 {}
259     }
260
261     pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
262         match self.0 {}
263     }
264
265     pub fn recv(&self, _: &mut [u8]) -> io::Result<usize> {
266         match self.0 {}
267     }
268
269     pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
270         match self.0 {}
271     }
272
273     pub fn send(&self, _: &[u8]) -> io::Result<usize> {
274         match self.0 {}
275     }
276
277     pub fn connect(&self, _: io::Result<&SocketAddr>) -> io::Result<()> {
278         match self.0 {}
279     }
280 }
281
282 impl fmt::Debug for UdpSocket {
283     fn fmt(&self, _f: &mut fmt::Formatter) -> fmt::Result {
284         match self.0 {}
285     }
286 }
287
288 pub struct LookupHost(Void);
289
290 impl LookupHost {
291     pub fn port(&self) -> u16 {
292         match self.0 {}
293     }
294 }
295
296 impl Iterator for LookupHost {
297     type Item = SocketAddr;
298     fn next(&mut self) -> Option<SocketAddr> {
299         match self.0 {}
300     }
301 }
302
303 impl<'a> TryFrom<&'a str> for LookupHost {
304     type Error = io::Error;
305
306     fn try_from(_v: &'a str) -> io::Result<LookupHost> {
307         unsupported()
308     }
309 }
310
311 impl<'a> TryFrom<(&'a str, u16)> for LookupHost {
312     type Error = io::Error;
313
314     fn try_from(_v: (&'a str, u16)) -> io::Result<LookupHost> {
315         unsupported()
316     }
317 }
318
319 #[allow(nonstandard_style)]
320 pub mod netc {
321     pub const AF_INET: u8 = 0;
322     pub const AF_INET6: u8 = 1;
323     pub type sa_family_t = u8;
324
325     #[derive(Copy, Clone)]
326     pub struct in_addr {
327         pub s_addr: u32,
328     }
329
330     #[derive(Copy, Clone)]
331     pub struct sockaddr_in {
332         pub sin_family: sa_family_t,
333         pub sin_port: u16,
334         pub sin_addr: in_addr,
335     }
336
337     #[derive(Copy, Clone)]
338     pub struct in6_addr {
339         pub s6_addr: [u8; 16],
340     }
341
342     #[derive(Copy, Clone)]
343     pub struct sockaddr_in6 {
344         pub sin6_family: sa_family_t,
345         pub sin6_port: u16,
346         pub sin6_addr: in6_addr,
347         pub sin6_flowinfo: u32,
348         pub sin6_scope_id: u32,
349     }
350
351     #[derive(Copy, Clone)]
352     pub struct sockaddr {
353     }
354
355     pub type socklen_t = usize;
356 }