Skip to content

Commit c3cff58

Browse files
committed
Fix types and remove outdated doc
1 parent ea3d783 commit c3cff58

5 files changed

Lines changed: 42 additions & 107 deletions

File tree

docs/client_macros.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ The `#[client_task_enum]` and `#[client_task]` procedural macro simplifies the i
55
`#[client_task]` attribute allows users to define a struct representing an RPC task and specify its common fields, request, response, and optional blob data using `#[field(...)]` attributes.
66
It will not generate ClientTask trait because the ClientTaskAction is optional for task variants.
77

8-
`#[client_task_enum]` attribute allow user to wrap an enum and delegate the ClienTask trait requirements to it's variants.
9-
It will generate ClientTask trait and the ClientTaskAction according to #[action()] specified for enum variants.
8+
`#[client_task_enum]` attribute allows users to wrap an enum and delegate the ClientTask trait requirements to its variants.
9+
It will generate the ClientTask trait and the ClientTaskAction according to the #[action()] specified for enum variants.
1010

1111
### `#[action]` on enum variants
1212

@@ -30,7 +30,7 @@ pub enum FileTask {
3030
Close(FileCloseTask),
3131
}
3232

33-
// This task does not need to specify an action, as it's handled by the enum variant.
33+
// This task does not need to specify an action, as it is handled by the enum variant.
3434
#[client_task]
3535
pub struct FileOpenTask {
3636
#[field(common)]
@@ -73,12 +73,12 @@ The macro processes specific fields within the task struct based on the `#[field
7373
* **Requirements:** This field is mandatory. The macro generates `Deref` and `DerefMut` implementations for the task struct, delegating to this `common` field. This allows direct access to the common fields of the task struct.
7474

7575
* `#[field(action)]`
76-
* Purpose: implement ClientTaskAction trait to return RpcAction according to the field
77-
* Requirements: there's no `action=` specified within the client_task attribute. the field is a numeric or string type, or an enum type that repr by number.
76+
* Purpose: Implement the ClientTaskAction trait to return an RpcAction according to the field.
77+
* Requirements: There is no `action=` specified within the `client_task` attribute. The field is a numeric or string type, or an enum type that is represented by a number.
7878

79-
* attribute parameter action in `#[client_task(action=...)]`
80-
* Purpose: implement ClientTaskAction trait with a static value
81-
* Requirements: there's no `#[field(action)]` specified within the struct. `action()` parameter must be only one, can be numeric, or string, or an enum repr by number.
79+
* attribute parameter `action` in `#[client_task(action=...)]`
80+
* Purpose: Implement the ClientTaskAction trait with a static value.
81+
* Requirements: There is no `#[field(action)]` specified within the struct. The `action()` parameter must be only one, and can be numeric, a string, or an enum represented by a number.
8282

8383
* `#[field(req)]`:
8484
* **Purpose:** Designates the field containing the request payload for the RPC call.
@@ -112,11 +112,11 @@ The `#[client_task]` macro automatically generates the following trait implement
112112

113113
* `ClientTaskEncode`:
114114
* `encode_req<C: occams_rpc::codec::Codec>(&self, codec: &C) -> Result<Vec<u8>, ()>`: Encodes the content of the `#[field(req)]` field using the provided codec.
115-
* `get_req_blob(&self) -> Option<&[u8]>`: If `#[field(req_blob)]` is present, returns `Some` reference to the blob data; otherwise, it returns `None`.
115+
* `get_req_blob(&self) -> Option<&[u8]>`: If `#[field(req_blob)]` is present, returns a `Some` reference to the blob data; otherwise, it returns `None`.
116116

117117
* `ClientTaskDecode`:
118118
* `decode_resp<C: occams_rpc::codec::Codec>(&mut self, codec: &C, buffer: &[u8]) -> Result<(), ()>`: Decodes the response buffer using the provided codec and stores the result in the `#[field(resp)]` field.
119-
* `get_resp_blob_mut(&mut self) -> Option<&mut impl occams_rpc::io::AllocateBuf>`: If `#[field(resp_blob)]` is present, returns `Some` mutable reference to the response blob `Option<T>`; otherwise, it returns `None`.
119+
* `get_resp_blob_mut(&mut self) -> Option<&mut impl occams_rpc::io::AllocateBuf>`: If `#[field(resp_blob)]` is present, returns a `Some` mutable reference to the response blob `Option<T>`; otherwise, it returns `None`.
120120

121121
* `ClientTaskDone`:
122122
* This trait is implemented when `#[field(res)]` and `#[field(noti)]` are present.
@@ -131,7 +131,7 @@ The `#[client_task]` macro automatically generates the following trait implement
131131
}
132132
```
133133

134-
* when `#[client_task(debug)]` is specified, you will get a more specified Debug generated according to `req` and `resp` field
134+
* when `#[client_task(debug)]` is specified, you will get a more specific Debug generated according to the `req` and `resp` fields
135135
```rust
136136
impl std::fmt::Debug for T {
137137
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
@@ -145,7 +145,7 @@ The `#[client_task]` macro automatically generates the following trait implement
145145
```
146146

147147

148-
The `#[client_task_enum]` will implement `From` to assist convertion from it's variants to parent enum, and delegating `ClienTaskEnode`, `ClientTaskDecode`, `ClientTaskAction`, `RpcClientTask` to it's variants.
148+
The `#[client_task_enum]` will implement `From` to assist conversion from its variants to the parent enum, and delegate `ClientTaskEncode`, `ClientTaskDecode`, `ClientTaskAction`, and `RpcClientTask` to its variants.
149149

