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 is_read_vectored(&self) -> bool {
62 pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
66 pub fn recv_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
70 pub fn peek_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
74 pub fn write(&self, _: &[u8]) -> io::Result<usize> {
78 pub fn write_vectored(&self, _: &[IoSlice<'_>]) -> io::Result<usize> {
82 pub fn is_write_vectored(&self) -> bool {
86 pub fn set_timeout(&self, _: Option<Duration>, _: libc::c_int) -> io::Result<()> {
90 pub fn timeout(&self, _: libc::c_int) -> io::Result<Option<Duration>> {
94 pub fn shutdown(&self, _: Shutdown) -> io::Result<()> {
98 pub fn set_nodelay(&self, _: bool) -> io::Result<()> {
102 pub fn nodelay(&self) -> io::Result<bool> {
106 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
110 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
115 impl AsInner<libc::c_int> for Socket {
116 fn as_inner(&self) -> &libc::c_int {
121 impl FromInner<libc::c_int> for Socket {
122 fn from_inner(fd: libc::c_int) -> Socket {
123 Socket(FileDesc::new(fd))
127 impl IntoInner<libc::c_int> for Socket {
128 fn into_inner(self) -> libc::c_int {
133 pub struct TcpStream {
138 pub fn connect(_: io::Result<&SocketAddr>) -> io::Result<TcpStream> {
142 pub fn connect_timeout(_: &SocketAddr, _: Duration) -> io::Result<TcpStream> {
146 pub fn socket(&self) -> &Socket {
150 pub fn into_socket(self) -> Socket {
154 pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
158 pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
162 pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
166 pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
170 pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
174 pub fn read(&self, _: &mut [u8]) -> io::Result<usize> {
178 pub fn read_vectored(&self, _: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
182 pub fn is_read_vectored(&self) -> bool {
186 pub fn write(&self, _: &[u8]) -> io::Result<usize> {
190 pub fn write_vectored(&self, _: &[IoSlice<'_>]) -> io::Result<usize> {
194 pub fn is_write_vectored(&self) -> bool {
198 pub fn peer_addr(&self) -> io::Result<SocketAddr> {
202 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
206 pub fn shutdown(&self, _: Shutdown) -> io::Result<()> {
210 pub fn duplicate(&self) -> io::Result<TcpStream> {
214 pub fn set_nodelay(&self, _: bool) -> io::Result<()> {
218 pub fn nodelay(&self) -> io::Result<bool> {
222 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
226 pub fn ttl(&self) -> io::Result<u32> {
230 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
234 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
239 impl FromInner<Socket> for TcpStream {
240 fn from_inner(socket: Socket) -> TcpStream {
241 TcpStream { inner: socket }
245 impl fmt::Debug for TcpStream {
246 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
247 write!(f, "No networking support available on L4Re")
251 pub struct TcpListener {
256 pub fn bind(_: io::Result<&SocketAddr>) -> io::Result<TcpListener> {
260 pub fn socket(&self) -> &Socket {
264 pub fn into_socket(self) -> Socket {
268 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
272 pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
276 pub fn duplicate(&self) -> io::Result<TcpListener> {
280 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
284 pub fn ttl(&self) -> io::Result<u32> {
288 pub fn set_only_v6(&self, _: bool) -> io::Result<()> {
292 pub fn only_v6(&self) -> io::Result<bool> {
296 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
300 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
305 impl FromInner<Socket> for TcpListener {
306 fn from_inner(socket: Socket) -> TcpListener {
307 TcpListener { inner: socket }
311 impl fmt::Debug for TcpListener {
312 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
313 write!(f, "No networking support available on L4Re.")
317 pub struct UdpSocket {
322 pub fn bind(_: io::Result<&SocketAddr>) -> io::Result<UdpSocket> {
326 pub fn socket(&self) -> &Socket {
330 pub fn into_socket(self) -> Socket {
334 pub fn peer_addr(&self) -> io::Result<SocketAddr> {
338 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
342 pub fn recv_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
346 pub fn peek_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
350 pub fn send_to(&self, _: &[u8], _: &SocketAddr) -> io::Result<usize> {
354 pub fn duplicate(&self) -> io::Result<UdpSocket> {
358 pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
362 pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
366 pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
370 pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
374 pub fn set_broadcast(&self, _: bool) -> io::Result<()> {
378 pub fn broadcast(&self) -> io::Result<bool> {
382 pub fn set_multicast_loop_v4(&self, _: bool) -> io::Result<()> {
386 pub fn multicast_loop_v4(&self) -> io::Result<bool> {
390 pub fn set_multicast_ttl_v4(&self, _: u32) -> io::Result<()> {
394 pub fn multicast_ttl_v4(&self) -> io::Result<u32> {
398 pub fn set_multicast_loop_v6(&self, _: bool) -> io::Result<()> {
402 pub fn multicast_loop_v6(&self) -> io::Result<bool> {
406 pub fn join_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) -> io::Result<()> {
410 pub fn join_multicast_v6(&self, _: &Ipv6Addr, _: u32) -> io::Result<()> {
414 pub fn leave_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) -> io::Result<()> {
418 pub fn leave_multicast_v6(&self, _: &Ipv6Addr, _: u32) -> io::Result<()> {
422 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
426 pub fn ttl(&self) -> io::Result<u32> {
430 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
434 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
438 pub fn recv(&self, _: &mut [u8]) -> io::Result<usize> {
442 pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
446 pub fn send(&self, _: &[u8]) -> io::Result<usize> {
450 pub fn connect(&self, _: io::Result<&SocketAddr>) -> io::Result<()> {
455 impl FromInner<Socket> for UdpSocket {
456 fn from_inner(socket: Socket) -> UdpSocket {
457 UdpSocket { inner: socket }
461 impl fmt::Debug for UdpSocket {
462 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
463 write!(f, "No networking support on L4Re available.")
467 pub struct LookupHost {
468 original: *mut libc::addrinfo,
469 cur: *mut libc::addrinfo,
472 impl Iterator for LookupHost {
473 type Item = SocketAddr;
474 fn next(&mut self) -> Option<SocketAddr> {
480 pub fn port(&self) -> u16 {
485 unsafe impl Sync for LookupHost {}
486 unsafe impl Send for LookupHost {}
488 impl TryFrom<&str> for LookupHost {
489 type Error = io::Error;
491 fn try_from(_v: &str) -> io::Result<LookupHost> {
496 impl<'a> TryFrom<(&'a str, u16)> for LookupHost {
497 type Error = io::Error;
499 fn try_from(_v: (&'a str, u16)) -> io::Result<LookupHost> {