1// Copyright (c) 2023 Huawei Device Co., Ltd.
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6//     http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14//! Event-driven non-blocking Tcp/Udp for windows
15
16macro_rules! syscall {
17    ($fn: ident ( $($arg: expr),* $(,)* ), $ret: expr) => {{
18        let res = unsafe { $fn($($arg, )*) };
19        if res == 0 {
20            Err(io::Error::last_os_error())
21        } else {
22            Ok($ret)
23        }
24    }};
25}
26
27mod afd;
28mod iocp;
29
30mod selector;
31pub use selector::Selector;
32
33mod handle;
34use handle::Handle;
35
36mod events;
37pub use events::{Event, Events};
38
39mod overlapped;
40pub(crate) use overlapped::Overlapped;
41
42mod io_status_block;
43mod socket_addr;
44
45mod waker;
46pub(crate) use waker::WakerInner;
47
48mod net;
49pub(crate) mod winapi;
50
51pub(crate) use net::NetInner;
52cfg_net! {
53    macro_rules! socket_syscall {
54        ($fn: ident ( $($arg: expr),* $(,)* ), $err_fn: path, $err_val: expr) => {{
55            let res = unsafe { $fn($($arg, )*) };
56            if $err_fn(&res, &$err_val) {
57                Err(io::Error::last_os_error())
58            } else {
59                Ok(res)
60            }
61        }};
62    }
63    pub(crate) use net::NetState;
64}
65
66cfg_tcp! {
67    mod tcp;
68    pub use self::tcp::{TcpListener, TcpStream};
69}
70
71cfg_udp! {
72    mod udp;
73    pub use self::udp::{UdpSocket, ConnectedUdpSocket};
74}
75