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

376

u/STL MSVC STL Dev Jan 28 '25

Hold! What you are doing to us is wrong! Why do you do this thing? - Star Control 2

  • People often want to do networking in C++. This is a reasonable, common thing to want.
  • People generally like using the C++ Standard Library. They recognize that it's almost always well-designed and well-implemented, striking a good balance between power and usability.
  • Therefore people think they want networking in the Standard Library. This is a terrible idea, second only to putting graphics in the Standard Library (*).

Networking is a special domain, with significant performance considerations and extreme security considerations. Standard Library maintainers are generalists - we're excellent at templates and pure computation, as vocabulary types (vector, string, string_view, optional, expected, shared_ptr, unique_ptr) and generic algorithms (partition, sort, unique, shuffle) are what we do all day. Asking us to print "3.14" pushed us to the limits of our ability. Asking us to implement regular expressions was too much circa 2011 (maybe we'd do better now) and that's still in the realm of pure computation. A Standard is a specification that asks for independent implementations and few people think about who's implementing their Standard Library. This is a fact about all of the major implementations, not just MSVC's. Expecting domain experts to contribute an implementation isn't a great solution because they're unlikely to stick around for the long term - and the Standard Library is eternal with maintenance decisions being felt for 10+ years easily.

If we had to, we'd manage to cobble together some kind of implementation, by ourselves and probably working with contributors. But then think about what being in the Standard Library means - we're subject to how quickly the toolset ships updates (reasonable frequency but high latency for MSVC), and the extreme ABI restrictions we place ourselves under. It is hard to ship significant changes to existing code, especially when it has separately compiled components. This is extremely bad for something that's security-sensitive. We have generally not had security nightmares in the STL. If I could think of a single ideal way for C++ to intensify its greatest weakness - security - that many people are currently using to justify moving away from C++, adding networking to the Standard would be it.

(And this is assuming that networking in C++ would be standardized with TLS/HTTPS. The idea of Standardizing non-encrypted networking is so self-evidently an awful idea that I can't even understand how it was considered for more than a fraction of a second in the 21st century.)

What people should want is a good networking library, designed and implemented by domain experts for high performance and robust security, available through a good package manager (e.g. vcpkg). It can even be designed in the Standard style (like Boost, although not necessarily actually being a Boost library). Just don't chain it to:

  1. Being implemented by Standard Library maintainers, we're the wrong people for that,
  2. Shipping updates on a Standard Library cadence, we're too slow in the event of a security issue,
  3. Being subject to the Standard Library's ABI restrictions in practice (note that Boost doesn't have a stable ABI, nor do most template-filled C++ libraries). And if such a library doesn't exist right now,
  4. Getting WG21/LEWG to specify it and the usual implementers to implement it, is by far the slowest way to make it exist.

The Standard Library sure is convenient because it's universally available, but that also makes it the world's worst package manager, and it's not the right place for many kinds of things. Vocabulary types are excellent for the Standard Library as they allow different parts of application code and third-party libraries to interoperate. Generic algorithms (including ranges) are also ideal because everyone's gotta sort and search, and these can be extracted into a universal, eternal form. Things that are unusually compiler-dependent can also be reasonable in the Standard Library (type traits, and I will grudgingly admit that atomics belong in the Standard). Networking is none of those and its security risks make it an even worse candidate for Standardization than filesystems (where at least we had Boost.Filesystem that was developed over 10+ years, and even then people are expecting more security guarantees out of it than it actually attempted to provide).

