Skip to content

Commit 6d4f313

Browse files
committed
fix: update compio docs
1 parent 8f8b0ce commit 6d4f313

10 files changed

Lines changed: 26 additions & 15 deletions

File tree

content/docs/compio/buffers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ Crate `compio-buf` is fundamental to `compio`. It provides abstractions for diff
44

55
## Buffer traits
66

7-
The trait `IoBuf` is the abstract of read-only buffers. Trait `IoBufMut` provides writing methods in addition, but it doesn't support extending the buffer. Therefore, even `Vec` implements `IoBufMut`, a write operation can only write into the allocated space, but cannot extend the vector automatically.
7+
The trait `IoBuf` is the abstract of read-only buffers. Trait `IoBufMut` provides writing methods in addition, and supports extending the buffer. A write operation can only write into the allocated space, but cannot extend the vector automatically.
88

99
`IoBuf` & `IoBufMut` represent owned buffers. The IO operations always require the ownership of a buffer to avoid potential race conditions. Although the traits implement for arrays `[u8; N]`, it's not a good idea to use them as buffer type, because the move operation of them is relatively slow. Use `Vec<u8>` or `Box<[u8]>` instead.
1010

1111
## Slicing
1212

13-
Sometimes an owned slice of the buffer is needed. `IoBuf::slice` provides such convenience. It creates a slice which owns the buffer, and the buffer could be retrieved by `<Slice as IntoInner>::into_inner`.
13+
Sometimes an owned slice of the buffer is needed. `IoBuf::slice` provides such convenience. It creates a slice which owns the buffer, and the buffer could be retrieved by `<Slice as IntoInner>::into_inner`. `IoBufMut::uninit` provides similar functionalities, but it represents only the uninitialized part of the buffer.
1414

1515
## Vectored buffers
1616

