starpc 0.52.1 → 0.52.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -8
- package/dist/srpc/client-rpc.d.ts +1 -0
- package/dist/srpc/client-rpc.js +9 -0
- package/dist/srpc/client-rpc.test.d.ts +1 -0
- package/dist/srpc/client-rpc.test.js +50 -0
- package/dist/srpc/common-rpc.d.ts +5 -0
- package/dist/srpc/common-rpc.js +37 -8
- package/dist/srpc/errors.d.ts +2 -0
- package/dist/srpc/errors.js +14 -0
- package/dist/srpc/index.d.ts +1 -1
- package/dist/srpc/index.js +1 -1
- package/echo/Cargo.toml +8 -0
- package/echo/echo_e2e_test.cpp +542 -985
- package/echo/echo_srpc.pb.cpp +3 -5
- package/echo/echo_srpc.pb.go +6 -9
- package/echo/echo_srpc.pb.hpp +23 -3
- package/echo/echo_srpc.pb.rs +61 -26
- package/echo/echo_srpc.py +4 -1
- package/echo/half_close_test.rs +178 -0
- package/echo/integration_server.rs +14 -21
- package/echo/main.rs +28 -48
- package/go.mod +1 -1
- package/go.sum +2 -18
- package/integration/cross-language/cpp-client.cpp +446 -402
- package/integration/cross-language/cpp-pipe-server.cpp +139 -0
- package/integration/cross-language/cpp-pipe_test.go +114 -0
- package/integration/cross-language/cpp-server.cpp +222 -186
- package/mock/mock_srpc.pb.cpp +1 -1
- package/mock/mock_srpc.pb.hpp +1 -1
- package/mock/mock_srpc.pb.rs +10 -9
- package/package.json +1 -1
- package/srpc/CMakeLists.txt +3 -58
- package/srpc/README-cpp.md +69 -0
- package/srpc/accept.go +10 -4
- package/srpc/accept_test.go +25 -0
- package/srpc/build.rs +129 -34
- package/srpc/client-half-close_test.go +152 -0
- package/srpc/client-invoker.go +32 -42
- package/srpc/client-invoker_test.go +53 -0
- package/srpc/client-rpc.cpp +65 -80
- package/srpc/client-rpc.go +32 -33
- package/srpc/client-rpc.hpp +52 -38
- package/srpc/client-rpc.test.ts +67 -0
- package/srpc/client-rpc.ts +10 -0
- package/srpc/client-rpc_test.go +76 -0
- package/srpc/client.cpp +99 -87
- package/srpc/client.hpp +46 -35
- package/srpc/client.rs +78 -38
- package/srpc/client_half_close_test.cc +331 -0
- package/srpc/client_invoker.rs +75 -0
- package/srpc/common-rpc.cpp +186 -146
- package/srpc/common-rpc.go +5 -4
- package/srpc/common-rpc.hpp +119 -89
- package/srpc/common-rpc.ts +43 -8
- package/srpc/common-rpc_test.go +23 -0
- package/srpc/error.rs +19 -2
- package/srpc/errors.hpp +80 -50
- package/srpc/errors.ts +16 -0
- package/srpc/handler.hpp +9 -7
- package/srpc/handler.rs +7 -45
- package/srpc/index.ts +2 -0
- package/srpc/invoker.hpp +82 -55
- package/srpc/invoker.rs +14 -52
- package/srpc/lib.rs +2 -0
- package/srpc/message.hpp +17 -12
- package/srpc/msg-stream.go +1 -0
- package/srpc/msg-stream.hpp +108 -61
- package/srpc/mux.cpp +84 -84
- package/srpc/mux.hpp +48 -38
- package/srpc/mux.rs +4 -4
- package/srpc/net.go +12 -3
- package/srpc/packet.cpp +60 -58
- package/srpc/packet.hpp +35 -20
- package/srpc/packet.rs +8 -27
- package/srpc/rpc.rs +332 -115
- package/srpc/rpc_lifecycle_test.cc +333 -0
- package/srpc/server-cancel_test.go +39 -0
- package/srpc/server-rpc.cpp +83 -73
- package/srpc/server-rpc.go +21 -19
- package/srpc/server-rpc.hpp +56 -37
- package/srpc/server.rs +76 -131
- package/srpc/starpc.hpp +4 -2
- package/srpc/stream.go +4 -0
- package/srpc/stream.hpp +95 -34
- package/srpc/stream.rs +7 -2
- package/srpc/testing.rs +11 -66
- package/srpc/transport.rs +21 -71
- package/srpc/websocket.rs +106 -57
- package/srpc/writer.hpp +46 -32
- package/srpc/yamux.rs +82 -26
- package/srpc/tests/integration_test.rs +0 -495
package/echo/main.rs
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
//! echo service that supports unary, server streaming, client streaming,
|
|
5
5
|
//! and bidirectional streaming RPCs.
|
|
6
6
|
|
|
7
|
+
// This example uses only part of the generated service surface.
|
|
8
|
+
#[allow(dead_code)]
|
|
7
9
|
mod gen;
|
|
8
10
|
|
|
9
11
|
use std::sync::Arc;
|
|
@@ -19,22 +21,13 @@ struct EchoServerImpl;
|
|
|
19
21
|
|
|
20
22
|
#[async_trait]
|
|
21
23
|
impl EchoerServer for EchoServerImpl {
|
|
22
|
-
async fn echo(&self, request: EchoMsg) -> Result<EchoMsg> {
|
|
24
|
+
async fn echo(&self, _context: &starpc::Context, request: EchoMsg) -> Result<EchoMsg> {
|
|
23
25
|
println!("Server: received echo request: {:?}", request.body);
|
|
24
|
-
Ok(EchoMsg {
|
|
25
|
-
body: request.body,
|
|
26
|
-
})
|
|
26
|
+
Ok(EchoMsg { body: request.body })
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
async fn echo_server_stream(
|
|
30
|
-
|
|
31
|
-
request: EchoMsg,
|
|
32
|
-
stream: Box<dyn Stream>,
|
|
33
|
-
) -> Result<()> {
|
|
34
|
-
println!(
|
|
35
|
-
"Server: received server stream request: {:?}",
|
|
36
|
-
request.body
|
|
37
|
-
);
|
|
29
|
+
async fn echo_server_stream(&self, request: EchoMsg, stream: Box<dyn Stream>) -> Result<()> {
|
|
30
|
+
println!("Server: received server stream request: {:?}", request.body);
|
|
38
31
|
|
|
39
32
|
// Send multiple responses.
|
|
40
33
|
for i in 0..5 {
|
|
@@ -65,11 +58,9 @@ impl EchoerServer for EchoServerImpl {
|
|
|
65
58
|
}
|
|
66
59
|
|
|
67
60
|
// Return combined response (the handler will send it automatically).
|
|
68
|
-
|
|
61
|
+
Ok(EchoMsg {
|
|
69
62
|
body: messages.join(", "),
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
Ok(response)
|
|
63
|
+
})
|
|
73
64
|
}
|
|
74
65
|
|
|
75
66
|
async fn echo_bidi_stream(&self, stream: Box<dyn Stream>) -> Result<()> {
|
|
@@ -95,53 +86,42 @@ impl EchoerServer for EchoServerImpl {
|
|
|
95
86
|
Err(Error::Unimplemented)
|
|
96
87
|
}
|
|
97
88
|
|
|
98
|
-
async fn do_nothing(
|
|
89
|
+
async fn do_nothing(
|
|
90
|
+
&self,
|
|
91
|
+
_context: &starpc::Context,
|
|
92
|
+
_request: gen::Empty,
|
|
93
|
+
) -> Result<gen::Empty> {
|
|
99
94
|
Ok(gen::Empty {})
|
|
100
95
|
}
|
|
101
96
|
}
|
|
102
97
|
|
|
98
|
+
/// Binds the server before connecting and retains both operations until their call completes.
|
|
103
99
|
#[tokio::main]
|
|
104
100
|
async fn main() -> Result<()> {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
let server_handle = tokio::spawn(run_server(addr.to_string()));
|
|
109
|
-
|
|
110
|
-
// Wait for the server to start.
|
|
111
|
-
tokio::time::sleep(tokio::time::Duration::from_millis(100)).await;
|
|
112
|
-
|
|
113
|
-
// Run the client.
|
|
114
|
-
run_client(addr).await?;
|
|
115
|
-
|
|
116
|
-
// Stop the server.
|
|
117
|
-
server_handle.abort();
|
|
101
|
+
// Listener construction is the readiness capability used by the client.
|
|
102
|
+
let listener = TcpListener::bind("127.0.0.1:0").await?;
|
|
103
|
+
let address = listener.local_addr()?.to_string();
|
|
118
104
|
|
|
105
|
+
// Both futures remain owned here, so failure or cancellation releases the other side.
|
|
106
|
+
tokio::try_join!(run_server(listener), run_client(&address))?;
|
|
119
107
|
println!("Example completed successfully!");
|
|
120
108
|
Ok(())
|
|
121
109
|
}
|
|
122
110
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
// Create the mux and register our handler.
|
|
111
|
+
/// Serves the one connection used by this example through the ordinary server owner.
|
|
112
|
+
async fn run_server(listener: TcpListener) -> Result<()> {
|
|
113
|
+
// Publish the handler before accepting the paired client's connection.
|
|
114
|
+
println!("Server listening on {}", listener.local_addr()?);
|
|
128
115
|
let mux = Arc::new(Mux::new());
|
|
129
116
|
mux.register(Arc::new(EchoerHandler::new(EchoServerImpl)))?;
|
|
130
117
|
|
|
131
|
-
//
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
let server = Server::with_arc(mux.clone());
|
|
137
|
-
tokio::spawn(async move {
|
|
138
|
-
if let Err(e) = server.handle_stream(stream).await {
|
|
139
|
-
eprintln!("Server error: {}", e);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
}
|
|
118
|
+
// Return only after the actual call and its packet reader have finished.
|
|
119
|
+
let (stream, peer_address) = listener.accept().await?;
|
|
120
|
+
println!("Server: accepted connection from {}", peer_address);
|
|
121
|
+
Server::with_arc(mux).handle_stream(stream).await
|
|
143
122
|
}
|
|
144
123
|
|
|
124
|
+
/// Runs a unary call over one connection and verifies its exact response.
|
|
145
125
|
async fn run_client(addr: &str) -> Result<()> {
|
|
146
126
|
println!("\nClient: connecting to {}", addr);
|
|
147
127
|
|
package/go.mod
CHANGED
|
@@ -29,6 +29,6 @@ require (
|
|
|
29
29
|
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
|
|
30
30
|
github.com/tetratelabs/wazero v1.12.0 // indirect
|
|
31
31
|
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 // indirect
|
|
32
|
-
golang.org/x/mod v0.
|
|
32
|
+
golang.org/x/mod v0.40.0 // indirect
|
|
33
33
|
golang.org/x/sys v0.47.0 // indirect
|
|
34
34
|
)
|
package/go.sum
CHANGED
|
@@ -2,26 +2,10 @@ github.com/aperturerobotics/abseil-cpp v0.0.0-20260131110040-4bb56e2f9017 h1:3U7
|
|
|
2
2
|
github.com/aperturerobotics/abseil-cpp v0.0.0-20260131110040-4bb56e2f9017/go.mod h1:lNSJTKECIUFAnfeSqy01kXYTYe1BHubW7198jNX3nEw=
|
|
3
3
|
github.com/aperturerobotics/cli v1.1.0 h1:7a+YRC+EY3npAnTzhHV5gLCiw91KS0Ts3XwLILGOsT8=
|
|
4
4
|
github.com/aperturerobotics/cli v1.1.0/go.mod h1:M7BFP9wow5ytTzMyJQOOO991fGfsUqdTI7gGEsHfTQ8=
|
|
5
|
-
github.com/aperturerobotics/common v0.34.4 h1:RQTOm6LxEnucXkED/kruhKKAOL6tbaPzMgfHPKaES4k=
|
|
6
|
-
github.com/aperturerobotics/common v0.34.4/go.mod h1:xnb1VBRs3x2o1PaKg0OlP7SqDaC9Hmrmt9xH85rOS+A=
|
|
7
|
-
github.com/aperturerobotics/common v0.35.0 h1:VU4OPMXJyqT37lTOtNEMa3QLW5tR8YIBAKbjgxSzuZs=
|
|
8
|
-
github.com/aperturerobotics/common v0.35.0/go.mod h1:xnb1VBRs3x2o1PaKg0OlP7SqDaC9Hmrmt9xH85rOS+A=
|
|
9
|
-
github.com/aperturerobotics/common v0.35.1-0.20260808094909-49d3232b4f83 h1:QkFoyeJ0QBw21a+1YR0kB+JaBSY2mHFiIGiFwWUJ/wQ=
|
|
10
|
-
github.com/aperturerobotics/common v0.35.1-0.20260808094909-49d3232b4f83/go.mod h1:sPjrQZeS/yr9kBro4rN2BrYvG9TCn1eIGk7dMH/E2NQ=
|
|
11
|
-
github.com/aperturerobotics/common v0.35.1-0.20260808095531-8f6fd4367389 h1:J/vc+AKFh8hIVJJ2LrAJVwEgIYvFeQ5XANg3dK3OnYk=
|
|
12
|
-
github.com/aperturerobotics/common v0.35.1-0.20260808095531-8f6fd4367389/go.mod h1:sPjrQZeS/yr9kBro4rN2BrYvG9TCn1eIGk7dMH/E2NQ=
|
|
13
|
-
github.com/aperturerobotics/common v0.35.1-0.20260808100945-fe2b561bec93 h1:Bc7ThfLt5ekHZmOH9vGW0PiiuVUl1R+vneFH/G0j5D4=
|
|
14
|
-
github.com/aperturerobotics/common v0.35.1-0.20260808100945-fe2b561bec93/go.mod h1:sPjrQZeS/yr9kBro4rN2BrYvG9TCn1eIGk7dMH/E2NQ=
|
|
15
|
-
github.com/aperturerobotics/common v0.35.1-0.20260808101203-caeb6303ba93 h1:JoERBAX9HuOzopNLZQCT851YnYz9h9nYSpEe6XjcP0o=
|
|
16
|
-
github.com/aperturerobotics/common v0.35.1-0.20260808101203-caeb6303ba93/go.mod h1:sPjrQZeS/yr9kBro4rN2BrYvG9TCn1eIGk7dMH/E2NQ=
|
|
17
|
-
github.com/aperturerobotics/common v0.35.1-0.20260808102028-33a08259dd38 h1:c3IXUqJHt1EAlCyD0d0IrI7YYf4txwICtoh+ylQV6tU=
|
|
18
|
-
github.com/aperturerobotics/common v0.35.1-0.20260808102028-33a08259dd38/go.mod h1:sPjrQZeS/yr9kBro4rN2BrYvG9TCn1eIGk7dMH/E2NQ=
|
|
19
5
|
github.com/aperturerobotics/common v0.35.1-0.20260808123156-c77af26f63bd h1:BTfB1V2X+u3/56negSjrx+AWg+Uk84rFFryvpGTj7f4=
|
|
20
6
|
github.com/aperturerobotics/common v0.35.1-0.20260808123156-c77af26f63bd/go.mod h1:sPjrQZeS/yr9kBro4rN2BrYvG9TCn1eIGk7dMH/E2NQ=
|
|
21
7
|
github.com/aperturerobotics/go-protoc-gen-prost v0.0.0-20260705010911-9f53feac967b h1:MMk+AbWPCMfqc2Lm2bJl8lCCsuvlM2+C0CP10fpE3bc=
|
|
22
8
|
github.com/aperturerobotics/go-protoc-gen-prost v0.0.0-20260705010911-9f53feac967b/go.mod h1:OBb/beWmr/pDIZAUfi86j/4tBh2v5ctTxKMqSnh9c/4=
|
|
23
|
-
github.com/aperturerobotics/go-protoc-wasi v0.0.0-20260712054757-d8078c296c17 h1:WT1YmZjJf8fUF1zKbeNNKXFA+t8Wtbr8AVMAmdKcrUU=
|
|
24
|
-
github.com/aperturerobotics/go-protoc-wasi v0.0.0-20260712054757-d8078c296c17/go.mod h1:vEq8i7EKb32+KXGtIEZjjhNns+BdsL2dUMw4uhy3578=
|
|
25
9
|
github.com/aperturerobotics/go-protoc-wasi v0.0.0-20260808023521-7b1595380c3f h1:UszdpmKBfQd0LdOZjypeRGrHz2tcPpmKpw6SV3DYyN0=
|
|
26
10
|
github.com/aperturerobotics/go-protoc-wasi v0.0.0-20260808023521-7b1595380c3f/go.mod h1:vEq8i7EKb32+KXGtIEZjjhNns+BdsL2dUMw4uhy3578=
|
|
27
11
|
github.com/aperturerobotics/go-websocket v1.8.15-0.20260619192713-a096778f08c1 h1:q2qkdNOrnhAFf6B7TBeUoAYstYWxPvozN+3vJi2jgp0=
|
|
@@ -54,8 +38,8 @@ github.com/tetratelabs/wazero v1.12.0 h1:DuWcpNu/FzgEXgGBDp8J1Spc+CWOvvtvVyjKlaZ
|
|
|
54
38
|
github.com/tetratelabs/wazero v1.12.0/go.mod h1:LvKtzl2RqO4gyF27BiXU+nKAjcV8f38U+kP/q2vgxh0=
|
|
55
39
|
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342 h1:FnBeRrxr7OU4VvAzt5X7s6266i6cSVkkFPS0TuXWbIg=
|
|
56
40
|
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM=
|
|
57
|
-
golang.org/x/mod v0.
|
|
58
|
-
golang.org/x/mod v0.
|
|
41
|
+
golang.org/x/mod v0.40.0 h1:hUv+3cXcdRHz08UmSiOob7sadHig73uo5bkXxQ/tvUs=
|
|
42
|
+
golang.org/x/mod v0.40.0/go.mod h1:0/weTWkPWGBikyTWAX3dkjVztMmBA5hM0DH6BElSupE=
|
|
59
43
|
golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs=
|
|
60
44
|
golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
|
61
45
|
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
|