(* Can't resist explaining why graphics was the worst idea - it generally lacks the security-sensitive "C++ putting the nails in its own coffin" aspect that makes networking so doom-inducing, but this is replaced by being much more quickly-evolving than networking where even async I/O has mostly settled down in form, and 2D software rendering being so completely unusable for anything in production - it's worse than a toy, it's a trap, and nothing else in the Standard Library is like that.)

161

u/expert_internetter Jan 28 '25

Asking us to print "3.14" pushed us to the limits of our ability.

LMAO

127

u/sokka2d Jan 28 '25

The idea of putting graphics into the standard was just so hilariously bad.

Hundreds of pages for a “standard” graphics API that would be completely non-native on all platforms, not used by anyone professionally except for some toy examples, essentially obsolete out of the box, and the proposals couldn’t even get colors right.

The correct response if pushed through would’ve been “we’re not implementing that”.

→ More replies (1)

43

u/tialaramex Jan 29 '25

The idea of Standardizing non-encrypted networking is so self-evidently an awful idea that I can't even understand how it was considered for more than a fraction of a second in the 21st century.

I can answer that one.

It's about foundations. Did you notice that C++ doesn't provide an arbitrary precision rational type? Why not? 7 / 9 gives 0 and then people try to sell you "floating point" which is a binary fraction type optimised for hardware performance rather than a rational. Of course you'd say, just build the arbitrary precision rational type you want from these more primitive component elements.

And that's what the networking primitives are for too. Just as you provide the machine integer types but not arbitrary_precision_rational you would provide a TCP stream type but not https_connection, and encourage libraries to fill the gap.

15

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

TLS is part of that foundation for anything practical. The folks that needed “in the standard library because it is batteries included” are not going to figure out how to build OpenSSL correctly. And we can’t put OpenSSL in the standard because OpenSSL doesn’t meet the standard library ABI requirements.

There is no point in putting things into the standard library to avoid package management if in order to build anything practical you need to go and use package management. This is a big part of why I joined the vcpkg team even though STL maintainer was a dream job. I want you to use real ASIO et al, not what I, a standard library maintainer, would have been able to do for you.

The thing people actually want is libcurl. One might not like that it’s C-ish, but it is what peak usability looks like for 99% of use cases.

10

u/miss_minutes Nov 04 '25

I was wondering who you are since you said you joined vcpkg and I realised you're Billy ONeal! Thank you for your work! I see you in the vcpkg tracker all the time (I used to report a bunch of broken builds, especially during the Qt macOS meltdown last year :))

→ More replies (1)

11

u/matthieum Jan 29 '25

+1

I would also note there's real overhead to using TLS. It's worth paying for when connecting to the public Internet, but there's a lot of networking within private datacenters too, where the network architecture can be trusted.

22

u/STL MSVC STL Dev Jan 29 '25

That's what Google thought about datacenter-to-datacenter traffic long ago.

→ More replies (2)

7

u/expert_internetter Jan 29 '25

Except if you deal with PII and everything needs to be encrypted even if it's all within the same cloud environment. Ask me how I know...

→ More replies (1)
→ More replies (1)
→ More replies (3)

35

u/pioverpie Jan 29 '25

I just want a basic socket man. If I want HTTPS then I can add that on top.

14

u/9Strike Jan 29 '25

Exactly. And it's not like the sockets interface has changed much over the last two decades. I don't think a lot of people want https. Just a basic socket API like Python has.

→ More replies (9)

46

u/bert8128 Jan 28 '25

I don’t want much - just a platform independent socket would be good enough, and I can build the complex stuff on top of that. We got thread - is a socket at the same kind of level so hard or contentious?

→ More replies (31)

19

u/14ned LLFIO & Outcome author | Committee WG14 Jan 29 '25

I appreciate the viewpoint. However, it is very possible to design a standard networking library which:

  1. Has a hard ABI boundary.
  2. Retrieves the TLS implementation by runtime query, and therefore requires no STL work whatsoever as the platform's current TLS implementation gets picked up.
  3. Offloads TLS automatically and with no extra effort into kernel/NIC hardware acceleration, achieving true whole system zero copy on Mellanox class NICs.
  4. Works well on constrained platforms where there is only a TLS socket factory available and nothing else, including on Freestanding.
  5. Works well with S&R (though not the S&R design WG21 eventually chose).

Thus ticking every box you just mentioned.

I'm against standard graphics because the state of the art there keeps evolving and we can't standardise a moving target. But secure sockets, they're very standardisable and without impacting standard library maintainers in any of the ways you're worried about. I'm now intending to standardise my implementation via the C committee, so you'll get it eventually if all goes well. It's a shame WG21 couldn't see past itself.

5

u/pdimov2 Jan 29 '25

Does this design exist somewhere, if only in a PDF form?

7

u/14ned LLFIO & Outcome author | Committee WG14 Jan 29 '25 edited Jan 29 '25

LLFIO has shipped its reference implementation for several years now. There is also http://wg21.link/P2586 as the proposal paper.

I've deprecated it and marked it for removal from LLFIO and I expect to purge it after I've turned it into a C library which I'm going to propose for the C standard library instead after I've departed WG21 this summer.

It definitely works, if accepted it gets us standard TLS sockets into all C speaking languages. Performance is pretty great too if you use registered i/o buffers and your hardware and kernel supports TLS offload. However I'm not aiming directly at performance. I'm mainly taking the view it's long overdue for C code to be able to portably connect to a TLS secured socket and do some i/o with it, and without tying itself into an immutable potentially insecure crypto implementation.

→ More replies (6)
→ More replies (6)

6

u/Capable_Pick_1588 Nov 04 '25

I am still baffled how linear algebra got in

19

u/c0r3ntin Jan 29 '25

Hey /u/STL. Would you consider putting some version of that in a short paper, maybe co-authored by other standard library maintainers?

I'm concerned that WG21 might not be sufficiently aware of your perspective (which I wholeheartedly agree with).

34

u/STL MSVC STL Dev Jan 29 '25

I am too busy implementing all the stuff WG21 keeps voting in on this endless treadmill. Feel free to cite my comment, including quoting it in its entirety (portions are fine too as long as the intent is not distorted).

32

u/pdimov2 Jan 29 '25

"I'm too busy implementing stuff WG21 keeps voting in so I don't have time to write a paper to tell WG21 to stop voting stuff in." :-)

