1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//! Async networking primitives for lio.
//!
//! This module provides high-level abstractions for network I/O operations using lio's
//! async runtime. It includes both low-level socket primitives and higher-level TCP
//! abstractions.
//!
//! # Main Types
//!
//! - [`Socket`]: Low-level async socket wrapper that provides direct access to socket operations
//! - [`TcpListener`]: High-level TCP server for accepting incoming connections
//! - [`TcpSocket`]: High-level TCP client/server connection for sending and receiving data
//!
//! # Features
//!
//! - **Async-first design**: All I/O operations return [`Io<T>`](crate::api::io::Io)
//! which can be awaited
//! - **Efficient buffer management**: Operations take ownership of buffers and return them,
//! avoiding unnecessary copies
//! - **Zero-cost abstractions**: High-level types like `TcpListener` and `TcpSocket` are
//! thin wrappers around `Socket` with no runtime overhead
//! - **Platform-native**: Uses the most efficient I/O mechanism available on the platform
//! (io_uring on Linux, kqueue on BSD/macOS, etc.)
//!
//! # Examples
//!
//! ## TCP Echo Server
//!
//! ```rust,ignore
//! use lio::net::TcpListener;
//!
//! async fn echo_server() -> std::io::Result<()> {
//! let listener = TcpListener::bind_async("127.0.0.1:8080").await?;
//! println!("Server listening on 127.0.0.1:8080");
//!
//! loop {
//! let (socket, addr) = listener.accept().await?;
//! println!("New connection from: {}", addr);
//!
//! // Echo data back to the client
//! let buffer = vec![0u8; 1024];
//! let (result, buffer) = socket.recv(buffer).await;
//! let bytes_read = result? as usize;
//!
//! if bytes_read > 0 {
//! let (result, _) = socket.send(buffer[..bytes_read].to_vec()).await;
//! let bytes_sent = result? as usize;
//! println!("Echoed {} bytes", bytes_sent);
//! }
//! }
//! }
//! ```
//!
//! ## TCP Client
//!
//! ```rust,ignore
//! use lio::net::TcpSocket;
//! use std::net::SocketAddr;
//!
//! async fn send_message() -> std::io::Result<()> {
//! // Connect to server
//! let addr: SocketAddr = "127.0.0.1:8080".parse().unwrap();
//! let socket = TcpSocket::connect_async(addr).await?;
//!
//! // Send a message
//! let message = b"Hello, server!".to_vec();
//! let (result, message) = socket.send(message).await;
//! let bytes_sent = result? as usize;
//! println!("Sent {} bytes", bytes_sent);
//!
//! // Receive response
//! let buffer = vec![0u8; 1024];
//! let (result, buffer) = socket.recv(buffer).await;
//! let bytes_read = result? as usize;
//! println!("Received: {:?}", &buffer[..bytes_read]);
//!
//! // Gracefully shutdown
//! socket.shutdown(libc::SHUT_RDWR).await?;
//!
//! Ok(())
//! }
//! ```
//!
//! ## Low-Level Socket Operations
//!
//! For advanced use cases, you can use [`Socket`] directly:
//!
//! ```rust,ignore
//! use lio::net::Socket;
//! use std::net::SocketAddr;
//!
//! async fn custom_socket() -> std::io::Result<()> {
//! // Create a raw TCP socket
//! let socket = Socket::new(libc::AF_INET, libc::SOCK_STREAM, 0).await?;
//!
//! // Bind to an address
//! let addr: SocketAddr = "0.0.0.0:9000".parse().unwrap();
//! socket.bind(addr).await?;
//!
//! // Listen for connections
//! socket.listen().await?;
//!
//! // Accept a connection (returns Socket and address)
//! let (client_socket, client_addr) = socket.accept().await?;
//! println!("Client connected: {}", client_addr);
//!
//! Ok(())
//! }
//! ```
//!
//! # Synchronous vs Asynchronous
//!
//! Most operations in this module are async by default. However, some types like
//! [`TcpListener`] and [`TcpSocket`] provide `_sync` variants for blocking operations:
//!
//! ```rust,ignore
//! use lio::net::TcpListener;
//!
//! fn sync_example() -> std::io::Result<()> {
//! // This blocks until the listener is ready
//! let listener = TcpListener::bind_sync("127.0.0.1:8080")?;
//!
//! // Accept is still async
//! Ok(())
//! }
//! ```
//!
//! # See Also
//!
//! - [`crate::api::resource`]: Resource management for file descriptors
//! - [`crate::api::io`]: Io type for async operations
pub use *;
pub use *;