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_linger(&self, _: Option<Duration>) -> io::Result<()> {
105 pub fn linger(&self) -> io::Result<Option<Duration>> {
109 pub fn set_nodelay(&self, _: bool) -> io::Result<()> {
113 pub fn nodelay(&self) -> io::Result<bool> {
117 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
121 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
126 impl AsInner<libc::c_int> for Socket {
127 fn as_inner(&self) -> &libc::c_int {
132 impl FromInner<libc::c_int> for Socket {
133 fn from_inner(fd: libc::c_int) -> Socket {
134 Socket(FileDesc::new(fd))
138 impl IntoInner<libc::c_int> for Socket {
139 fn into_inner(self) -> libc::c_int {
144 pub struct TcpStream {
149 pub fn connect(_: io::Result<&SocketAddr>) -> io::Result<TcpStream> {
153 pub fn connect_timeout(_: &SocketAddr, _: Duration) -> io::Result<TcpStream> {
157 pub fn socket(&self) -> &Socket {
161 pub fn into_socket(self) -> Socket {
165 pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
169 pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
173 pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
177 pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
181 pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
185 pub fn read(&self, _: &mut [u8]) -> io::Result<usize> {
189 pub fn read_vectored(&self, _: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
193 pub fn is_read_vectored(&self) -> bool {
197 pub fn write(&self, _: &[u8]) -> io::Result<usize> {
201 pub fn write_vectored(&self, _: &[IoSlice<'_>]) -> io::Result<usize> {
205 pub fn is_write_vectored(&self) -> bool {
209 pub fn peer_addr(&self) -> io::Result<SocketAddr> {
213 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
217 pub fn shutdown(&self, _: Shutdown) -> io::Result<()> {
221 pub fn duplicate(&self) -> io::Result<TcpStream> {
225 pub fn set_linger(&self, _: Option<Duration>) -> io::Result<()> {
229 pub fn linger(&self) -> io::Result<Option<Duration>> {
233 pub fn set_nodelay(&self, _: bool) -> io::Result<()> {
237 pub fn nodelay(&self) -> io::Result<bool> {
241 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
245 pub fn ttl(&self) -> io::Result<u32> {
249 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
253 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
258 impl FromInner<Socket> for TcpStream {
259 fn from_inner(socket: Socket) -> TcpStream {
260 TcpStream { inner: socket }
264 impl fmt::Debug for TcpStream {
265 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
266 write!(f, "No networking support available on L4Re")
270 pub struct TcpListener {
275 pub fn bind(_: io::Result<&SocketAddr>) -> io::Result<TcpListener> {
279 pub fn socket(&self) -> &Socket {
283 pub fn into_socket(self) -> Socket {
287 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
291 pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
295 pub fn duplicate(&self) -> io::Result<TcpListener> {
299 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
303 pub fn ttl(&self) -> io::Result<u32> {
307 pub fn set_only_v6(&self, _: bool) -> io::Result<()> {
311 pub fn only_v6(&self) -> io::Result<bool> {
315 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
319 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
324 impl FromInner<Socket> for TcpListener {
325 fn from_inner(socket: Socket) -> TcpListener {
326 TcpListener { inner: socket }
330 impl fmt::Debug for TcpListener {
331 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
332 write!(f, "No networking support available on L4Re.")
336 pub struct UdpSocket {
341 pub fn bind(_: io::Result<&SocketAddr>) -> io::Result<UdpSocket> {
345 pub fn socket(&self) -> &Socket {
349 pub fn into_socket(self) -> Socket {
353 pub fn peer_addr(&self) -> io::Result<SocketAddr> {
357 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
361 pub fn recv_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
365 pub fn peek_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
369 pub fn send_to(&self, _: &[u8], _: &SocketAddr) -> io::Result<usize> {
373 pub fn duplicate(&self) -> io::Result<UdpSocket> {
377 pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
381 pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
385 pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
389 pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
393 pub fn set_broadcast(&self, _: bool) -> io::Result<()> {
397 pub fn broadcast(&self) -> io::Result<bool> {
401 pub fn set_multicast_loop_v4(&self, _: bool) -> io::Result<()> {
405 pub fn multicast_loop_v4(&self) -> io::Result<bool> {
409 pub fn set_multicast_ttl_v4(&self, _: u32) -> io::Result<()> {
413 pub fn multicast_ttl_v4(&self) -> io::Result<u32> {
417 pub fn set_multicast_loop_v6(&self, _: bool) -> io::Result<()> {
421 pub fn multicast_loop_v6(&self) -> io::Result<bool> {
425 pub fn join_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) -> io::Result<()> {
429 pub fn join_multicast_v6(&self, _: &Ipv6Addr, _: u32) -> io::Result<()> {
433 pub fn leave_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) -> io::Result<()> {
437 pub fn leave_multicast_v6(&self, _: &Ipv6Addr, _: u32) -> io::Result<()> {
441 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
445 pub fn ttl(&self) -> io::Result<u32> {
449 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
453 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
457 pub fn recv(&self, _: &mut [u8]) -> io::Result<usize> {
461 pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
465 pub fn send(&self, _: &[u8]) -> io::Result<usize> {
469 pub fn connect(&self, _: io::Result<&SocketAddr>) -> io::Result<()> {
474 impl FromInner<Socket> for UdpSocket {
475 fn from_inner(socket: Socket) -> UdpSocket {
476 UdpSocket { inner: socket }
480 impl fmt::Debug for UdpSocket {
481 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
482 write!(f, "No networking support on L4Re available.")
486 pub struct LookupHost {
487 original: *mut libc::addrinfo,
488 cur: *mut libc::addrinfo,
491 impl Iterator for LookupHost {
492 type Item = SocketAddr;
493 fn next(&mut self) -> Option<SocketAddr> {
499 pub fn port(&self) -> u16 {
504 unsafe impl Sync for LookupHost {}
505 unsafe impl Send for LookupHost {}
507 impl TryFrom<&str> for LookupHost {
508 type Error = io::Error;
510 fn try_from(_v: &str) -> io::Result<LookupHost> {
515 impl<'a> TryFrom<(&'a str, u16)> for LookupHost {
516 type Error = io::Error;
518 fn try_from(_v: (&'a str, u16)) -> io::Result<LookupHost> {