3 return Err(io::const_io_error!(
4 io::ErrorKind::Unsupported,
5 "No networking available on L4Re.",
13 use crate::io::{self, IoSlice, IoSliceMut};
14 use crate::net::{Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr};
15 use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
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>> {
125 // This is used by sys_common code to abstract over Windows and Unix.
126 pub fn as_raw(&self) -> RawFd {
131 impl AsInner<FileDesc> for Socket {
132 fn as_inner(&self) -> &FileDesc {
137 impl FromInner<FileDesc> for Socket {
138 fn from_inner(file_desc: FileDesc) -> Socket {
143 impl IntoInner<FileDesc> for Socket {
144 fn into_inner(self) -> FileDesc {
149 impl AsFd for Socket {
150 fn as_fd(&self) -> BorrowedFd<'_> {
155 impl AsRawFd for Socket {
156 fn as_raw_fd(&self) -> RawFd {
161 impl IntoRawFd for Socket {
162 fn into_raw_fd(self) -> RawFd {
167 impl FromRawFd for Socket {
168 unsafe fn from_raw_fd(raw_fd: RawFd) -> Self {
169 Self(FromRawFd::from_raw_fd(raw_fd))
173 pub struct TcpStream {
178 pub fn connect(_: io::Result<&SocketAddr>) -> io::Result<TcpStream> {
182 pub fn connect_timeout(_: &SocketAddr, _: Duration) -> io::Result<TcpStream> {
186 pub fn socket(&self) -> &Socket {
190 pub fn into_socket(self) -> Socket {
194 pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
198 pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
202 pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
206 pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
210 pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
214 pub fn read(&self, _: &mut [u8]) -> io::Result<usize> {
218 pub fn read_vectored(&self, _: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
222 pub fn is_read_vectored(&self) -> bool {
226 pub fn write(&self, _: &[u8]) -> io::Result<usize> {
230 pub fn write_vectored(&self, _: &[IoSlice<'_>]) -> io::Result<usize> {
234 pub fn is_write_vectored(&self) -> bool {
238 pub fn peer_addr(&self) -> io::Result<SocketAddr> {
242 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
246 pub fn shutdown(&self, _: Shutdown) -> io::Result<()> {
250 pub fn duplicate(&self) -> io::Result<TcpStream> {
254 pub fn set_linger(&self, _: Option<Duration>) -> io::Result<()> {
258 pub fn linger(&self) -> io::Result<Option<Duration>> {
262 pub fn set_nodelay(&self, _: bool) -> io::Result<()> {
266 pub fn nodelay(&self) -> io::Result<bool> {
270 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
274 pub fn ttl(&self) -> io::Result<u32> {
278 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
282 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
287 impl FromInner<Socket> for TcpStream {
288 fn from_inner(socket: Socket) -> TcpStream {
289 TcpStream { inner: socket }
293 impl fmt::Debug for TcpStream {
294 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
295 write!(f, "No networking support available on L4Re")
299 pub struct TcpListener {
304 pub fn bind(_: io::Result<&SocketAddr>) -> io::Result<TcpListener> {
308 pub fn socket(&self) -> &Socket {
312 pub fn into_socket(self) -> Socket {
316 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
320 pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
324 pub fn duplicate(&self) -> io::Result<TcpListener> {
328 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
332 pub fn ttl(&self) -> io::Result<u32> {
336 pub fn set_only_v6(&self, _: bool) -> io::Result<()> {
340 pub fn only_v6(&self) -> io::Result<bool> {
344 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
348 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
353 impl FromInner<Socket> for TcpListener {
354 fn from_inner(socket: Socket) -> TcpListener {
355 TcpListener { inner: socket }
359 impl fmt::Debug for TcpListener {
360 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
361 write!(f, "No networking support available on L4Re.")
365 pub struct UdpSocket {
370 pub fn bind(_: io::Result<&SocketAddr>) -> io::Result<UdpSocket> {
374 pub fn socket(&self) -> &Socket {
378 pub fn into_socket(self) -> Socket {
382 pub fn peer_addr(&self) -> io::Result<SocketAddr> {
386 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
390 pub fn recv_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
394 pub fn peek_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
398 pub fn send_to(&self, _: &[u8], _: &SocketAddr) -> io::Result<usize> {
402 pub fn duplicate(&self) -> io::Result<UdpSocket> {
406 pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
410 pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
414 pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
418 pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
422 pub fn set_broadcast(&self, _: bool) -> io::Result<()> {
426 pub fn broadcast(&self) -> io::Result<bool> {
430 pub fn set_multicast_loop_v4(&self, _: bool) -> io::Result<()> {
434 pub fn multicast_loop_v4(&self) -> io::Result<bool> {
438 pub fn set_multicast_ttl_v4(&self, _: u32) -> io::Result<()> {
442 pub fn multicast_ttl_v4(&self) -> io::Result<u32> {
446 pub fn set_multicast_loop_v6(&self, _: bool) -> io::Result<()> {
450 pub fn multicast_loop_v6(&self) -> io::Result<bool> {
454 pub fn join_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) -> io::Result<()> {
458 pub fn join_multicast_v6(&self, _: &Ipv6Addr, _: u32) -> io::Result<()> {
462 pub fn leave_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) -> io::Result<()> {
466 pub fn leave_multicast_v6(&self, _: &Ipv6Addr, _: u32) -> io::Result<()> {
470 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
474 pub fn ttl(&self) -> io::Result<u32> {
478 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
482 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
486 pub fn recv(&self, _: &mut [u8]) -> io::Result<usize> {
490 pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
494 pub fn send(&self, _: &[u8]) -> io::Result<usize> {
498 pub fn connect(&self, _: io::Result<&SocketAddr>) -> io::Result<()> {
503 impl FromInner<Socket> for UdpSocket {
504 fn from_inner(socket: Socket) -> UdpSocket {
505 UdpSocket { inner: socket }
509 impl fmt::Debug for UdpSocket {
510 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
511 write!(f, "No networking support on L4Re available.")
515 pub struct LookupHost {
516 original: *mut libc::addrinfo,
517 cur: *mut libc::addrinfo,
520 impl Iterator for LookupHost {
521 type Item = SocketAddr;
522 fn next(&mut self) -> Option<SocketAddr> {
528 pub fn port(&self) -> u16 {
533 unsafe impl Sync for LookupHost {}
534 unsafe impl Send for LookupHost {}
536 impl TryFrom<&str> for LookupHost {
537 type Error = io::Error;
539 fn try_from(_v: &str) -> io::Result<LookupHost> {
544 impl<'a> TryFrom<(&'a str, u16)> for LookupHost {
545 type Error = io::Error;
547 fn try_from(_v: (&'a str, u16)) -> io::Result<LookupHost> {