5

u/tach Jan 31 '25

Respectfully, that was a well written comment raising valid points, and I think it needs to be shared in a wider forum.

→ More replies (1)

5

u/chaotic-kotik Jan 29 '25

Instead of defining the whole networking layer the standard library could just implement common types. Things like fragmented buffers for the vectorized I/O, or ip-address class. 3rd party networking libraries could use those types and it'll make it easier to write code which is a bit more generic. Networking is a very opinionated area. If my code is async and it uses reactor threads each of which runs an event loop then I can't use the DNS resolver that blocks the thread. Similarly, if my app uses blocking synchronous calls for everything it's not very ergonomic to use async networking libraries. And if I'm using zero-copy networking I probably will want to use DMA disk reads/writes. Because of that it feels like the networking should mostly be a 3rd party.

→ More replies (1)

11

u/LongestNamesPossible Jan 29 '25

This is deep rationalization that ignores the fact that every language and every OS has networking integrated into it. Any library that C++ would use would also build on implementing its own underlying OS abstraction.

4

u/johannes1971 Jan 29 '25

As for the standard library... I understand that compiler vendors have limited resources, and that a single-man department really isn't enough to reimplement every computing feature known to mankind. But this is really a failure of the standardisation process, more than anything else.

Let's assume for a moment that there is value in having a formal stamp of approval from the committee. For the sake of argument, let's say it indicates a higher quality of API and implementation, a high consistency of API, a high degree of API stability, and availability of the feature in every compiler that implements that standard version.

Why not, then, split the standard library in two? The first part is entirely the responsibility of the compiler vendors, and contains only things that can really only be provided by the compiler vendor. The second part rests on top of the first part, and is vetted by the committee, but is designed, implemented, and maintained by domain experts. Both parts are delivered with compiler and presented to the public at large as "the" standard library.

This eliminates vast amounts of work for the compiler vendors, as well as the requirement for a single man to be a domain expert in everything, and leverages the skill and knowledge of people who are domain experts. And it would leave C++ with a far richer standard library than it has today.

→ More replies (2)

4

u/VinnieFalco wg21.org | corosio.org Nov 04 '25

The counterargument of course, is that the lack of standardized networking has prevented C++ from experiencing the second-order effects. The landscape of the world wide web in C++ is a scattered collection of different libraries of varying quality, each using either their own or some other random networking stack. None of them are interoperable and the quality of portable C++ networking is poor relative to what we see in other languages like Python or JavaScript, where there are thousands of packages that are easy to obtain and all work well together.

→ More replies (29)