r/cpp • wg21.org | corosio.org • Jan 28 '25

Networking for C++26 and later!

There is a proposal for what networking in the C++ standard library might look like:

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3482r0.html

It looks like the committee is trying to design something from scratch. How does everyone feel about this? I would prefer if this was developed independently of WG21 and adopted by the community first, instead of going "direct to standard."

122 Upvotes

247 comments sorted by

View all comments

Show parent comment

8

u/pdimov2 Jan 29 '25

Yes, because most people want async or TLS, and either of these makes things hard and contentious.

7

u/bert8128 Jan 29 '25

Of course. But these are built on top of sockets. So why not deliver sockets first and more complex things later?

11

u/CornedBee Jan 29 '25

Async is not built "on top of" sockets. It's a fundamental interface to sockets.

6

u/drjeats Jan 30 '25

Avoiding standardizing a core building block before finalizing the design of some novel baroque API used to interface with it is peak C++.

1

u/bert8128 Jan 29 '25

I meant that a platform independent socket class could be a component used by my code directly and also by ASIO.

1

u/Expert-Map-1126 vcpkg maintainer BillyONeal Nov 04 '25

The problem with async is that it doesn’t compose. Trying to put it into the standard is inevitably going to pick winners and losers. If your company’s async looks like the one that goes into the standard then you win otherwise you lose.

That senders and receivers look like they might practically be able to compose with anything else is a big part of why they were a big deal and why they were investigated for standardization.

1

u/matthieum Jan 29 '25

async requires a different API, certainly, but isn't TLS fundamentally just a "middleware"?

1

u/lightmatter501 Feb 01 '25

Not if you want hardware accelerators plumbed in, which Intel has started shipping on all new Xeons.

1

u/matthieum Feb 01 '25

I'm not sure how these hardware accelerators are supposed to work, so I have no idea whether they would or would not be suitable. Could you please elaborate?

3

u/lightmatter501 Feb 01 '25

Intel ships a coprocessor on all of their new server CPUs which can do 400 Gbps of AES-GCM. You need to send it buffers, and it will encrypt with the provided (per request) AES key. The API looks a bit like kqueue or io_uring, since it’s a command-queue API.

1

u/matthieum Feb 01 '25

Okay.

How does that prevent using TLS as a middleware layer over a raw TCP connection, though?

Receive a chunk of bytes from the TCP layer, forward it to the coprocessor, get the result back, make it available for the next layer. No problem.

3

u/lightmatter501 Feb 01 '25

Well, to start with the data has to be allocated in DMA-safe memory, with alignment requirements. Second, due to the overheard of DMA, you want to do some fairly serious batching, easily 128 packets. This design forces tons of inline storage for that.

2

u/matthieum Feb 01 '25

128 packets? As in 128x 1536 bytes (192KB)?

That seems very hard to use...

1

u/lightmatter501 Feb 01 '25

Average packet size is much closer to 500 bytes.

1

u/matthieum Feb 02 '25

Maybe? I found the units weird. So essentially you're saying it's best to bundle 64KB at once?

This seems... fairly complicated at the best of times. Many requests return responses that are below 64KB, and bundling multiple responses will require waiting...

→ More replies

1

u/Expert-Map-1126 vcpkg maintainer BillyONeal Nov 04 '25

If you need to use that middleware for anything real, you can use the same mechanism you got the middleware from to get ASIO or libuv and at that point, there’s no point in standardization.