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.
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.
12 () => (return Err(io::Error::new(io::ErrorKind::Other, "No networking available on L4Re."));)
20 use net::{SocketAddr, Shutdown, Ipv4Addr, Ipv6Addr};
21 use sys_common::{AsInner, FromInner, IntoInner};
22 use sys::fd::FileDesc;
26 pub extern crate libc as netc;
28 pub struct Socket(FileDesc);
30 pub fn new(_: &SocketAddr, _: libc::c_int) -> io::Result<Socket> {
34 pub fn new_raw(_: libc::c_int, _: libc::c_int) -> io::Result<Socket> {
38 pub fn new_pair(_: libc::c_int, _: libc::c_int) -> io::Result<(Socket, Socket)> {
42 pub fn connect_timeout(&self, _: &SocketAddr, _: Duration) -> io::Result<()> {
46 pub fn accept(&self, _: *mut libc::sockaddr, _: *mut libc::socklen_t)
47 -> io::Result<Socket> {
51 pub fn duplicate(&self) -> io::Result<Socket> {
55 pub fn read(&self, _: &mut [u8]) -> io::Result<usize> {
59 pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
63 pub fn recv_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
67 pub fn peek_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
71 pub fn write(&self, _: &[u8]) -> io::Result<usize> {
75 pub fn set_timeout(&self, _: Option<Duration>, _: libc::c_int) -> io::Result<()> {
79 pub fn timeout(&self, _: libc::c_int) -> io::Result<Option<Duration>> {
83 pub fn shutdown(&self, _: Shutdown) -> io::Result<()> {
87 pub fn set_nodelay(&self, _: bool) -> io::Result<()> {
91 pub fn nodelay(&self) -> io::Result<bool> {
95 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
99 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
104 impl AsInner<libc::c_int> for Socket {
105 fn as_inner(&self) -> &libc::c_int { self.0.as_inner() }
108 impl FromInner<libc::c_int> for Socket {
109 fn from_inner(fd: libc::c_int) -> Socket { Socket(FileDesc::new(fd)) }
112 impl IntoInner<libc::c_int> for Socket {
113 fn into_inner(self) -> libc::c_int { self.0.into_raw() }
116 pub struct TcpStream {
121 pub fn connect(_: io::Result<&SocketAddr>) -> io::Result<TcpStream> {
125 pub fn connect_timeout(_: &SocketAddr, _: Duration) -> io::Result<TcpStream> {
129 pub fn socket(&self) -> &Socket { &self.inner }
131 pub fn into_socket(self) -> Socket { self.inner }
133 pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
137 pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
141 pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
145 pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
149 pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
153 pub fn read(&self, _: &mut [u8]) -> io::Result<usize> {
157 pub fn write(&self, _: &[u8]) -> io::Result<usize> {
161 pub fn peer_addr(&self) -> io::Result<SocketAddr> {
165 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
169 pub fn shutdown(&self, _: Shutdown) -> io::Result<()> {
173 pub fn duplicate(&self) -> io::Result<TcpStream> {
177 pub fn set_nodelay(&self, _: bool) -> io::Result<()> {
181 pub fn nodelay(&self) -> io::Result<bool> {
185 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
189 pub fn ttl(&self) -> io::Result<u32> {
193 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
197 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
202 impl FromInner<Socket> for TcpStream {
203 fn from_inner(socket: Socket) -> TcpStream {
204 TcpStream { inner: socket }
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")
214 pub struct TcpListener {
219 pub fn bind(_: io::Result<&SocketAddr>) -> io::Result<TcpListener> {
223 pub fn socket(&self) -> &Socket { &self.inner }
225 pub fn into_socket(self) -> Socket { self.inner }
227 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
231 pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
235 pub fn duplicate(&self) -> io::Result<TcpListener> {
239 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
243 pub fn ttl(&self) -> io::Result<u32> {
247 pub fn set_only_v6(&self, _: bool) -> io::Result<()> {
251 pub fn only_v6(&self) -> io::Result<bool> {
255 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
259 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
264 impl FromInner<Socket> for TcpListener {
265 fn from_inner(socket: Socket) -> TcpListener {
266 TcpListener { inner: socket }
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.")
276 pub struct UdpSocket {
281 pub fn bind(_: io::Result<&SocketAddr>) -> io::Result<UdpSocket> {
285 pub fn socket(&self) -> &Socket { &self.inner }
287 pub fn into_socket(self) -> Socket { self.inner }
289 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
293 pub fn recv_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
297 pub fn peek_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
301 pub fn send_to(&self, _: &[u8], _: &SocketAddr) -> io::Result<usize> {
305 pub fn duplicate(&self) -> io::Result<UdpSocket> {
309 pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
313 pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
317 pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
321 pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
325 pub fn set_broadcast(&self, _: bool) -> io::Result<()> {
329 pub fn broadcast(&self) -> io::Result<bool> {
333 pub fn set_multicast_loop_v4(&self, _: bool) -> io::Result<()> {
337 pub fn multicast_loop_v4(&self) -> io::Result<bool> {
341 pub fn set_multicast_ttl_v4(&self, _: u32) -> io::Result<()> {
345 pub fn multicast_ttl_v4(&self) -> io::Result<u32> {
349 pub fn set_multicast_loop_v6(&self, _: bool) -> io::Result<()> {
353 pub fn multicast_loop_v6(&self) -> io::Result<bool> {
357 pub fn join_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr)
362 pub fn join_multicast_v6(&self, _: &Ipv6Addr, _: u32)
367 pub fn leave_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr)
372 pub fn leave_multicast_v6(&self, _: &Ipv6Addr, _: u32)
377 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
381 pub fn ttl(&self) -> io::Result<u32> {
385 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
389 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
393 pub fn recv(&self, _: &mut [u8]) -> io::Result<usize> {
397 pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
401 pub fn send(&self, _: &[u8]) -> io::Result<usize> {
405 pub fn connect(&self, _: io::Result<&SocketAddr>) -> io::Result<()> {
410 impl FromInner<Socket> for UdpSocket {
411 fn from_inner(socket: Socket) -> UdpSocket {
412 UdpSocket { inner: socket }
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.")
422 pub struct LookupHost {
423 original: *mut libc::addrinfo,
424 cur: *mut libc::addrinfo,
427 impl Iterator for LookupHost {
428 type Item = SocketAddr;
429 fn next(&mut self) -> Option<SocketAddr> {
435 pub fn port(&self) -> u16 {
440 unsafe impl Sync for LookupHost {}
441 unsafe impl Send for LookupHost {}
444 impl<'a> TryFrom<&'a str> for LookupHost {
445 type Error = io::Error;
447 fn try_from(_v: &'a str) -> io::Result<LookupHost> {
452 impl<'a> TryFrom<(&'a str, u16)> for LookupHost {
453 type Error = io::Error;
455 fn try_from(_v: (&'a str, u16)) -> io::Result<LookupHost> {