3 return Err(io
::const_io_error
!(
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::os
::unix
::io
::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd}
;
17 use crate::sys
::fd
::FileDesc
;
18 use crate::sys_common
::{AsInner, FromInner, IntoInner}
;
19 use crate::time
::Duration
;
21 #[allow(unused_extern_crates)]
22 pub extern crate libc
as netc
;
24 pub struct Socket(FileDesc
);
26 pub fn new(_
: &SocketAddr
, _
: libc
::c_int
) -> io
::Result
<Socket
> {
30 pub fn new_raw(_
: libc
::c_int
, _
: libc
::c_int
) -> io
::Result
<Socket
> {
34 pub fn new_pair(_
: libc
::c_int
, _
: libc
::c_int
) -> io
::Result
<(Socket
, Socket
)> {
38 pub fn connect_timeout(&self, _
: &SocketAddr
, _
: Duration
) -> io
::Result
<()> {
44 _
: *mut libc
::sockaddr
,
45 _
: *mut libc
::socklen_t
,
46 ) -> io
::Result
<Socket
> {
50 pub fn duplicate(&self) -> io
::Result
<Socket
> {
54 pub fn read(&self, _
: &mut [u8]) -> io
::Result
<usize> {
58 pub fn read_vectored(&self, _
: &mut [IoSliceMut
<'_
>]) -> io
::Result
<usize> {
62 pub fn is_read_vectored(&self) -> bool
{
66 pub fn peek(&self, _
: &mut [u8]) -> io
::Result
<usize> {
70 pub fn recv_from(&self, _
: &mut [u8]) -> io
::Result
<(usize, SocketAddr
)> {
74 pub fn peek_from(&self, _
: &mut [u8]) -> io
::Result
<(usize, SocketAddr
)> {
78 pub fn write(&self, _
: &[u8]) -> io
::Result
<usize> {
82 pub fn write_vectored(&self, _
: &[IoSlice
<'_
>]) -> io
::Result
<usize> {
86 pub fn is_write_vectored(&self) -> bool
{
90 pub fn set_timeout(&self, _
: Option
<Duration
>, _
: libc
::c_int
) -> io
::Result
<()> {
94 pub fn timeout(&self, _
: libc
::c_int
) -> io
::Result
<Option
<Duration
>> {
98 pub fn shutdown(&self, _
: Shutdown
) -> io
::Result
<()> {
102 pub fn set_linger(&self, _
: Option
<Duration
>) -> io
::Result
<()> {
106 pub fn linger(&self) -> io
::Result
<Option
<Duration
>> {
110 pub fn set_nodelay(&self, _
: bool
) -> io
::Result
<()> {
114 pub fn nodelay(&self) -> io
::Result
<bool
> {
118 pub fn set_nonblocking(&self, _
: bool
) -> io
::Result
<()> {
122 pub fn take_error(&self) -> io
::Result
<Option
<io
::Error
>> {
126 // This is used by sys_common code to abstract over Windows and Unix.
127 pub fn as_raw(&self) -> RawFd
{
132 impl AsInner
<FileDesc
> for Socket
{
133 fn as_inner(&self) -> &FileDesc
{
138 impl FromInner
<FileDesc
> for Socket
{
139 fn from_inner(file_desc
: FileDesc
) -> Socket
{
144 impl IntoInner
<FileDesc
> for Socket
{
145 fn into_inner(self) -> FileDesc
{
150 impl AsFd
for Socket
{
151 fn as_fd(&self) -> BorrowedFd
<'_
> {
156 impl AsRawFd
for Socket
{
157 fn as_raw_fd(&self) -> RawFd
{
162 impl IntoRawFd
for Socket
{
163 fn into_raw_fd(self) -> RawFd
{
168 impl FromRawFd
for Socket
{
169 unsafe fn from_raw_fd(raw_fd
: RawFd
) -> Self {
170 Self(FromRawFd
::from_raw_fd(raw_fd
))
174 pub struct TcpStream
{
179 pub fn connect(_
: io
::Result
<&SocketAddr
>) -> io
::Result
<TcpStream
> {
183 pub fn connect_timeout(_
: &SocketAddr
, _
: Duration
) -> io
::Result
<TcpStream
> {
187 pub fn socket(&self) -> &Socket
{
191 pub fn into_socket(self) -> Socket
{
195 pub fn set_read_timeout(&self, _
: Option
<Duration
>) -> io
::Result
<()> {
199 pub fn set_write_timeout(&self, _
: Option
<Duration
>) -> io
::Result
<()> {
203 pub fn read_timeout(&self) -> io
::Result
<Option
<Duration
>> {
207 pub fn write_timeout(&self) -> io
::Result
<Option
<Duration
>> {
211 pub fn peek(&self, _
: &mut [u8]) -> io
::Result
<usize> {
215 pub fn read(&self, _
: &mut [u8]) -> io
::Result
<usize> {
219 pub fn read_vectored(&self, _
: &mut [IoSliceMut
<'_
>]) -> io
::Result
<usize> {
223 pub fn is_read_vectored(&self) -> bool
{
227 pub fn write(&self, _
: &[u8]) -> io
::Result
<usize> {
231 pub fn write_vectored(&self, _
: &[IoSlice
<'_
>]) -> io
::Result
<usize> {
235 pub fn is_write_vectored(&self) -> bool
{
239 pub fn peer_addr(&self) -> io
::Result
<SocketAddr
> {
243 pub fn socket_addr(&self) -> io
::Result
<SocketAddr
> {
247 pub fn shutdown(&self, _
: Shutdown
) -> io
::Result
<()> {
251 pub fn duplicate(&self) -> io
::Result
<TcpStream
> {
255 pub fn set_linger(&self, _
: Option
<Duration
>) -> io
::Result
<()> {
259 pub fn linger(&self) -> io
::Result
<Option
<Duration
>> {
263 pub fn set_nodelay(&self, _
: bool
) -> io
::Result
<()> {
267 pub fn nodelay(&self) -> io
::Result
<bool
> {
271 pub fn set_ttl(&self, _
: u32) -> io
::Result
<()> {
275 pub fn ttl(&self) -> io
::Result
<u32> {
279 pub fn take_error(&self) -> io
::Result
<Option
<io
::Error
>> {
283 pub fn set_nonblocking(&self, _
: bool
) -> io
::Result
<()> {
288 impl FromInner
<Socket
> for TcpStream
{
289 fn from_inner(socket
: Socket
) -> TcpStream
{
290 TcpStream { inner: socket }
294 impl fmt
::Debug
for TcpStream
{
295 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
296 write
!(f
, "No networking support available on L4Re")
300 pub struct TcpListener
{
305 pub fn bind(_
: io
::Result
<&SocketAddr
>) -> io
::Result
<TcpListener
> {
309 pub fn socket(&self) -> &Socket
{
313 pub fn into_socket(self) -> Socket
{
317 pub fn socket_addr(&self) -> io
::Result
<SocketAddr
> {
321 pub fn accept(&self) -> io
::Result
<(TcpStream
, SocketAddr
)> {
325 pub fn duplicate(&self) -> io
::Result
<TcpListener
> {
329 pub fn set_ttl(&self, _
: u32) -> io
::Result
<()> {
333 pub fn ttl(&self) -> io
::Result
<u32> {
337 pub fn set_only_v6(&self, _
: bool
) -> io
::Result
<()> {
341 pub fn only_v6(&self) -> io
::Result
<bool
> {
345 pub fn take_error(&self) -> io
::Result
<Option
<io
::Error
>> {
349 pub fn set_nonblocking(&self, _
: bool
) -> io
::Result
<()> {
354 impl FromInner
<Socket
> for TcpListener
{
355 fn from_inner(socket
: Socket
) -> TcpListener
{
356 TcpListener { inner: socket }
360 impl fmt
::Debug
for TcpListener
{
361 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
362 write
!(f
, "No networking support available on L4Re.")
366 pub struct UdpSocket
{
371 pub fn bind(_
: io
::Result
<&SocketAddr
>) -> io
::Result
<UdpSocket
> {
375 pub fn socket(&self) -> &Socket
{
379 pub fn into_socket(self) -> Socket
{
383 pub fn peer_addr(&self) -> io
::Result
<SocketAddr
> {
387 pub fn socket_addr(&self) -> io
::Result
<SocketAddr
> {
391 pub fn recv_from(&self, _
: &mut [u8]) -> io
::Result
<(usize, SocketAddr
)> {
395 pub fn peek_from(&self, _
: &mut [u8]) -> io
::Result
<(usize, SocketAddr
)> {
399 pub fn send_to(&self, _
: &[u8], _
: &SocketAddr
) -> io
::Result
<usize> {
403 pub fn duplicate(&self) -> io
::Result
<UdpSocket
> {
407 pub fn set_read_timeout(&self, _
: Option
<Duration
>) -> io
::Result
<()> {
411 pub fn set_write_timeout(&self, _
: Option
<Duration
>) -> io
::Result
<()> {
415 pub fn read_timeout(&self) -> io
::Result
<Option
<Duration
>> {
419 pub fn write_timeout(&self) -> io
::Result
<Option
<Duration
>> {
423 pub fn set_broadcast(&self, _
: bool
) -> io
::Result
<()> {
427 pub fn broadcast(&self) -> io
::Result
<bool
> {
431 pub fn set_multicast_loop_v4(&self, _
: bool
) -> io
::Result
<()> {
435 pub fn multicast_loop_v4(&self) -> io
::Result
<bool
> {
439 pub fn set_multicast_ttl_v4(&self, _
: u32) -> io
::Result
<()> {
443 pub fn multicast_ttl_v4(&self) -> io
::Result
<u32> {
447 pub fn set_multicast_loop_v6(&self, _
: bool
) -> io
::Result
<()> {
451 pub fn multicast_loop_v6(&self) -> io
::Result
<bool
> {
455 pub fn join_multicast_v4(&self, _
: &Ipv4Addr
, _
: &Ipv4Addr
) -> io
::Result
<()> {
459 pub fn join_multicast_v6(&self, _
: &Ipv6Addr
, _
: u32) -> io
::Result
<()> {
463 pub fn leave_multicast_v4(&self, _
: &Ipv4Addr
, _
: &Ipv4Addr
) -> io
::Result
<()> {
467 pub fn leave_multicast_v6(&self, _
: &Ipv6Addr
, _
: u32) -> io
::Result
<()> {
471 pub fn set_ttl(&self, _
: u32) -> io
::Result
<()> {
475 pub fn ttl(&self) -> io
::Result
<u32> {
479 pub fn take_error(&self) -> io
::Result
<Option
<io
::Error
>> {
483 pub fn set_nonblocking(&self, _
: bool
) -> io
::Result
<()> {
487 pub fn recv(&self, _
: &mut [u8]) -> io
::Result
<usize> {
491 pub fn peek(&self, _
: &mut [u8]) -> io
::Result
<usize> {
495 pub fn send(&self, _
: &[u8]) -> io
::Result
<usize> {
499 pub fn connect(&self, _
: io
::Result
<&SocketAddr
>) -> io
::Result
<()> {
504 impl FromInner
<Socket
> for UdpSocket
{
505 fn from_inner(socket
: Socket
) -> UdpSocket
{
506 UdpSocket { inner: socket }
510 impl fmt
::Debug
for UdpSocket
{
511 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
512 write
!(f
, "No networking support on L4Re available.")
516 pub struct LookupHost
{
517 original
: *mut libc
::addrinfo
,
518 cur
: *mut libc
::addrinfo
,
521 impl Iterator
for LookupHost
{
522 type Item
= SocketAddr
;
523 fn next(&mut self) -> Option
<SocketAddr
> {
529 pub fn port(&self) -> u16 {
534 unsafe impl Sync
for LookupHost {}
535 unsafe impl Send
for LookupHost {}
537 impl TryFrom
<&str> for LookupHost
{
538 type Error
= io
::Error
;
540 fn try_from(_v
: &str) -> io
::Result
<LookupHost
> {
545 impl<'a
> TryFrom
<(&'a
str, u16)> for LookupHost
{
546 type Error
= io
::Error
;
548 fn try_from(_v
: (&'a
str, u16)) -> io
::Result
<LookupHost
> {