1 #![deny(unsafe_op_in_unsafe_fn)]
4 use crate::convert
::TryFrom
;
6 use crate::io
::{self, IoSlice, IoSliceMut}
;
7 use crate::net
::{Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr}
;
8 use crate::sys
::{unsupported, Void}
;
9 use crate::sys_common
::FromInner
;
10 use crate::time
::Duration
;
12 pub struct TcpStream
{
17 pub fn connect(_
: io
::Result
<&SocketAddr
>) -> io
::Result
<TcpStream
> {
21 pub fn connect_timeout(_
: &SocketAddr
, _
: Duration
) -> io
::Result
<TcpStream
> {
25 pub fn set_read_timeout(&self, _
: Option
<Duration
>) -> io
::Result
<()> {
29 pub fn set_write_timeout(&self, _
: Option
<Duration
>) -> io
::Result
<()> {
33 pub fn read_timeout(&self) -> io
::Result
<Option
<Duration
>> {
37 pub fn write_timeout(&self) -> io
::Result
<Option
<Duration
>> {
41 pub fn peek(&self, _
: &mut [u8]) -> io
::Result
<usize> {
45 pub fn read(&self, _
: &mut [u8]) -> io
::Result
<usize> {
49 pub fn read_vectored(&self, _
: &mut [IoSliceMut
<'_
>]) -> io
::Result
<usize> {
53 pub fn is_read_vectored(&self) -> bool
{
57 pub fn write(&self, _
: &[u8]) -> io
::Result
<usize> {
61 pub fn write_vectored(&self, _
: &[IoSlice
<'_
>]) -> io
::Result
<usize> {
65 pub fn is_write_vectored(&self) -> bool
{
69 pub fn peer_addr(&self) -> io
::Result
<SocketAddr
> {
73 pub fn socket_addr(&self) -> io
::Result
<SocketAddr
> {
77 pub fn shutdown(&self, _
: Shutdown
) -> io
::Result
<()> {
81 pub fn duplicate(&self) -> io
::Result
<TcpStream
> {
85 pub fn set_nodelay(&self, _
: bool
) -> io
::Result
<()> {
89 pub fn nodelay(&self) -> io
::Result
<bool
> {
93 pub fn set_ttl(&self, _
: u32) -> io
::Result
<()> {
97 pub fn ttl(&self) -> io
::Result
<u32> {
101 pub fn take_error(&self) -> io
::Result
<Option
<io
::Error
>> {
105 pub fn set_nonblocking(&self, _
: bool
) -> io
::Result
<()> {
109 pub fn fd(&self) -> &WasiFd
{
113 pub fn into_fd(self) -> WasiFd
{
118 impl FromInner
<u32> for TcpStream
{
119 fn from_inner(fd
: u32) -> TcpStream
{
120 unsafe { TcpStream { fd: WasiFd::from_raw(fd) }
}
124 impl fmt
::Debug
for TcpStream
{
125 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
126 f
.debug_struct("TcpStream").field("fd", &self.fd
.as_raw()).finish()
130 pub struct TcpListener
{
135 pub fn bind(_
: io
::Result
<&SocketAddr
>) -> io
::Result
<TcpListener
> {
139 pub fn socket_addr(&self) -> io
::Result
<SocketAddr
> {
143 pub fn accept(&self) -> io
::Result
<(TcpStream
, SocketAddr
)> {
147 pub fn duplicate(&self) -> io
::Result
<TcpListener
> {
151 pub fn set_ttl(&self, _
: u32) -> io
::Result
<()> {
155 pub fn ttl(&self) -> io
::Result
<u32> {
159 pub fn set_only_v6(&self, _
: bool
) -> io
::Result
<()> {
163 pub fn only_v6(&self) -> io
::Result
<bool
> {
167 pub fn take_error(&self) -> io
::Result
<Option
<io
::Error
>> {
171 pub fn set_nonblocking(&self, _
: bool
) -> io
::Result
<()> {
175 pub fn fd(&self) -> &WasiFd
{
179 pub fn into_fd(self) -> WasiFd
{
184 impl FromInner
<u32> for TcpListener
{
185 fn from_inner(fd
: u32) -> TcpListener
{
186 unsafe { TcpListener { fd: WasiFd::from_raw(fd) }
}
190 impl fmt
::Debug
for TcpListener
{
191 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
192 f
.debug_struct("TcpListener").field("fd", &self.fd
.as_raw()).finish()
196 pub struct UdpSocket
{
201 pub fn bind(_
: io
::Result
<&SocketAddr
>) -> io
::Result
<UdpSocket
> {
205 pub fn peer_addr(&self) -> io
::Result
<SocketAddr
> {
209 pub fn socket_addr(&self) -> io
::Result
<SocketAddr
> {
213 pub fn recv_from(&self, _
: &mut [u8]) -> io
::Result
<(usize, SocketAddr
)> {
217 pub fn peek_from(&self, _
: &mut [u8]) -> io
::Result
<(usize, SocketAddr
)> {
221 pub fn send_to(&self, _
: &[u8], _
: &SocketAddr
) -> io
::Result
<usize> {
225 pub fn duplicate(&self) -> io
::Result
<UdpSocket
> {
229 pub fn set_read_timeout(&self, _
: Option
<Duration
>) -> io
::Result
<()> {
233 pub fn set_write_timeout(&self, _
: Option
<Duration
>) -> io
::Result
<()> {
237 pub fn read_timeout(&self) -> io
::Result
<Option
<Duration
>> {
241 pub fn write_timeout(&self) -> io
::Result
<Option
<Duration
>> {
245 pub fn set_broadcast(&self, _
: bool
) -> io
::Result
<()> {
249 pub fn broadcast(&self) -> io
::Result
<bool
> {
253 pub fn set_multicast_loop_v4(&self, _
: bool
) -> io
::Result
<()> {
257 pub fn multicast_loop_v4(&self) -> io
::Result
<bool
> {
261 pub fn set_multicast_ttl_v4(&self, _
: u32) -> io
::Result
<()> {
265 pub fn multicast_ttl_v4(&self) -> io
::Result
<u32> {
269 pub fn set_multicast_loop_v6(&self, _
: bool
) -> io
::Result
<()> {
273 pub fn multicast_loop_v6(&self) -> io
::Result
<bool
> {
277 pub fn join_multicast_v4(&self, _
: &Ipv4Addr
, _
: &Ipv4Addr
) -> io
::Result
<()> {
281 pub fn join_multicast_v6(&self, _
: &Ipv6Addr
, _
: u32) -> io
::Result
<()> {
285 pub fn leave_multicast_v4(&self, _
: &Ipv4Addr
, _
: &Ipv4Addr
) -> io
::Result
<()> {
289 pub fn leave_multicast_v6(&self, _
: &Ipv6Addr
, _
: u32) -> io
::Result
<()> {
293 pub fn set_ttl(&self, _
: u32) -> io
::Result
<()> {
297 pub fn ttl(&self) -> io
::Result
<u32> {
301 pub fn take_error(&self) -> io
::Result
<Option
<io
::Error
>> {
305 pub fn set_nonblocking(&self, _
: bool
) -> io
::Result
<()> {
309 pub fn recv(&self, _
: &mut [u8]) -> io
::Result
<usize> {
313 pub fn peek(&self, _
: &mut [u8]) -> io
::Result
<usize> {
317 pub fn send(&self, _
: &[u8]) -> io
::Result
<usize> {
321 pub fn connect(&self, _
: io
::Result
<&SocketAddr
>) -> io
::Result
<()> {
325 pub fn fd(&self) -> &WasiFd
{
329 pub fn into_fd(self) -> WasiFd
{
334 impl FromInner
<u32> for UdpSocket
{
335 fn from_inner(fd
: u32) -> UdpSocket
{
336 unsafe { UdpSocket { fd: WasiFd::from_raw(fd) }
}
340 impl fmt
::Debug
for UdpSocket
{
341 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
342 f
.debug_struct("UdpSocket").field("fd", &self.fd
.as_raw()).finish()
346 pub struct LookupHost(Void
);
349 pub fn port(&self) -> u16 {
354 impl Iterator
for LookupHost
{
355 type Item
= SocketAddr
;
356 fn next(&mut self) -> Option
<SocketAddr
> {
361 impl<'a
> TryFrom
<&'a
str> for LookupHost
{
362 type Error
= io
::Error
;
364 fn try_from(_v
: &'a
str) -> io
::Result
<LookupHost
> {
369 impl<'a
> TryFrom
<(&'a
str, u16)> for LookupHost
{
370 type Error
= io
::Error
;
372 fn try_from(_v
: (&'a
str, u16)) -> io
::Result
<LookupHost
> {
377 #[allow(nonstandard_style)]
379 pub const AF_INET
: u8 = 0;
380 pub const AF_INET6
: u8 = 1;
381 pub type sa_family_t
= u8;
383 #[derive(Copy, Clone)]
388 #[derive(Copy, Clone)]
389 pub struct sockaddr_in
{
390 pub sin_family
: sa_family_t
,
392 pub sin_addr
: in_addr
,
395 #[derive(Copy, Clone)]
396 pub struct in6_addr
{
397 pub s6_addr
: [u8; 16],
400 #[derive(Copy, Clone)]
401 pub struct sockaddr_in6
{
402 pub sin6_family
: sa_family_t
,
404 pub sin6_addr
: in6_addr
,
405 pub sin6_flowinfo
: u32,
406 pub sin6_scope_id
: u32,
409 #[derive(Copy, Clone)]
410 pub struct sockaddr {}
412 pub type socklen_t
= usize;