3 return Err(io::Error::new(io::ErrorKind::Other, "No networking available on L4Re."));
9 use crate::convert::TryFrom;
11 use crate::io::{self, IoSlice, IoSliceMut};
12 use crate::net::{Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr};
13 use crate::sys::fd::FileDesc;
14 use crate::sys_common::{AsInner, FromInner, IntoInner};
15 use crate::time::Duration;
17 #[allow(unused_extern_crates)]
18 pub extern crate libc as netc;
20 pub struct Socket(FileDesc);
22 pub fn new(_: &SocketAddr, _: libc::c_int) -> io::Result<Socket> {
26 pub fn new_raw(_: libc::c_int, _: libc::c_int) -> io::Result<Socket> {
30 pub fn new_pair(_: libc::c_int, _: libc::c_int) -> io::Result<(Socket, Socket)> {
34 pub fn connect_timeout(&self, _: &SocketAddr, _: Duration) -> io::Result<()> {
40 _: *mut libc::sockaddr,
41 _: *mut libc::socklen_t,
42 ) -> io::Result<Socket> {
46 pub fn duplicate(&self) -> io::Result<Socket> {
50 pub fn read(&self, _: &mut [u8]) -> io::Result<usize> {
54 pub fn read_vectored(&self, _: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
58 pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
62 pub fn recv_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
66 pub fn peek_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
70 pub fn write(&self, _: &[u8]) -> io::Result<usize> {
74 pub fn write_vectored(&self, _: &[IoSlice<'_>]) -> io::Result<usize> {
78 pub fn set_timeout(&self, _: Option<Duration>, _: libc::c_int) -> io::Result<()> {
82 pub fn timeout(&self, _: libc::c_int) -> io::Result<Option<Duration>> {
86 pub fn shutdown(&self, _: Shutdown) -> io::Result<()> {
90 pub fn set_nodelay(&self, _: bool) -> io::Result<()> {
94 pub fn nodelay(&self) -> io::Result<bool> {
98 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
102 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
107 impl AsInner<libc::c_int> for Socket {
108 fn as_inner(&self) -> &libc::c_int {
113 impl FromInner<libc::c_int> for Socket {
114 fn from_inner(fd: libc::c_int) -> Socket {
115 Socket(FileDesc::new(fd))
119 impl IntoInner<libc::c_int> for Socket {
120 fn into_inner(self) -> libc::c_int {
125 pub struct TcpStream {
130 pub fn connect(_: io::Result<&SocketAddr>) -> io::Result<TcpStream> {
134 pub fn connect_timeout(_: &SocketAddr, _: Duration) -> io::Result<TcpStream> {
138 pub fn socket(&self) -> &Socket {
142 pub fn into_socket(self) -> Socket {
146 pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
150 pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
154 pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
158 pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
162 pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
166 pub fn read(&self, _: &mut [u8]) -> io::Result<usize> {
170 pub fn read_vectored(&self, _: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
174 pub fn write(&self, _: &[u8]) -> io::Result<usize> {
178 pub fn write_vectored(&self, _: &[IoSlice<'_>]) -> io::Result<usize> {
182 pub fn peer_addr(&self) -> io::Result<SocketAddr> {
186 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
190 pub fn shutdown(&self, _: Shutdown) -> io::Result<()> {
194 pub fn duplicate(&self) -> io::Result<TcpStream> {
198 pub fn set_nodelay(&self, _: bool) -> io::Result<()> {
202 pub fn nodelay(&self) -> io::Result<bool> {
206 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
210 pub fn ttl(&self) -> io::Result<u32> {
214 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
218 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
223 impl FromInner<Socket> for TcpStream {
224 fn from_inner(socket: Socket) -> TcpStream {
225 TcpStream { inner: socket }
229 impl fmt::Debug for TcpStream {
230 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
231 write!(f, "No networking support available on L4Re")
235 pub struct TcpListener {
240 pub fn bind(_: io::Result<&SocketAddr>) -> io::Result<TcpListener> {
244 pub fn socket(&self) -> &Socket {
248 pub fn into_socket(self) -> Socket {
252 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
256 pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
260 pub fn duplicate(&self) -> io::Result<TcpListener> {
264 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
268 pub fn ttl(&self) -> io::Result<u32> {
272 pub fn set_only_v6(&self, _: bool) -> io::Result<()> {
276 pub fn only_v6(&self) -> io::Result<bool> {
280 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
284 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
289 impl FromInner<Socket> for TcpListener {
290 fn from_inner(socket: Socket) -> TcpListener {
291 TcpListener { inner: socket }
295 impl fmt::Debug for TcpListener {
296 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
297 write!(f, "No networking support available on L4Re.")
301 pub struct UdpSocket {
306 pub fn bind(_: io::Result<&SocketAddr>) -> io::Result<UdpSocket> {
310 pub fn socket(&self) -> &Socket {
314 pub fn into_socket(self) -> Socket {
318 pub fn peer_addr(&self) -> io::Result<SocketAddr> {
322 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
326 pub fn recv_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
330 pub fn peek_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
334 pub fn send_to(&self, _: &[u8], _: &SocketAddr) -> io::Result<usize> {
338 pub fn duplicate(&self) -> io::Result<UdpSocket> {
342 pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
346 pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
350 pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
354 pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
358 pub fn set_broadcast(&self, _: bool) -> io::Result<()> {
362 pub fn broadcast(&self) -> io::Result<bool> {
366 pub fn set_multicast_loop_v4(&self, _: bool) -> io::Result<()> {
370 pub fn multicast_loop_v4(&self) -> io::Result<bool> {
374 pub fn set_multicast_ttl_v4(&self, _: u32) -> io::Result<()> {
378 pub fn multicast_ttl_v4(&self) -> io::Result<u32> {
382 pub fn set_multicast_loop_v6(&self, _: bool) -> io::Result<()> {
386 pub fn multicast_loop_v6(&self) -> io::Result<bool> {
390 pub fn join_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) -> io::Result<()> {
394 pub fn join_multicast_v6(&self, _: &Ipv6Addr, _: u32) -> io::Result<()> {
398 pub fn leave_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) -> io::Result<()> {
402 pub fn leave_multicast_v6(&self, _: &Ipv6Addr, _: u32) -> io::Result<()> {
406 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
410 pub fn ttl(&self) -> io::Result<u32> {
414 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
418 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
422 pub fn recv(&self, _: &mut [u8]) -> io::Result<usize> {
426 pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
430 pub fn send(&self, _: &[u8]) -> io::Result<usize> {
434 pub fn connect(&self, _: io::Result<&SocketAddr>) -> io::Result<()> {
439 impl FromInner<Socket> for UdpSocket {
440 fn from_inner(socket: Socket) -> UdpSocket {
441 UdpSocket { inner: socket }
445 impl fmt::Debug for UdpSocket {
446 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
447 write!(f, "No networking support on L4Re available.")
451 pub struct LookupHost {
452 original: *mut libc::addrinfo,
453 cur: *mut libc::addrinfo,
456 impl Iterator for LookupHost {
457 type Item = SocketAddr;
458 fn next(&mut self) -> Option<SocketAddr> {
464 pub fn port(&self) -> u16 {
469 unsafe impl Sync for LookupHost {}
470 unsafe impl Send for LookupHost {}
472 impl TryFrom<&str> for LookupHost {
473 type Error = io::Error;
475 fn try_from(_v: &str) -> io::Result<LookupHost> {
480 impl<'a> TryFrom<(&'a str, u16)> for LookupHost {
481 type Error = io::Error;
483 fn try_from(_v: (&'a str, u16)) -> io::Result<LookupHost> {