1#[cfg_attr(target_family = "windows", path = "socket/socket_win32.rs")]
2#[cfg_attr(target_family = "unix", path = "socket/socket_unix.rs")]
3mod socket;
4pub use socket::*;
5
6pub mod tcp;
7pub mod udp;
8
9pub mod sys {
10 use std::{io::Result, net::SocketAddr, task::Poll, time::Duration};
11
12 use crate::io::{IoReactor, RawFd};
13
14 pub trait Socket: Sized {
16 fn socket(ip_v4: bool, sock_type: i32, protocol: i32) -> Result<RawFd>;
18
19 fn tcp(ip_v4: bool) -> Result<RawFd>;
21 fn udp(ip_v4: bool) -> Result<RawFd>;
23
24 fn bind(fd: RawFd, addr: SocketAddr) -> Result<()>;
26
27 fn listen(fd: RawFd) -> Result<()>;
29
30 fn new(ip_v4: bool, fd: RawFd, reactor: IoReactor) -> Result<Self>;
34
35 fn close(&mut self);
37
38 fn poll_connect(
40 self: std::pin::Pin<&mut Self>,
41 cx: &mut std::task::Context<'_>,
42 remote: SocketAddr,
43 timeout: Option<Duration>,
44 ) -> Poll<Result<()>>;
45 }
46
47 pub enum ReadBuffer<'cx> {
49 Stream(&'cx mut [u8]),
50 Datagram(&'cx mut [u8], &'cx mut Option<SocketAddr>),
51
52 Accept(&'cx mut Option<RawFd>, &'cx mut Option<SocketAddr>),
53 }
54
55 pub enum WriteBuffer<'cx> {
57 Stream(&'cx [u8]),
58 Datagram(&'cx [u8], &'cx SocketAddr),
59 }
60}