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 
16 macro_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 
27 mod afd;
28 mod iocp;
29 
30 mod selector;
31 pub use selector::Selector;
32 
33 mod handle;
34 use handle::Handle;
35 
36 mod events;
37 pub use events::{Event, Events};
38 
39 mod overlapped;
40 pub(crate) use overlapped::Overlapped;
41 
42 mod io_status_block;
43 mod socket_addr;
44 
45 mod waker;
46 pub(crate) use waker::WakerInner;
47 
48 mod net;
49 pub(crate) mod winapi;
50 
51 pub(crate) use net::NetInner;
52 cfg_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 
66 cfg_tcp! {
67     mod tcp;
68     pub use self::tcp::{TcpListener, TcpStream};
69 }
70 
71 cfg_udp! {
72     mod udp;
73     pub use self::udp::{UdpSocket, ConnectedUdpSocket};
74 }
75