Skip to content

PEP748 tlslib - context & socket#4960

Open
Julien00859 wants to merge 4 commits intopython:mainfrom
Julien00859:Julien00859/tlslib-context
Open

PEP748 tlslib - context & socket#4960
Julien00859 wants to merge 4 commits intopython:mainfrom
Julien00859:Julien00859/tlslib-context

Conversation

@Julien00859
Copy link
Copy Markdown

PEP 748: create_connection and create_server instead of connect

Prior discussions at:

That commit is the solution to my struggle binding an Ipv6 localhost address when I first tested tlslib. At the time the library was always binding the socket using family=AF_INET. The solution we implemented in tlslib is to perform a DNS request on the user-provided address to determine the family to use (family=AF_INET6 in my case).

I'm still unhappy with this API server-side. "connect" is the wrong verb, it should be "bind". It is not obvious if other sockets are supported (e.g. Unix Domain Socket).

create_connection and create_server make so much more sense to me, at least as long as we don't have a wrap_socket function.

PEP 748: shutdown(show: 0|1|2) instead of close(force: bool)

Prior discussions:

Work in progress in siotls:

The messages I wrote on the forum explain the problems I have with close(force: bool), which mainly boils down to "it feels too TLS 1.2-ish". I spent many days exploring ideas to have a clean API to terminate the TLS connection a way that is safe in both TLS 1.2 (synchronous termination) and TLS 1.3 (asynchronous and IMO better). Reusing socket's shutdown terminology feels right to me. It works well for TLS 1.3 and is fine for TLS 1.2.

There are other things in the current Buffer & Socket spec that I find are leaking openssl's API, and that I expect won't work very well with other TLS libraries (including my own) but I'm not ready at this time to make new proposals.

Ease reading the diff of the next commits.
The `connect()` function is poorly named server-side as it actually
`bind()` the socket. Server-side the function lacks a `family` parameter
to support IPv6 without a DNS lookup.

Actually all three `connect()`, `bind()` and `listen()` socket function
are pretty low-level. The high-level `create_connection` (for `connect`)
and `create_server` (for `bind()` + `listen()`) are more pythonic. Wrap
the latter and not the former, also to remove the need of a `listen()`
method on the created socket (which is useless client-side).
@Julien00859 Julien00859 requested a review from ncoghlan as a code owner May 6, 2026 23:02
@python-cla-bot
Copy link
Copy Markdown

python-cla-bot Bot commented May 6, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@read-the-docs-community
Copy link
Copy Markdown

Documentation build overview

📚 pep-previews | 🛠️ Build #32574488 | 📁 Comparing 3d40e2f against latest (c093d5f)

  🔍 Preview build  

709 files changed · ± 709 modified

± Modified

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant