]> git.proxmox.com Git - rustc.git/blob - library/std/src/sys/wasi/net.rs
New upstream version 1.52.0~beta.3+dfsg1
[rustc.git] / library / std / src / sys / wasi / net.rs
1 #![deny(unsafe_op_in_unsafe_fn)]
2
3 use super::fd::WasiFd;
4 use crate::convert::TryFrom;
5 use crate::fmt;
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;
11
12 pub struct TcpStream {
13 fd: WasiFd,
14 }
15
16 impl TcpStream {
17 pub fn connect(_: io::Result<&SocketAddr>) -> io::Result<TcpStream> {
18 unsupported()
19 }
20
21 pub fn connect_timeout(_: &SocketAddr, _: Duration) -> io::Result<TcpStream> {
22 unsupported()
23 }
24
25 pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
26 unsupported()
27 }
28
29 pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
30 unsupported()
31 }
32
33 pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
34 unsupported()
35 }
36
37 pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
38 unsupported()
39 }
40
41 pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
42 unsupported()
43 }
44
45 pub fn read(&self, _: &mut [u8]) -> io::Result<usize> {
46 unsupported()
47 }
48
49 pub fn read_vectored(&self, _: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
50 unsupported()
51 }
52
53 pub fn is_read_vectored(&self) -> bool {
54 true
55 }
56
57 pub fn write(&self, _: &[u8]) -> io::Result<usize> {
58 unsupported()
59 }
60
61 pub fn write_vectored(&self, _: &[IoSlice<'_>]) -> io::Result<usize> {
62 unsupported()
63 }
64
65 pub fn is_write_vectored(&self) -> bool {
66 true
67 }
68
69 pub fn peer_addr(&self) -> io::Result<SocketAddr> {
70 unsupported()
71 }
72
73 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
74 unsupported()
75 }
76
77 pub fn shutdown(&self, _: Shutdown) -> io::Result<()> {
78 unsupported()
79 }
80
81 pub fn duplicate(&self) -> io::Result<TcpStream> {
82 unsupported()
83 }
84
85 pub fn set_nodelay(&self, _: bool) -> io::Result<()> {
86 unsupported()
87 }
88
89 pub fn nodelay(&self) -> io::Result<bool> {
90 unsupported()
91 }
92
93 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
94 unsupported()
95 }
96
97 pub fn ttl(&self) -> io::Result<u32> {
98 unsupported()
99 }
100
101 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
102 unsupported()
103 }
104
105 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
106 unsupported()
107 }
108
109 pub fn fd(&self) -> &WasiFd {
110 &self.fd
111 }
112
113 pub fn into_fd(self) -> WasiFd {
114 self.fd
115 }
116 }
117
118 impl FromInner<u32> for TcpStream {
119 fn from_inner(fd: u32) -> TcpStream {
120 unsafe { TcpStream { fd: WasiFd::from_raw(fd) } }
121 }
122 }
123
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()
127 }
128 }
129
130 pub struct TcpListener {
131 fd: WasiFd,
132 }
133
134 impl TcpListener {
135 pub fn bind(_: io::Result<&SocketAddr>) -> io::Result<TcpListener> {
136 unsupported()
137 }
138
139 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
140 unsupported()
141 }
142
143 pub fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
144 unsupported()
145 }
146
147 pub fn duplicate(&self) -> io::Result<TcpListener> {
148 unsupported()
149 }
150
151 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
152 unsupported()
153 }
154
155 pub fn ttl(&self) -> io::Result<u32> {
156 unsupported()
157 }
158
159 pub fn set_only_v6(&self, _: bool) -> io::Result<()> {
160 unsupported()
161 }
162
163 pub fn only_v6(&self) -> io::Result<bool> {
164 unsupported()
165 }
166
167 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
168 unsupported()
169 }
170
171 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
172 unsupported()
173 }
174
175 pub fn fd(&self) -> &WasiFd {
176 &self.fd
177 }
178
179 pub fn into_fd(self) -> WasiFd {
180 self.fd
181 }
182 }
183
184 impl FromInner<u32> for TcpListener {
185 fn from_inner(fd: u32) -> TcpListener {
186 unsafe { TcpListener { fd: WasiFd::from_raw(fd) } }
187 }
188 }
189
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()
193 }
194 }
195
196 pub struct UdpSocket {
197 fd: WasiFd,
198 }
199
200 impl UdpSocket {
201 pub fn bind(_: io::Result<&SocketAddr>) -> io::Result<UdpSocket> {
202 unsupported()
203 }
204
205 pub fn peer_addr(&self) -> io::Result<SocketAddr> {
206 unsupported()
207 }
208
209 pub fn socket_addr(&self) -> io::Result<SocketAddr> {
210 unsupported()
211 }
212
213 pub fn recv_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
214 unsupported()
215 }
216
217 pub fn peek_from(&self, _: &mut [u8]) -> io::Result<(usize, SocketAddr)> {
218 unsupported()
219 }
220
221 pub fn send_to(&self, _: &[u8], _: &SocketAddr) -> io::Result<usize> {
222 unsupported()
223 }
224
225 pub fn duplicate(&self) -> io::Result<UdpSocket> {
226 unsupported()
227 }
228
229 pub fn set_read_timeout(&self, _: Option<Duration>) -> io::Result<()> {
230 unsupported()
231 }
232
233 pub fn set_write_timeout(&self, _: Option<Duration>) -> io::Result<()> {
234 unsupported()
235 }
236
237 pub fn read_timeout(&self) -> io::Result<Option<Duration>> {
238 unsupported()
239 }
240
241 pub fn write_timeout(&self) -> io::Result<Option<Duration>> {
242 unsupported()
243 }
244
245 pub fn set_broadcast(&self, _: bool) -> io::Result<()> {
246 unsupported()
247 }
248
249 pub fn broadcast(&self) -> io::Result<bool> {
250 unsupported()
251 }
252
253 pub fn set_multicast_loop_v4(&self, _: bool) -> io::Result<()> {
254 unsupported()
255 }
256
257 pub fn multicast_loop_v4(&self) -> io::Result<bool> {
258 unsupported()
259 }
260
261 pub fn set_multicast_ttl_v4(&self, _: u32) -> io::Result<()> {
262 unsupported()
263 }
264
265 pub fn multicast_ttl_v4(&self) -> io::Result<u32> {
266 unsupported()
267 }
268
269 pub fn set_multicast_loop_v6(&self, _: bool) -> io::Result<()> {
270 unsupported()
271 }
272
273 pub fn multicast_loop_v6(&self) -> io::Result<bool> {
274 unsupported()
275 }
276
277 pub fn join_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) -> io::Result<()> {
278 unsupported()
279 }
280
281 pub fn join_multicast_v6(&self, _: &Ipv6Addr, _: u32) -> io::Result<()> {
282 unsupported()
283 }
284
285 pub fn leave_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) -> io::Result<()> {
286 unsupported()
287 }
288
289 pub fn leave_multicast_v6(&self, _: &Ipv6Addr, _: u32) -> io::Result<()> {
290 unsupported()
291 }
292
293 pub fn set_ttl(&self, _: u32) -> io::Result<()> {
294 unsupported()
295 }
296
297 pub fn ttl(&self) -> io::Result<u32> {
298 unsupported()
299 }
300
301 pub fn take_error(&self) -> io::Result<Option<io::Error>> {
302 unsupported()
303 }
304
305 pub fn set_nonblocking(&self, _: bool) -> io::Result<()> {
306 unsupported()
307 }
308
309 pub fn recv(&self, _: &mut [u8]) -> io::Result<usize> {
310 unsupported()
311 }
312
313 pub fn peek(&self, _: &mut [u8]) -> io::Result<usize> {
314 unsupported()
315 }
316
317 pub fn send(&self, _: &[u8]) -> io::Result<usize> {
318 unsupported()
319 }
320
321 pub fn connect(&self, _: io::Result<&SocketAddr>) -> io::Result<()> {
322 unsupported()
323 }
324
325 pub fn fd(&self) -> &WasiFd {
326 &self.fd
327 }
328
329 pub fn into_fd(self) -> WasiFd {
330 self.fd
331 }
332 }
333
334 impl FromInner<u32> for UdpSocket {
335 fn from_inner(fd: u32) -> UdpSocket {
336 unsafe { UdpSocket { fd: WasiFd::from_raw(fd) } }
337 }
338 }
339
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()
343 }
344 }
345
346 pub struct LookupHost(Void);
347
348 impl LookupHost {
349 pub fn port(&self) -> u16 {
350 match self.0 {}
351 }
352 }
353
354 impl Iterator for LookupHost {
355 type Item = SocketAddr;
356 fn next(&mut self) -> Option<SocketAddr> {
357 match self.0 {}
358 }
359 }
360
361 impl<'a> TryFrom<&'a str> for LookupHost {
362 type Error = io::Error;
363
364 fn try_from(_v: &'a str) -> io::Result<LookupHost> {
365 unsupported()
366 }
367 }
368
369 impl<'a> TryFrom<(&'a str, u16)> for LookupHost {
370 type Error = io::Error;
371
372 fn try_from(_v: (&'a str, u16)) -> io::Result<LookupHost> {
373 unsupported()
374 }
375 }
376
377 #[allow(nonstandard_style)]
378 pub mod netc {
379 pub const AF_INET: u8 = 0;
380 pub const AF_INET6: u8 = 1;
381 pub type sa_family_t = u8;
382
383 #[derive(Copy, Clone)]
384 pub struct in_addr {
385 pub s_addr: u32,
386 }
387
388 #[derive(Copy, Clone)]
389 pub struct sockaddr_in {
390 pub sin_family: sa_family_t,
391 pub sin_port: u16,
392 pub sin_addr: in_addr,
393 }
394
395 #[derive(Copy, Clone)]
396 pub struct in6_addr {
397 pub s6_addr: [u8; 16],
398 }
399
400 #[derive(Copy, Clone)]
401 pub struct sockaddr_in6 {
402 pub sin6_family: sa_family_t,
403 pub sin6_port: u16,
404 pub sin6_addr: in6_addr,
405 pub sin6_flowinfo: u32,
406 pub sin6_scope_id: u32,
407 }
408
409 #[derive(Copy, Clone)]
410 pub struct sockaddr {}
411
412 pub type socklen_t = usize;
413 }