Skip to content

Commit 30a4901

Browse files
authored
bindings: mark Connection as Sync (#4467)
1 parent 3926a45 commit 30a4901

File tree

6 files changed

+29
-7
lines changed

6 files changed

+29
-7
lines changed

bindings/rust/s2n-tls-sys/templates/Cargo.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "s2n-tls-sys"
33
description = "A C99 implementation of the TLS/SSL protocols"
4-
version = "0.1.7"
4+
version = "0.2.0"
55
authors = ["AWS s2n"]
66
edition = "2021"
77
rust-version = "1.63.0"

bindings/rust/s2n-tls-tokio/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "s2n-tls-tokio"
33
description = "An implementation of TLS streams for Tokio built on top of s2n-tls"
4-
version = "0.1.7"
4+
version = "0.2.0"
55
authors = ["AWS s2n"]
66
edition = "2021"
77
rust-version = "1.63.0"
@@ -15,7 +15,7 @@ default = []
1515
errno = { version = "0.3" }
1616
libc = { version = "0.2" }
1717
pin-project-lite = { version = "0.2" }
18-
s2n-tls = { version = "=0.1.7", path = "../s2n-tls" }
18+
s2n-tls = { version = "=0.2.0", path = "../s2n-tls" }
1919
tokio = { version = "1", features = ["net", "time"] }
2020

2121
[dev-dependencies]

bindings/rust/s2n-tls/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "s2n-tls"
33
description = "A C99 implementation of the TLS/SSL protocols"
4-
version = "0.1.7"
4+
version = "0.2.0"
55
authors = ["AWS s2n"]
66
edition = "2021"
77
rust-version = "1.63.0"
@@ -19,7 +19,7 @@ testing = ["bytes"]
1919
bytes = { version = "1", optional = true }
2020
errno = { version = "0.3" }
2121
libc = "0.2"
22-
s2n-tls-sys = { version = "=0.1.7", path = "../s2n-tls-sys", features = ["internal"] }
22+
s2n-tls-sys = { version = "=0.2.0", path = "../s2n-tls-sys", features = ["internal"] }
2323
pin-project-lite = "0.2"
2424
hex = "0.4"
2525

bindings/rust/s2n-tls/src/callbacks/async_cb.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use std::pin::Pin;
2626
/// if it wants to run an asynchronous operation (disk read, network call).
2727
/// The application can return an error ([Err(Error::application())])
2828
/// to indicate connection failure.
29-
pub trait ConnectionFuture: 'static + Send {
29+
pub trait ConnectionFuture: 'static + Send + Sync {
3030
fn poll(
3131
self: Pin<&mut Self>,
3232
connection: &mut Connection,

bindings/rust/s2n-tls/src/callbacks/client_hello.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<F: 'static + Send + Future<Output = Result<Config, Error>>> ConfigResolver<
4848
}
4949
}
5050

51-
impl<F: 'static + Send + Future<Output = Result<Config, Error>>> ConnectionFuture
51+
impl<F: 'static + Send + Sync + Future<Output = Result<Config, Error>>> ConnectionFuture
5252
for ConfigResolver<F>
5353
{
5454
fn poll(

bindings/rust/s2n-tls/src/connection.rs

+22
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@ impl fmt::Debug for Connection {
6464
/// s2n_connection objects can be sent across threads
6565
unsafe impl Send for Connection {}
6666

67+
/// # Sync
68+
///
69+
/// Although NonNull isn't Sync and allows access to mutable pointers even from
70+
/// immutable references, the Connection interface enforces that all mutating
71+
/// methods correctly require &mut self.
72+
///
73+
/// Developers and reviewers MUST ensure that new methods correctly use
74+
/// either &self or &mut self depending on their behavior. No mechanism enforces this.
75+
///
76+
/// Note: Although non-mutating methods like getters should be thread-safe by definition,
77+
/// technically the only thread safety guarantee provided by the underlying C library
78+
/// is that s2n_send and s2n_recv can be called concurrently.
79+
///
80+
unsafe impl Sync for Connection {}
81+
6782
impl Connection {
6883
pub fn new(mode: Mode) -> Self {
6984
crate::init::init();
@@ -1017,4 +1032,11 @@ mod tests {
10171032
fn assert_send<T: 'static + Send>() {}
10181033
assert_send::<Context>();
10191034
}
1035+
1036+
// ensure the connection context is sync
1037+
#[test]
1038+
fn context_sync_test() {
1039+
fn assert_sync<T: 'static + Sync>() {}
1040+
assert_sync::<Context>();
1041+
}
10201042
}

0 commit comments

Comments
 (0)