content/docs/compio/dispatcher.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ for _i in 0..CLIENT_NUM {
2828
while handles.next().await.is_some() {}
2929
dispatcher.join().await.unwrap();
3030
```
31+
32+
## An optional solution
33+
The dispatcher is not the only solution to multi-threading webservers. `SO_REUSEADDR` or `SO_REUSEPORT` might be more efficient.

content/docs/compio/driver.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ The `Proactor` provides a simple cancellation mechanism. The cancellation of an
2222

2323
## Shared FDs
2424

25-
"File descriptors" in `compio` represents the file descriptors on Unix and handles on Windows. When the driver is holding the operations, it should also hold the reference of the related fds. Therefore, all fds are wrapped inside an `Arc`. When a file or socket is cloned, the inner `Arc` is cloned, rather than duplicating (e.g., with `dup`) the fds or handles. When the method `close` is called on a file or socket, the future will wait for all related operations to complete. Therefore, it's not a good idea to close a cloned file or socket.
25+
"File descriptors" in `compio` represents the file descriptors on Unix and handles on Windows. When the driver is holding the operations, it should also hold the reference of the related fds. Therefore, all fds are wrapped inside an `Rc`/`Arc`, depending on the feature `"sync"`. When a file or socket is cloned, the inner `Rc`/`Arc` is cloned, rather than duplicating (e.g., with `dup`) the fds or handles. When the method `close` is called on a file or socket, the future will wait for all related operations to complete. Therefore, it's not a good idea to close a cloned file or socket.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# io-uring
22

3-
The io-uring driver requires a Linux 5.19+ kernel. The kernel version limitation is from the oldest supported Ubuntu version.
4-
53
Some operations require a newer kernel, so they are hidden behind feature gates.
64

75
| feature | description |
86
| ----------------- | ----------------------------------- |
97
| `io-uring-cqe32` | Enable large completion queue entry |
108
| `io-uring-sqe128` | Enable large submission queue entry |
119

12-
If a feature is enabled but the kernel doesn't support it, the behavior depends on whether `polling` feature is also enabled. If `polling` is not enabled, the driver will continue using io-uring regardless of the kernel support. Or `polling` will be used as a fallback.
10+
If the kernel doesn't support these features, the driver will not fallback to the polling driver.
11+
12+
If the kernel doesn't support the opcode to be submitted, the driver will fallback to a blocking operation.
1313

1414
As io-uring is a bounded ring, possibly there is a case that the queues are full. The kernel is responsible to decide whether to discard the entries or report it to the user.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# polling
22

3-
`polling` crate is a subproject of `smol`. It provides a unified wrapper for the reactors on most platforms. Therefore, it is used on platforms other than Windows. On Linux, it is an option if io-uring is not available. When the user enables both `"io-uring"` and `"polling"`, a "fusion" driver is used and responsible for deciding which one to use in runtime.
3+
`polling` crate is a subproject of `smol`. It provides a unified wrapper for the reactors on most platforms. Therefore, it is used on platforms other than Windows. On Linux, it is an option if io-uring is not available. When the user enables both `"io-uring"` and `"polling"`, a "fusion" driver is used and responsible for deciding which one to use in runtime. You are able to specify the exact driver to use in the `ProactorBuilder`.
44

55
Frankly, there is no real async operations in a reactor. The socket IO operations are non-blocking, but the data copying still takes time. The blocking operations are spawned to the thread pool.
66

77
## What about AIO?
88

99
The POSIX standard leaves no way to interact the AIO operations with polling interfaces.
1010

11-
## FreeBSD
11+
### FreeBSD
1212

1313
FreeBSD provides extensions to post AIO events to kqueue. There are some known issues:
1414
* Some filesystems don't support AIO. `compio` fallbacks to blocking call if the AIO method returns `EOPNOTSUPP`.
1515
* The process-wide AIO queue is limited. If the queue is full, users cannot add new AIO requests unless one control block is removed by `aio_return`. In that case, `compio` fallbacks to blocking call.
1616

17-
## Illumos & Solaris
17+
### Illumos & Solaris
1818

1919
Solarish systems provides extensions to post AIO events to an event port. However, it doesn't support `aio_readv` or `aio_writev`. Therefore, `compio` fallbacks to `aio_read` & `aio_write` for files on solarish systems.

content/docs/compio/io.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@ assert_eq!(read_len, buffer.len());
3434

3535
## Managed buffer pool
3636

37-
`AsyncReadManaged` and `AsyncReadManagedAt` provide methods to read data with a buffer pool. The buffer pool itself, or the runtime, is responsible for selecting and filling in the suitable buffer. It is specially optimized when using `compio` with `"io-uring"` feature enabled.
37+
`AsyncReadManaged` and `AsyncReadManagedAt` provide methods to read data with a buffer pool. The buffer pool itself, or the runtime, is responsible for selecting and filling in the suitable buffer. It is specially optimized when using `compio` with io-uring driver enabled.
3838

3939
## Compatible helpers
4040

4141
Mod `compio::io::compat` provides `SyncStream` and `AsyncStream` for compatibility usages. `SyncStream` implements `std::io::{Read, Write}`, and will return error with `WouldBlock` if the inner buffer should be updated manually. `AsyncStream` wraps `SyncStream` and implements `AsyncRead` & `AsyncWrite` of `futures`.
42+
43+
## Framed IO
44+
45+
TODO

content/docs/compio/net.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Networking
22

3-
`compio-net` provides most networking affairs. TCP, UDP, Unix sockets are supported. The TLS support is in `compio-tls`, while QUIC support is in `compio-quic`. For high level HTTP support, see `cyper`.
3+
`compio-net` provides most networking affairs. TCP, UDP, Unix sockets are supported. The TLS support is in `compio-tls`, the QUIC support is in `compio-quic`, and the WebSocket support is in `compio-ws`. For high level HTTP support, see `cyper`.
44

55
Sockets in `compio` expose completion-based APIs. If it is too confusing to use, `PollFd` is provided for all kinds of socket resources, and exposes ready-based APIs.

content/docs/compio/net/sockets.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ A client can simply use `TcpStream::connect` to connect to the remote listener.
1010

1111
See the introduction of [`File::close`](../fs/file) for closing the sockets.
1212

13-
## TCP options
13+
## Socket options
1414

15-
`TcpListener::bind_with_options`, `TcpStream::connect_with_options` and `TcpStream::bind_and_connect_with_options` accept `TcpOpts` to specify TCP options on creation.
15+
`*Listener::bind_with_options`, `*Listener::accept_with_options`, `*Stream::connect_with_options` and `TcpStream::bind_and_connect_with_options` accept `SocketOpts` to specify options on creation.
1616

1717
## Dual-stack support
1818

@@ -24,4 +24,4 @@ Windows _does_ support Unix sockets, with some limitations. A Unix socket on Win
2424

2525
## Control messages of UDP sockets
2626

27-
TODO
27+
There are `send_msg*` and `recv_msg*` methods in `UdpSocket`. They retrieve ancillary data as raw buffers. The users are responsible to align the buffer correctly.

content/docs/compio/ws.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# WebSocket
2+
3+
`compio::ws` contains adapters for `tungstenite`. It is almost the same as `tokio-tungstenite`.

content/docs/summary.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ const compio: Section[] = [
3636
['Signal', '/docs/compio/signal'],
3737
['Process', '/docs/compio/process'],
3838
['TLS', '/docs/compio/tls'],
39-
// [['QUIC', 'compio/quic'], [['HTTP 3', 'compio/quic/http3']]], // TODO(@Berrysoft): Write this
39+
['WebSocket', "/docs/compio/ws"]
40+
// [['QUIC', 'compio/quic'], [['HTTP 3', 'compio/quic/http3']]], // TODO(@AsakuraMizu): Write this
4041
]
4142

4243
const cyper: Section[] = [

0 commit comments

Comments
 (0)