150150
## User Responsibilities
151151

docs/client_task_v1.md

Lines changed: 0 additions & 61 deletions
This file was deleted.

docs/design_v2.md

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
## Design goal
44

5-
A modular, plugable RPC that supports various async runtimes.
5+
A modular, pluggable RPC that supports various async runtimes.
66

77
* interface types:
88
- stream: Interface for stream processing.
99
- api: Interface for remote function call.
1010
* transport types:
1111
- TCP transport: optimized for high throughput internal network.
1212
- RDMA transport: optimized for low latency internal network.
13-
- Quic transport: optimized for high throughput public network.
13+
- QUIC transport: optimized for high throughput public network.
1414
* codec:
1515
- Msgpack
1616
- bincode
@@ -22,13 +22,13 @@ A modular, plugable RPC that supports various async runtimes.
2222

2323
### Stream protocol
2424

25-
str/stream/proto.rs: Defines general proto
25+
src/stream/proto.rs: Defines general proto
2626

27-
`RpcAction`: numeric action is for fewer type variants, while string action is for the implmentation of API interface.
27+
`RpcAction`: A numeric action is for fewer type variants, while a string action is for the implementation of the API interface.
2828

29-
Request format: each request package has a fixed-length header (ReqHead), then followed by structured encoded "msg", then optionally followed by a "blob" (which allocated as owned buffer).
29+
Request format: Each request package has a fixed-length header (ReqHead), followed by a structured encoded "msg", and then optionally followed by a "blob" (which is allocated as an owned buffer).
3030

31-
Response format: each reponse package has a fixed-length header (RespHead), then followed by structured encoded "msg", then optionally followed by a "blob" (which allocated as owned buffer)
31+
Response format: Each response package has a fixed-length header (RespHead), followed by a structured encoded "msg", and then optionally followed by a "blob" (which is allocated as an owned buffer)
3232

3333
### Stream Client
3434

@@ -37,63 +37,59 @@ Response format: each reponse package has a fixed-length header (RespHead), then
3737

3838
src/stream/server.rs:
3939

40-
`ServerFactory` is the interafce for user can assign or customize with various plugin (transport, codec, ...)
40+
`ServerFactory` is the interface for a user to assign or customize with various plugins (transport, codec, etc.).
4141

4242
src/stream/server_impl.rs:
4343

44-
`RpcServer` is the server implementation, listen and accept connections through transport. The new connection is process by ServerHandle::run interface. We typically use the `ServerHandleTaskStream` implmentation, which utilizes a coroutine to read and a coroutine to write, so that the throughput can at max use 2 cpu cores with one connection.
44+
`RpcServer` is the server implementation, which listens for and accepts connections through the transport. The new connection is processed by the ServerHandle::run interface. We typically use the `ServerHandleTaskStream` implementation, which utilizes a coroutine to read and a coroutine to write, so that the throughput can use at most 2 CPU cores with one connection.
4545

46-
We intended to support service-level graceful restart and graceful shutdown.
46+
We intend to support service-level graceful restart and graceful shutdown.
4747

48-
As a packet received by server, should have gone through the steps:
48+
A packet received by the server should have gone through the following steps:
4949

5050
decode -> request task -> dispatch -> processed -> response task -> encode -> write
5151

5252
#### decode
5353

54-
An enum task should impl ServerTaskDecode::decode_req(action ... ), regconize sub task type by RpcAction.
54+
An enum task should implement ServerTaskDecode::decode_req(action ... ), and recognize the sub-task type by RpcAction.
5555

56-
For numeric, more used in the stream interface, suitable to use a generated match to call the sub types decode_req.
56+
For numeric actions, which are more used in the stream interface, it is suitable to use a generated match to call the sub-type's decode_req.
5757

5858
The macro can be:
5959

6060
```
6161
6262
#[server_task_enum]
6363
pub enum MyServerTask {
64-
[action=xxx]
64+
#[action=xxx]
6565
Type1(SubType1)
66-
[action=xxx]
66+
#[action=xxx]
6767
Type2(SubType2)
6868
}
6969
```
7070

71-
(action may be num or "string")
71+
(action may be a number or a string)
7272

73-
For SubType1, need to generate MyServerTask::From SubType1. If user process using SubType, and call subtype::set_result(), should transform into() the supertype to call RpcRespNoti.done().
73+
For SubType1, we need to generate MyServerTask::From<SubType1>. If a user processes using SubType and calls subtype::set_result(), it should be transformed via into() into the supertype to call RpcRespNoti.done().
7474

