2 () => (return Err(io::Error::new(io::ErrorKind::Other, "No networking available on L4Re."));)
8 use crate::io::{self, IoSlice, IoSliceMut};
9 use crate::net::{SocketAddr, Shutdown, Ipv4Addr, Ipv6Addr};
10 use crate::sys_common::{AsInner, FromInner, IntoInner};
11 use crate::sys::fd::FileDesc;
12 use crate::time::Duration;
13 use crate::convert::TryFrom;
15 #[allow(unused_extern_crates)]
16 pub extern crate libc as netc;
18 pub struct Socket(FileDesc);
20 pub fn new(_: &SocketAddr, _: libc::c_int) -> io::Result<Socket> {
24 pub fn new_raw(_: libc::c_int, _: libc::c_int) -> io::Result<Socket> {
28 pub fn new_pair(_: libc::c_int, _: libc::c_int) -> io::Result<(Socket, Socket)> {
32 pub fn connect_timeout(&self, _: &SocketAddr, _: Duration) -> io::Result<()> {
36 pub fn accept(&self, _: *mut libc::sockaddr, _: *mut libc::socklen_t)
37 -> io::Result<Socket> {
41 pub fn duplicate(&self) -> io::Result<Socket> {
45 pub fn read(&self, _: &mut [u8]) -> io::Result<usize> {
49 pub fn read_vectored(&self, _: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
53 pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
57 pub fn recv_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
61 pub fn peek_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
65 pub fn write(&self, _: &[u8]) -> io::Result<usize> {
69 pub fn write_vectored(&self, _: &[IoSlice<'_>]) -> io::Result<usize> {
73 pub fn set_timeout(&self, _: Option<Duration>, _: libc::c_int) -> io::Result<()> {
77 pub fn timeout(&self, _: libc::c_int) -> io::Result<Option<Duration>> {
81 pub fn shutdown(&self, _: Shutdown) -> io::Result<()> {
85 pub fn set_nodelay(&self, _: bool) -> io::Result<()> {
89 pub fn nodelay(&self) -> io::Result<bool> {
93 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
97 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
102 impl AsInner<libc::c_int> for Socket {
103 fn as_inner(&self) -> &libc::c_int { self.0.as_inner() }
106 impl FromInner<libc::c_int> for Socket {
107 fn from_inner(fd: libc::c_int) -> Socket { Socket(FileDesc::new(fd)) }
110 impl IntoInner<libc::c_int> for Socket {
111 fn into_inner(self) -> libc::c_int { self.0.into_raw() }
114 pub struct TcpStream {
119 pub fn connect(_: io::Result<&SocketAddr>) -> io::Result<TcpStream> {
123 pub fn connect_timeout(_: &SocketAddr, _: Duration) -> io::Result<TcpStream> {
127 pub fn socket(&self) -> &Socket { &self.inner }
129 pub fn into_socket(self) -> Socket { self.inner }
131 pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
135 pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
139 pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
143 pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
147 pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
151 pub fn read(&self, _: &mut [u8]) -> io::Result<usize> {
155 pub fn read_vectored(&self, _: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
159 pub fn write(&self, _: &[u8]) -> io::Result<usize> {
163 pub fn write_vectored(&self, _: &[IoSlice<'_>]) -> io::Result<usize> {
167 pub fn peer_addr(&self) -> io::Result<SocketAddr> {
171 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
175 pub fn shutdown(&self, _: Shutdown) -> io::Result<()> {
179 pub fn duplicate(&self) -> io::Result<TcpStream> {
183 pub fn set_nodelay(&self, _: bool) -> io::Result<()> {
187 pub fn nodelay(&self) -> io::Result<bool> {
191 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
195 pub fn ttl(&self) -> io::Result<u32> {
199 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
203 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
208 impl FromInner<Socket> for TcpStream {
209 fn from_inner(socket: Socket) -> TcpStream {
210 TcpStream { inner: socket }
214 impl fmt::Debug for TcpStream {
215 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
216 write!(f, "No networking support available on L4Re")
220 pub struct TcpListener {
225 pub fn bind(_: io::Result<&SocketAddr>) -> io::Result<TcpListener> {
229 pub fn socket(&self) -> &Socket { &self.inner }
231 pub fn into_socket(self) -> Socket { self.inner }
233 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
237 pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
241 pub fn duplicate(&self) -> io::Result<TcpListener> {
245 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
249 pub fn ttl(&self) -> io::Result<u32> {
253 pub fn set_only_v6(&self, _: bool) -> io::Result<()> {
257 pub fn only_v6(&self) -> io::Result<bool> {
261 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
265 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
270 impl FromInner<Socket> for TcpListener {
271 fn from_inner(socket: Socket) -> TcpListener {
272 TcpListener { inner: socket }
276 impl fmt::Debug for TcpListener {
277 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
278 write!(f, "No networking support available on L4Re.")
282 pub struct UdpSocket {
287 pub fn bind(_: io::Result<&SocketAddr>) -> io::Result<UdpSocket> {
291 pub fn socket(&self) -> &Socket { &self.inner }
293 pub fn into_socket(self) -> Socket { self.inner }
295 pub fn peer_addr(&self) -> io::Result<SocketAddr> {
299 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
303 pub fn recv_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
307 pub fn peek_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
311 pub fn send_to(&self, _: &[u8], _: &SocketAddr) -> io::Result<usize> {
315 pub fn duplicate(&self) -> io::Result<UdpSocket> {
319 pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
323 pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
327 pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
331 pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
335 pub fn set_broadcast(&self, _: bool) -> io::Result<()> {
339 pub fn broadcast(&self) -> io::Result<bool> {
343 pub fn set_multicast_loop_v4(&self, _: bool) -> io::Result<()> {
347 pub fn multicast_loop_v4(&self) -> io::Result<bool> {
351 pub fn set_multicast_ttl_v4(&self, _: u32) -> io::Result<()> {
355 pub fn multicast_ttl_v4(&self) -> io::Result<u32> {
359 pub fn set_multicast_loop_v6(&self, _: bool) -> io::Result<()> {
363 pub fn multicast_loop_v6(&self) -> io::Result<bool> {
367 pub fn join_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr)
372 pub fn join_multicast_v6(&self, _: &Ipv6Addr, _: u32)
377 pub fn leave_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr)
382 pub fn leave_multicast_v6(&self, _: &Ipv6Addr, _: u32)
387 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
391 pub fn ttl(&self) -> io::Result<u32> {
395 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
399 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
403 pub fn recv(&self, _: &mut [u8]) -> io::Result<usize> {
407 pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
411 pub fn send(&self, _: &[u8]) -> io::Result<usize> {
415 pub fn connect(&self, _: io::Result<&SocketAddr>) -> io::Result<()> {
420 impl FromInner<Socket> for UdpSocket {
421 fn from_inner(socket: Socket) -> UdpSocket {
422 UdpSocket { inner: socket }
426 impl fmt::Debug for UdpSocket {
427 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
428 write!(f, "No networking support on L4Re available.")
432 pub struct LookupHost {
433 original: *mut libc::addrinfo,
434 cur: *mut libc::addrinfo,
437 impl Iterator for LookupHost {
438 type Item = SocketAddr;
439 fn next(&mut self) -> Option<SocketAddr> {
445 pub fn port(&self) -> u16 {
450 unsafe impl Sync for LookupHost {}
451 unsafe impl Send for LookupHost {}
454 impl TryFrom<&str> for LookupHost {
455 type Error = io::Error;
457 fn try_from(_v: &str) -> io::Result<LookupHost> {
462 impl<'a> TryFrom<(&'a str, u16)> for LookupHost {
463 type Error = io::Error;
465 fn try_from(_v: (&'a str, u16)) -> io::Result<LookupHost> {