]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/unix/l4re.rs
Refactor net::each_addr/lookup_host to forward error from resolve
[rust.git] / src / libstd / sys / unix / l4re.rs
1 // Copyright 2016-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 macro_rules! unimpl {
12     () => (return Err(io::Error::new(io::ErrorKind::Other, "No networking available on L4Re."));)
13 }
14
15 pub mod net {
16     #![allow(warnings)]
17     use fmt;
18     use io;
19     use libc;
20     use net::{SocketAddr, Shutdown, Ipv4Addr, Ipv6Addr};
21     use sys_common::{AsInner, FromInner, IntoInner};
22     use sys::fd::FileDesc;
23     use time::Duration;
24     use convert::TryFrom;
25
26     pub extern crate libc as netc;
27
28     pub struct Socket(FileDesc);
29     impl Socket {
30         pub fn new(_: &SocketAddr, _: libc::c_int) -> io::Result<Socket> {
31             unimpl!();
32         }
33
34         pub fn new_raw(_: libc::c_int, _: libc::c_int) -> io::Result<Socket> {
35             unimpl!();
36         }
37
38         pub fn new_pair(_: libc::c_int, _: libc::c_int) -> io::Result<(Socket, Socket)> {
39             unimpl!();
40         }
41
42         pub fn connect_timeout(&self, _: &SocketAddr, _: Duration) -> io::Result<()> {
43             unimpl!();
44         }
45
46         pub fn accept(&self, _: *mut libc::sockaddr, _: *mut libc::socklen_t)
47                   -> io::Result<Socket> {
48             unimpl!();
49         }
50
51         pub fn duplicate(&self) -> io::Result<Socket> {
52             unimpl!();
53         }
54
55         pub fn read(&self, _: &mut [u8]) -> io::Result<usize> {
56             unimpl!();
57         }
58
59         pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
60             unimpl!();
61         }
62
63         pub fn recv_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
64             unimpl!();
65         }
66
67         pub fn peek_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
68             unimpl!();
69         }
70
71         pub fn write(&self, _: &[u8]) -> io::Result<usize> {
72             unimpl!();
73         }
74
75         pub fn set_timeout(&self, _: Option<Duration>, _: libc::c_int) -> io::Result<()> {
76             unimpl!();
77         }
78
79         pub fn timeout(&self, _: libc::c_int) -> io::Result<Option<Duration>> {
80             unimpl!();
81         }
82
83         pub fn shutdown(&self, _: Shutdown) -> io::Result<()> {
84             unimpl!();
85         }
86
87         pub fn set_nodelay(&self, _: bool) -> io::Result<()> {
88             unimpl!();
89         }
90
91         pub fn nodelay(&self) -> io::Result<bool> {
92             unimpl!();
93         }
94
95         pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
96             unimpl!();
97         }
98
99         pub fn take_error(&self) -> io::Result<Option<io::Error>> {
100             unimpl!();
101         }
102     }
103
104     impl AsInner<libc::c_int> for Socket {
105         fn as_inner(&self) -> &libc::c_int { self.0.as_inner() }
106     }
107
108     impl FromInner<libc::c_int> for Socket {
109         fn from_inner(fd: libc::c_int) -> Socket { Socket(FileDesc::new(fd)) }
110     }
111
112     impl IntoInner<libc::c_int> for Socket {
113         fn into_inner(self) -> libc::c_int { self.0.into_raw() }
114     }
115
116     pub struct TcpStream {
117         inner: Socket,
118     }
119
120     impl TcpStream {
121         pub fn connect(_: io::Result<&SocketAddr>) -> io::Result<TcpStream> {
122             unimpl!();
123         }
124
125         pub fn connect_timeout(_: &SocketAddr, _: Duration) -> io::Result<TcpStream> {
126             unimpl!();
127         }
128
129         pub fn socket(&self) -> &Socket { &self.inner }
130
131         pub fn into_socket(self) -> Socket { self.inner }
132
133         pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
134             unimpl!();
135         }
136
137         pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
138             unimpl!();
139         }
140
141         pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
142             unimpl!();
143         }
144
145         pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
146             unimpl!();
147         }
148
149         pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
150             unimpl!();
151         }
152
153         pub fn read(&self, _: &mut [u8]) -> io::Result<usize> {
154             unimpl!();
155         }
156
157         pub fn write(&self, _: &[u8]) -> io::Result<usize> {
158             unimpl!();
159         }
160
161         pub fn peer_addr(&self) -> io::Result<SocketAddr> {
162             unimpl!();
163         }
164
165         pub fn socket_addr(&self) -> io::Result<SocketAddr> {
166             unimpl!();
167         }
168
169         pub fn shutdown(&self, _: Shutdown) -> io::Result<()> {
170             unimpl!();
171         }
172
173         pub fn duplicate(&self) -> io::Result<TcpStream> {
174             unimpl!();
175         }
176
177         pub fn set_nodelay(&self, _: bool) -> io::Result<()> {
178             unimpl!();
179         }
180
181         pub fn nodelay(&self) -> io::Result<bool> {
182             unimpl!();
183         }
184
185         pub fn set_ttl(&self, _: u32) -> io::Result<()> {
186             unimpl!();
187         }
188
189         pub fn ttl(&self) -> io::Result<u32> {
190             unimpl!();
191         }
192
193         pub fn take_error(&self) -> io::Result<Option<io::Error>> {
194             unimpl!();
195         }
196
197         pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
198             unimpl!();
199         }
200     }
201
202     impl FromInner<Socket> for TcpStream {
203         fn from_inner(socket: Socket) -> TcpStream {
204             TcpStream { inner: socket }
205         }
206     }
207
208     impl fmt::Debug for TcpStream {
209         fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
210             write!(f, "No networking support available on L4Re")
211         }
212     }
213
214     pub struct TcpListener {
215         inner: Socket,
216     }
217
218     impl TcpListener {
219         pub fn bind(_: io::Result<&SocketAddr>) -> io::Result<TcpListener> {
220             unimpl!();
221         }
222
223         pub fn socket(&self) -> &Socket { &self.inner }
224
225         pub fn into_socket(self) -> Socket { self.inner }
226
227         pub fn socket_addr(&self) -> io::Result<SocketAddr> {
228             unimpl!();
229         }
230
231         pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
232             unimpl!();
233         }
234
235         pub fn duplicate(&self) -> io::Result<TcpListener> {
236             unimpl!();
237         }
238
239         pub fn set_ttl(&self, _: u32) -> io::Result<()> {
240             unimpl!();
241         }
242
243         pub fn ttl(&self) -> io::Result<u32> {
244             unimpl!();
245         }
246
247         pub fn set_only_v6(&self, _: bool) -> io::Result<()> {
248             unimpl!();
249         }
250
251         pub fn only_v6(&self) -> io::Result<bool> {
252             unimpl!();
253         }
254
255         pub fn take_error(&self) -> io::Result<Option<io::Error>> {
256             unimpl!();
257         }
258
259         pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
260             unimpl!();
261         }
262     }
263
264     impl FromInner<Socket> for TcpListener {
265         fn from_inner(socket: Socket) -> TcpListener {
266             TcpListener { inner: socket }
267         }
268     }
269
270     impl fmt::Debug for TcpListener {
271         fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
272             write!(f, "No networking support available on L4Re.")
273         }
274     }
275
276     pub struct UdpSocket {
277         inner: Socket,
278     }
279
280     impl UdpSocket {
281         pub fn bind(_: io::Result<&SocketAddr>) -> io::Result<UdpSocket> {
282             unimpl!();
283         }
284
285         pub fn socket(&self) -> &Socket { &self.inner }
286
287         pub fn into_socket(self) -> Socket { self.inner }
288
289         pub fn socket_addr(&self) -> io::Result<SocketAddr> {
290             unimpl!();
291         }
292
293         pub fn recv_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
294             unimpl!();
295         }
296
297         pub fn peek_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
298             unimpl!();
299         }
300
301         pub fn send_to(&self, _: &[u8], _: &SocketAddr) -> io::Result<usize> {
302             unimpl!();
303         }
304
305         pub fn duplicate(&self) -> io::Result<UdpSocket> {
306             unimpl!();
307         }
308
309         pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
310             unimpl!();
311         }
312
313         pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
314             unimpl!();
315         }
316
317         pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
318             unimpl!();
319         }
320
321         pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
322             unimpl!();
323         }
324
325         pub fn set_broadcast(&self, _: bool) -> io::Result<()> {
326             unimpl!();
327         }
328
329         pub fn broadcast(&self) -> io::Result<bool> {
330             unimpl!();
331         }
332
333         pub fn set_multicast_loop_v4(&self, _: bool) -> io::Result<()> {
334             unimpl!();
335         }
336
337         pub fn multicast_loop_v4(&self) -> io::Result<bool> {
338             unimpl!();
339         }
340
341         pub fn set_multicast_ttl_v4(&self, _: u32) -> io::Result<()> {
342             unimpl!();
343         }
344
345         pub fn multicast_ttl_v4(&self) -> io::Result<u32> {
346             unimpl!();
347         }
348
349         pub fn set_multicast_loop_v6(&self, _: bool) -> io::Result<()> {
350             unimpl!();
351         }
352
353         pub fn multicast_loop_v6(&self) -> io::Result<bool> {
354             unimpl!();
355         }
356
357         pub fn join_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr)
358                              -> io::Result<()> {
359                                  unimpl!();
360         }
361
362         pub fn join_multicast_v6(&self, _: &Ipv6Addr, _: u32)
363                              -> io::Result<()> {
364                                  unimpl!();
365         }
366
367         pub fn leave_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr)
368                               -> io::Result<()> {
369                                   unimpl!();
370         }
371
372         pub fn leave_multicast_v6(&self, _: &Ipv6Addr, _: u32)
373                               -> io::Result<()> {
374                                   unimpl!();
375         }
376
377         pub fn set_ttl(&self, _: u32) -> io::Result<()> {
378             unimpl!();
379         }
380
381         pub fn ttl(&self) -> io::Result<u32> {
382             unimpl!();
383         }
384
385         pub fn take_error(&self) -> io::Result<Option<io::Error>> {
386             unimpl!();
387         }
388
389         pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
390             unimpl!();
391         }
392
393         pub fn recv(&self, _: &mut [u8]) -> io::Result<usize> {
394             unimpl!();
395         }
396
397         pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
398             unimpl!();
399         }
400
401         pub fn send(&self, _: &[u8]) -> io::Result<usize> {
402             unimpl!();
403         }
404
405         pub fn connect(&self, _: io::Result<&SocketAddr>) -> io::Result<()> {
406             unimpl!();
407         }
408     }
409
410     impl FromInner<Socket> for UdpSocket {
411         fn from_inner(socket: Socket) -> UdpSocket {
412             UdpSocket { inner: socket }
413         }
414     }
415
416     impl fmt::Debug for UdpSocket {
417         fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
418             write!(f, "No networking support on L4Re available.")
419         }
420     }
421
422     pub struct LookupHost {
423         original: *mut libc::addrinfo,
424         cur: *mut libc::addrinfo,
425     }
426
427     impl Iterator for LookupHost {
428         type Item = SocketAddr;
429         fn next(&mut self) -> Option<SocketAddr> {
430             None
431         }
432     }
433
434     impl LookupHost {
435         pub fn port(&self) -> u16 {
436             unimpl!();
437         }
438     }
439
440     unsafe impl Sync for LookupHost {}
441     unsafe impl Send for LookupHost {}
442
443
444     impl<'a> TryFrom<&'a str> for LookupHost {
445         type Error = io::Error;
446
447         fn try_from(_v: &'a str) -> io::Result<LookupHost> {
448             unimpl!();
449         }
450     }
451
452     impl<'a> TryFrom<(&'a str, u16)> for LookupHost {
453         type Error = io::Error;
454
455         fn try_from(_v: (&'a str, u16)) -> io::Result<LookupHost> {
456             unimpl!();
457         }
458     }
459 }
460