75-
If user use the ServerTaskVariant/ServerTaskVariantFull generic as subtype, which already implemented ServerTaskEncode/Encode,
76-
they cannot impl they own method due to the "Orphan Rule" limitation of Rust,
77-
they should impl wrapper types with new-type pattern. (It's not certain for me Deref, should test)
75+
If a user uses the ServerTaskVariant/ServerTaskVariantFull generic as a subtype, which has already implemented ServerTaskEncode/Encode, they cannot implement their own methods due to the "Orphan Rule" limitation of Rust. They should implement wrapper types with the new-type pattern. (I'm not certain about Deref, I should test it).
7876

7977
So the macro is on MyServerTask:
8078

81-
* Need to assign action for the variants for ServerTaskDecode::decode_req, provides get_action(&self) for user
79+
* Need to assign an action for the variants for ServerTaskDecode::decode_req, which provides get_action(&self) for the user
8280

83-
* Need to impl From variants
81+
* Need to implement From for variants
8482

85-
For string, might used in the API interface, can be first match in a HashMap to decide which class to handle, an decode accoding to string (class::method) to a specified Req type.
83+
For a string, which might be used in the API interface, it can be first matched in a HashMap to decide which class to handle, and decoded according to the string (class::method) to a specified Req type.
8684

8785

8886
#### Dispatch
8987

90-
The dispatcher is repsponsible for decode the task and dispatch to backend processing. (There may be struct like worker pool in other threads/coroutines to handle)
88+
The dispatcher is responsible for decoding the task and dispatching it to the backend for processing. (There may be a struct like a worker pool in other threads/coroutines to handle this).
9189

92-
Codec is intend to support encryption, so there should be shared state, need to initialized as Arc<Codec> share between
93-
conn reader and writer. Therefore, The dispatcher should be a Arc being shared between reader and writer.
90+
The codec is intended to support encryption, so there should be a shared state, which needs to be initialized as an Arc<Codec> and shared between the connection reader and writer. Therefore, the dispatcher should be an Arc shared between the reader and writer.
9491

95-
Because the connection of reader and writer is parallel, we should define ReqDispatch trait and RespReceiver trait separately. The ReqDispatch relies on RespReceiver because it should know about the task type of done channel.
92+
Because the reader and writer for a connection are parallel, we should define the ReqDispatch and RespReceiver traits separately. The ReqDispatch trait relies on RespReceiver because it needs to know about the task type of the done channel.
9693

97-
We set RespReceiver in ServerFactory as an associate type. but we leave the ReqDispatch to be infered From
98-
` fn new_dispatcher(&self) -> impl ReqDispatch<Self::RespReceiver>``, because like TaskReqDispatch, usually comes with
99-
closure capturing the connext about how to dispatch the task. There may be a Fn or a struct defined by user.
94+
We set RespReceiver in ServerFactory as an associated type, but we leave ReqDispatch to be inferred from
95+
` fn new_dispatcher(&self) -> impl ReqDispatch<Self::RespReceiver>``, because, like TaskReqDispatch, it usually comes with a closure capturing the context about how to dispatch the task. This may be a Fn or a struct defined by the user.

docs/server_macros.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ pub enum ServerTask {
4949
Task1(SubTask1),
5050
}
5151

52-
#[server_task_enum(resp)] // Example with only resp, resp_type and action is not required
52+
#[server_task_enum(resp)] // Example with only resp, resp_type and action are not required
5353
#[derive(Debug)]
5454
pub enum ServerTask {
5555
Task1(SubTask1),
5656
}
5757
```
5858

59-
The `#[action()]` can contain multiple items, separated with comma. Then it will call the SubType::decode_req in multiple situtation.
60-
In this case the SubType is required to impl `ServerTaskAction` trait to return the actual action it stored
59+
The `#[action()]` can contain multiple items, separated by a comma. It will then call SubType::decode_req in multiple situations.
60+
In this case, the SubType is required to implement the `ServerTaskAction` trait to return the actual action it stored.
6161

6262
```rust
6363
#[server_task_enum(req, resp_type = RpcResp)] // Example with only req, resp_type is required
@@ -72,7 +72,7 @@ pub struct SubTask1 {
7272
...
7373
}
7474

75-
When the `#[action()]` item is not numeric, nor string, it can be an one or multiple Enum value, in this case the value conver to number when parsing.
75+
When an `#[action()]` item is not numeric or a string, it can be one or more Enum values. In this case, the value is converted to a number when parsing.
7676

7777
``` rust
7878
#[server_task_enum(req, resp_type = RpcResp)] // Example with only req, resp_type is required

transport_tcp/src/graceful.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn write_pid_file(run_dir: &str, prog_name: &str) -> std::io::Result<()> {
3535
Ok(())
3636
}
3737

38-
/// Call after program is fork. Use a seperate empty file to notify parent that child has started up.
38+
/// Call after program is fork. Use a separate empty file to notify parent that child has started up.
3939
fn write_child_pid_file(run_dir: &str, prog_name: &str) -> std::io::Result<()> {
4040
let pid_file_path = Path::new(run_dir).join(format!("{}_{}", prog_name, process::id()));
4141
std::fs::File::create(pid_file_path.to_str().unwrap())?;

0 commit comments

Comments
 (0)