Skip to content

docs: io callback examples - #6036

Open
jmayclin wants to merge 2 commits into
aws:mainfrom
jmayclin:2026-08-13-io-callbacks
Open

docs: io callback examples#6036
jmayclin wants to merge 2 commits into
aws:mainfrom
jmayclin:2026-08-13-io-callbacks

Conversation

@jmayclin

@jmayclin jmayclin commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Goal

  • demonstrate a generic send/recv callback
  • show how to work with raw file descriptors
  • show how a TlsStream abstraction can help handle lifetime concerns

Why

This is all very tedious stuff. I have found these patterns to be really useful in my own work, so it makes sense to document them.

How

Examples!

Callouts

This code is deliberately verbose. In my opinion DRY is a very poor fit for examples.

Testing

The examples are really more reference code. So there are tests that confirm things are working.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions github-actions Bot added the s2n-core team label Aug 14, 2026
@jmayclin
jmayclin requested review from jouho and maddeleine August 14, 2026 02:27
@@ -0,0 +1,264 @@
//! This example shows how to setup the unsafe send + recv callbacks for s2n-tls.

@jouho jouho Aug 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these new files just need the copyright/licence headers. Otherwise looks good to me

/// use s2n_tls::connection::Connection;
/// use io_callbacks::generic_posix_send_cb;
///
/// let (client_stream, server_stream) = UnixStream::pair().unwrap();

@maddeleine maddeleine Aug 18, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this doc example if you have a test example further on. Just seems weird since the send callback has a doc example but the recv callback does not.

//! s2n-tls holds a raw pointer to the IO context for the life of the connection,
//! so the transport must have a stable address and must outlive the connection's
//! use of it. `TlsStream` enforces both by pinning the transport on the heap and
//! owning it alongside the connection.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the purpose of this example. You've already shown how a UnixStream can be used to send/read from a connection in your lib.rs test. What are you showing in this test file that is different?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A common problem that people run into is "how do I managed transport layer lifetimes". This TlsStream abstraction is how I'd recommend they deal with the disconnected lifetimes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it implements std::io::Read and std::io::Write, which I expect people will generally be more comfortable using instead of poll_send and poll_recv.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh the tls_stream is what you actually recommend people use, and the lib.rs functions are just the barebones impl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants