3 return Err(io::Error::new_const(
4 io::ErrorKind::Unsupported,
5 &"No networking available on L4Re.",
12 use crate::convert::TryFrom;
14 use crate::io::{self, IoSlice, IoSliceMut};
15 use crate::net::{Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr};
16 use crate::sys::fd::FileDesc;
17 use crate::sys_common::{AsInner, FromInner, IntoInner};
18 use crate::time::Duration;
20 #[allow(unused_extern_crates)]
21 pub extern crate libc as netc;
23 pub struct Socket(FileDesc);
25 pub fn new(_: &SocketAddr, _: libc::c_int) -> io::Result<Socket> {
29 pub fn new_raw(_: libc::c_int, _: libc::c_int) -> io::Result<Socket> {
33 pub fn new_pair(_: libc::c_int, _: libc::c_int) -> io::Result<(Socket, Socket)> {
37 pub fn connect_timeout(&self, _: &SocketAddr, _: Duration) -> io::Result<()> {
43 _: *mut libc::sockaddr,
44 _: *mut libc::socklen_t,
45 ) -> io::Result<Socket> {
49 pub fn duplicate(&self) -> io::Result<Socket> {
53 pub fn read(&self, _: &mut [u8]) -> io::Result<usize> {
57 pub fn read_vectored(&self, _: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
61 pub fn is_read_vectored(&self) -> bool {
65 pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
69 pub fn recv_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
73 pub fn peek_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
77 pub fn write(&self, _: &[u8]) -> io::Result<usize> {
81 pub fn write_vectored(&self, _: &[IoSlice<'_>]) -> io::Result<usize> {
85 pub fn is_write_vectored(&self) -> bool {
89 pub fn set_timeout(&self, _: Option<Duration>, _: libc::c_int) -> io::Result<()> {
93 pub fn timeout(&self, _: libc::c_int) -> io::Result<Option<Duration>> {
97 pub fn shutdown(&self, _: Shutdown) -> io::Result<()> {
101 pub fn set_nodelay(&self, _: bool) -> io::Result<()> {
105 pub fn nodelay(&self) -> io::Result<bool> {
109 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
113 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
118 impl AsInner<libc::c_int> for Socket {
119 fn as_inner(&self) -> &libc::c_int {
124 impl FromInner<libc::c_int> for Socket {
125 fn from_inner(fd: libc::c_int) -> Socket {
126 Socket(FileDesc::new(fd))
130 impl IntoInner<libc::c_int> for Socket {
131 fn into_inner(self) -> libc::c_int {
136 pub struct TcpStream {
141 pub fn connect(_: io::Result<&SocketAddr>) -> io::Result<TcpStream> {
145 pub fn connect_timeout(_: &SocketAddr, _: Duration) -> io::Result<TcpStream> {
149 pub fn socket(&self) -> &Socket {
153 pub fn into_socket(self) -> Socket {
157 pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
161 pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
165 pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
169 pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
173 pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
177 pub fn read(&self, _: &mut [u8]) -> io::Result<usize> {
181 pub fn read_vectored(&self, _: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
185 pub fn is_read_vectored(&self) -> bool {
189 pub fn write(&self, _: &[u8]) -> io::Result<usize> {
193 pub fn write_vectored(&self, _: &[IoSlice<'_>]) -> io::Result<usize> {
197 pub fn is_write_vectored(&self) -> bool {
201 pub fn peer_addr(&self) -> io::Result<SocketAddr> {
205 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
209 pub fn shutdown(&self, _: Shutdown) -> io::Result<()> {
213 pub fn duplicate(&self) -> io::Result<TcpStream> {
217 pub fn set_nodelay(&self, _: bool) -> io::Result<()> {
221 pub fn nodelay(&self) -> io::Result<bool> {
225 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
229 pub fn ttl(&self) -> io::Result<u32> {
233 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
237 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
242 impl FromInner<Socket> for TcpStream {
243 fn from_inner(socket: Socket) -> TcpStream {
244 TcpStream { inner: socket }
248 impl fmt::Debug for TcpStream {
249 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
250 write!(f, "No networking support available on L4Re")
254 pub struct TcpListener {
259 pub fn bind(_: io::Result<&SocketAddr>) -> io::Result<TcpListener> {
263 pub fn socket(&self) -> &Socket {
267 pub fn into_socket(self) -> Socket {
271 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
275 pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
279 pub fn duplicate(&self) -> io::Result<TcpListener> {
283 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
287 pub fn ttl(&self) -> io::Result<u32> {
291 pub fn set_only_v6(&self, _: bool) -> io::Result<()> {
295 pub fn only_v6(&self) -> io::Result<bool> {
299 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
303 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
308 impl FromInner<Socket> for TcpListener {
309 fn from_inner(socket: Socket) -> TcpListener {
310 TcpListener { inner: socket }
314 impl fmt::Debug for TcpListener {
315 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
316 write!(f, "No networking support available on L4Re.")
320 pub struct UdpSocket {
325 pub fn bind(_: io::Result<&SocketAddr>) -> io::Result<UdpSocket> {
329 pub fn socket(&self) -> &Socket {
333 pub fn into_socket(self) -> Socket {
337 pub fn peer_addr(&self) -> io::Result<SocketAddr> {
341 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
345 pub fn recv_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
349 pub fn peek_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
353 pub fn send_to(&self, _: &[u8], _: &SocketAddr) -> io::Result<usize> {
357 pub fn duplicate(&self) -> io::Result<UdpSocket> {
361 pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
365 pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
369 pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
373 pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
377 pub fn set_broadcast(&self, _: bool) -> io::Result<()> {
381 pub fn broadcast(&self) -> io::Result<bool> {
385 pub fn set_multicast_loop_v4(&self, _: bool) -> io::Result<()> {
389 pub fn multicast_loop_v4(&self) -> io::Result<bool> {
393 pub fn set_multicast_ttl_v4(&self, _: u32) -> io::Result<()> {
397 pub fn multicast_ttl_v4(&self) -> io::Result<u32> {
401 pub fn set_multicast_loop_v6(&self, _: bool) -> io::Result<()> {
405 pub fn multicast_loop_v6(&self) -> io::Result<bool> {
409 pub fn join_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) -> io::Result<()> {
413 pub fn join_multicast_v6(&self, _: &Ipv6Addr, _: u32) -> io::Result<()> {
417 pub fn leave_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) -> io::Result<()> {
421 pub fn leave_multicast_v6(&self, _: &Ipv6Addr, _: u32) -> io::Result<()> {
425 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
429 pub fn ttl(&self) -> io::Result<u32> {
433 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
437 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
441 pub fn recv(&self, _: &mut [u8]) -> io::Result<usize> {
445 pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
449 pub fn send(&self, _: &[u8]) -> io::Result<usize> {
453 pub fn connect(&self, _: io::Result<&SocketAddr>) -> io::Result<()> {
458 impl FromInner<Socket> for UdpSocket {
459 fn from_inner(socket: Socket) -> UdpSocket {
460 UdpSocket { inner: socket }
464 impl fmt::Debug for UdpSocket {
465 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
466 write!(f, "No networking support on L4Re available.")
470 pub struct LookupHost {
471 original: *mut libc::addrinfo,
472 cur: *mut libc::addrinfo,
475 impl Iterator for LookupHost {
476 type Item = SocketAddr;
477 fn next(&mut self) -> Option<SocketAddr> {
483 pub fn port(&self) -> u16 {
488 unsafe impl Sync for LookupHost {}
489 unsafe impl Send for LookupHost {}
491 impl TryFrom<&str> for LookupHost {
492 type Error = io::Error;
494 fn try_from(_v: &str) -> io::Result<LookupHost> {
499 impl<'a> TryFrom<(&'a str, u16)> for LookupHost {
500 type Error = io::Error;
502 fn try_from(_v: (&'a str, u16)) -> io::Result<LookupHost> {