Skip to content

Commit 7052a91

Browse files
committed
feat(transport): start working on transport metering & metrics
1 parent d036a78 commit 7052a91

14 files changed

Lines changed: 274 additions & 14 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
*.svg
55
*.log
66
.DS_Store
7+
8+
todo.md

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ thiserror = "1"
5555
tracing = "0.1"
5656
rustc-hash = "1"
5757
rand = "0.8"
58+
libc = "0.2"
5859

5960
# networking
6061
quinn = "0.11.9"

msg-socket/src/req/driver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type ConnectionTask<Io, Err> = Pin<Box<dyn Future<Output = Result<Io, Err>> + Se
3434
type ConnectionCtl<Io, Addr> = ConnectionState<Framed<Io, reqrep::Codec>, ExponentialBackoff, Addr>;
3535

3636
/// The request socket driver. Endless future that drives
37-
/// the the socket forward.
37+
/// the socket forward.
3838
pub(crate) struct ReqDriver<T: Transport<A>, A: Address> {
3939
/// Options shared with the socket.
4040
pub(crate) options: Arc<ReqOptions>,

msg-socket/src/req/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ pub struct ReqOptions {
5757
/// Default is `None`, and the connection is flushed after every send.
5858
flush_interval: Option<std::time::Duration>,
5959
/// The maximum number of bytes that can be buffered in the session before being flushed.
60-
/// This internally sets [`Framed::set_backpressure_boundary`](tokio_util::codec::Framed).
60+
/// This internally sets
61+
/// [`Framed::set_backpressure_boundary`](tokio_util::codec::Framed::set_backpressure_boundary).
6162
backpressure_boundary: usize,
6263
/// The maximum number of retry attempts. If `None`, the connection will retry indefinitely.
6364
retry_attempts: Option<usize>,
@@ -182,5 +183,6 @@ impl ReqMessage {
182183
/// The request socket state, shared between the backend task and the socket.
183184
#[derive(Debug, Default)]
184185
pub(crate) struct SocketState {
186+
/// The socket stats.
185187
pub(crate) stats: SocketStats<ReqStats>,
186188
}

msg-socket/src/req/socket.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use super::{Command, DEFAULT_BUFFER_SIZE, ReqError, ReqOptions};
1313
use crate::{
1414
ConnectionState, ExponentialBackoff, ReqMessage,
1515
req::{SocketState, driver::ReqDriver, stats::ReqStats},
16+
stats::SocketStats,
1617
};
1718

1819
/// The request socket.
@@ -82,8 +83,9 @@ where
8283
self
8384
}
8485

85-
pub fn stats(&self) -> &ReqStats {
86-
&self.state.stats.specific
86+
/// Returns the socket stats.
87+
pub fn stats(&self) -> &SocketStats<ReqStats> {
88+
&self.state.stats
8789
}
8890

8991
pub async fn request(&self, message: Bytes) -> Result<Bytes, ReqError> {

msg-socket/src/stats.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use std::fmt::Debug;
22

3+
/// Statistics for a socket
34
#[derive(Debug)]
45
pub struct SocketStats<S> {
6+
/// Socket-specific stats.
57
pub(crate) specific: S,
68
}
79

msg-socket/src/sub/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl<A: Address> PubMessage<A> {
158158
}
159159

160160
/// The subscriber socket state, shared between the backend task and the socket frontend.
161-
#[derive(Debug)] // Should derive default fine now
161+
#[derive(Debug)]
162162
pub(crate) struct SocketState<A: Address> {
163163
pub(crate) stats: SocketStats<SubStats<A>>,
164164
}
@@ -184,7 +184,7 @@ mod tests {
184184
use super::*;
185185

186186
async fn spawn_listener() -> SocketAddr {
187-
let listener = TcpListener::bind("0.0.0.0:0").await.unwrap();
187+
let listener = TcpListener::bind("[::]:0").await.unwrap();
188188

189189
let addr = listener.local_addr().unwrap();
190190

msg-transport/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ tokio.workspace = true
1919
tracing.workspace = true
2020
thiserror.workspace = true
2121

22+
libc.workspace = true
23+
2224
# QUIC
2325
quinn = { workspace = true, optional = true }
2426
rcgen = { workspace = true, optional = true }

msg-transport/src/ipc/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{
22
io,
3+
os::fd::{AsRawFd, RawFd},
34
path::PathBuf,
45
pin::Pin,
56
task::{Context, Poll},
@@ -51,6 +52,12 @@ pub struct IpcStream {
5152
stream: UnixStream,
5253
}
5354

55+
impl AsRawFd for IpcStream {
56+
fn as_raw_fd(&self) -> RawFd {
57+
self.stream.as_raw_fd()
58+
}
59+
}
60+
5461
impl IpcStream {
5562
pub async fn connect(peer: PathBuf) -> io::Result<Self> {
5663
let stream = UnixStream::connect(&peer).await?;

0 commit comments

Comments
 (0)