Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion aimdb-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ observability = ["aimdb-core/observability"]
# compiled in is rejected at resolve time.
transport-uds = ["dep:aimdb-uds-connector"]
transport-serial = ["dep:aimdb-serial-connector"]
transport-tcp = ["dep:aimdb-tcp-connector"]
# The TCP dialer comes from the adapter's `net` transports.
transport-tcp = ["dep:aimdb-tcp-connector", "aimdb-tokio-adapter/net"]

[dependencies]
# Core dependencies - protocol types from aimdb-core. `connector-session`
Expand Down
7 changes: 6 additions & 1 deletion aimdb-client/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ pub fn dial(endpoint: &str) -> ClientResult<Box<dyn Dialer>> {
Scheme::Tcp => {
#[cfg(feature = "transport-tcp")]
{
Ok(Box::new(aimdb_tcp_connector::TcpDialer::new(parsed.target)))
// The adapter owns the socket; the connector owns the
// host/port grammar.
Ok(Box::new(aimdb_tcp_connector::framed_dialer_at(
aimdb_tokio_adapter::net::TokioNet::tcp(),
&parsed.target,
)))
}
#[cfg(not(feature = "transport-tcp"))]
{
Expand Down
13 changes: 13 additions & 0 deletions aimdb-core/src/session/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,19 @@ pub struct FramingDialer<D, FF, const RC: usize = 256, const WC: usize = 256> {
port: u16,
}

/// `SessionClientConnector` clones its dialer per build, so a framed one must
/// clone too.
impl<D: Clone, FF: Clone, const RC: usize, const WC: usize> Clone for FramingDialer<D, FF, RC, WC> {
fn clone(&self) -> Self {
Self {
dialer: self.dialer.clone(),
framers: self.framers.clone(),
host: self.host.clone(),
port: self.port,
}
}
}

impl<D, FF, const RC: usize, const WC: usize> FramingDialer<D, FF, RC, WC> {
/// Dial `host:port` through `dialer`, framing each stream with a framer
/// from `framers`.
Expand Down
1 change: 1 addition & 0 deletions aimdb-embassy-adapter/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ impl ByteStream for EmbassyTcpStream {
}

/// Dials TCP connections over one caller-owned socket.
#[derive(Clone)]
pub struct EmbassyTcpDialer {
slot: Arc<TcpSocketSlot>,
}
Expand Down
14 changes: 14 additions & 0 deletions aimdb-tcp-connector/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- **One path for both runtimes (breaking).** `TcpServer::new` takes an
already-bound listener from an adapter (`TokioNet::listen`,
`EmbassyNet::listen::<N>`) instead of a bind string, and `TcpClient::new`
takes a dialer. `tokio_transport` and `embassy_transport` are deleted with the
whole `Tokio*`/`Embassy*` alias set, and with them the crate's last three
`unsafe impl`s. The library no longer depends on `tokio`, `embassy-net`,
`embassy-futures` or `embedded-io-async`.

### Added

- **`connector` — runtime-neutral `TcpClient`/`TcpServer`** over core's
`StreamDialer`/`StreamListener`, plus `framing::LengthFramer` against core's
`Framer`. `split_host_port` and `framed_dialer_at` carry the `host:port`
grammar, including bracketed IPv6 literals.
- **`tests/accept_pool.rs`** — the adapter's pooled `StreamListener` over two
crossover-wired `embassy-net` stacks, with a rebuild-and-cancel pool as the
negative control: it loses a SYN arriving between accepts, the stored-accept
Expand Down
19 changes: 6 additions & 13 deletions aimdb-tcp-connector/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ tokio-runtime = [
"std",
"aimdb-core/connector-session",
"aimdb-core/remote",
"dep:tokio",
]

embassy-runtime = [
Expand All @@ -33,16 +32,13 @@ embassy-runtime = [
"aimdb-core/remote",
"dep:aimdb-embassy-adapter",
"aimdb-embassy-adapter/connectors",
"aimdb-embassy-adapter/embassy-net-support",
"dep:embassy-net",
"dep:embassy-futures",
"dep:embedded-io-async",
"aimdb-embassy-adapter/net",
]

tracing = ["aimdb-core/tracing"]
defmt = ["aimdb-core/defmt"]

_test-tokio = ["tokio-runtime", "dep:aimdb-tokio-adapter"]
_test-tokio = ["tokio-runtime", "dep:aimdb-tokio-adapter", "aimdb-tokio-adapter/net"]

# Internal: the Embassy TCP half's runtime smoke (`tests/embassy_loopback.rs`)
# stands up two real `embassy-net` stacks wired by an in-memory driver-channel
Expand All @@ -52,9 +48,7 @@ _test-tokio = ["tokio-runtime", "dep:aimdb-tokio-adapter"]
# the `_test-tokio` build too). Run with `--features _test-embassy-loopback`.
_test-embassy-loopback = [
"embassy-runtime",
# The adapter's neutral transports, exercised by `tests/accept_pool.rs`
# over the same two real stacks as `embassy_loopback.rs`.
"aimdb-embassy-adapter/net",
"dep:embassy-net",
"embassy-net/medium-ip",
"embassy-net/proto-ipv4",
"dep:embassy-net-driver-channel",
Expand All @@ -64,12 +58,11 @@ _test-embassy-loopback = [
[dependencies]
aimdb-core = { version = "1.1.0", path = "../aimdb-core", default-features = false }

tokio = { workspace = true, optional = true, features = ["net", "io-util"] }

aimdb-embassy-adapter = { version = "0.6.0", path = "../aimdb-embassy-adapter", default-features = false, optional = true }

# Test-only: the loopback harness stands up two real stacks (see
# `_test-embassy-loopback`). The crate itself names no socket type.
embassy-net = { workspace = true, optional = true }
embassy-futures = { workspace = true, optional = true }
embedded-io-async = { workspace = true, optional = true }

aimdb-tokio-adapter = { version = "0.6.0", path = "../aimdb-tokio-adapter", optional = true }

Expand Down
10 changes: 7 additions & 3 deletions aimdb-tcp-connector/examples/tcp_demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ use aimdb_core::remote::{AimxConfig, SecurityPolicy};
use aimdb_core::session::aimx::AimxCodec;
use aimdb_core::session::{run_client, ClientConfig, Payload};
use aimdb_core::AimDbBuilder;
use aimdb_tcp_connector::tokio_transport::{TcpDialer, TcpServer};
use aimdb_tcp_connector::connector::{framed_dialer_at, TcpServer};
use aimdb_tokio_adapter::net::TokioNet;
use aimdb_tokio_adapter::{TokioAdapter, TokioRecordRegistrarExt};
use serde::{Deserialize, Serialize};
use serde_json::json;
Expand Down Expand Up @@ -73,9 +74,12 @@ async fn run_server(bind_addr: String) {
.max_connections(8)
.max_subs_per_connection(32);

let listener = TokioNet::listen(&bind_addr)
.await
.expect("bind the TCP listener");
let mut builder = AimDbBuilder::new()
.runtime(Arc::new(TokioAdapter))
.with_connector(TcpServer::new(bind_addr).with_config(config));
.with_connector(TcpServer::new(listener).with_config(config));
builder.configure::<Counter>("counter", |reg| {
reg.buffer(BufferCfg::SingleLatest).with_remote_access();
});
Expand Down Expand Up @@ -148,7 +152,7 @@ async fn run_set_mode(endpoint: String, level: u64) {

fn connect(endpoint: String) -> aimdb_core::session::ClientHandle {
let (handle, engine) = run_client(
TcpDialer::new(endpoint),
framed_dialer_at(TokioNet::tcp(), &endpoint),
AimxCodec,
ClientConfig {
sends_hello: false,
Expand Down
Loading
Loading