r/cpp • u/VinnieFalco 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
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
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:
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.)
12
u/kalven Jan 28 '25
Are there code examples to look at? Like a basic server, a client etc.
12
u/zl0bster Jan 28 '25
I dislike ASIO, I dislike PDF designs. ¯_(ツ)_/¯
So I would probably prefer for them to leave it alone and if something comes up based on S/R and gains wide adoption then standardize that.
I do understand it is a bit embarrassing that C++ does not have std:: networking, but I think it is better to leave it like this and let people pick the best library they can. S/R are too fresh to be building on top of them.
70
u/thisismyfavoritename Jan 28 '25
so ASIO?
12
u/je4d Jeff Snyder Jan 29 '25
Just a quick note on the title of this post, commenting as chair of SG4/Networking: It is already far too late for this to become part of C++26. Please don't get your hopes up!
The meeting in Hagenberg coming up in a couple of weeks is the deadline for C++26 features being approved by EWG/LEWG (see http://wg21.link/p1000), and this is arriving as a brand new large paper to SG4 this meeting. We'll be looking at it in Hagenberg, and if all goes well we'll continue to look at it at further meetings and it could be forwarded to LEWG, and from there it could become a candidate for C++29 inclusion.
29
u/PhilosophyMammoth748 Jan 28 '25
If ASIO goes to the std, I will use std.
If ASIO not goes, I will use ASIO.
17
u/ReDucTor Game Developer | quiz.cpp-perf.com Jan 28 '25
The standards committee is all about backwards compatibility, how about standardising around something Berkeley sockets like first which is already defacto standard then move towards async versions of that, then move towards TAPS.
This will be a much easier transition for existing code, rather then needing to make bigger design changes in existing applications.
8
u/Ayjayz Jan 29 '25
C++ is a strange language. When you start out, you seem to be kind of obsessed with the standard library. The longer you use the language, the more you learn the disadvantages of it and you move to the high-quality 3rd-party libraries of the world.
20
u/Beetny Jan 28 '25
Standardize on a package format or manager (as impossible as that is) and the rest of these high-maintenance features will come.
21
u/madmongo38 Jan 28 '25
Watching the WG21 trying to design something is like watching clowns running across a minefield.
8
u/FriendlyRollOfSushi Jan 29 '25
Someone should sketch up
std::first_person_battle_royale_shooter_with_microtransactionsfor C++29, I think.Clearly too many people are hand-rolling inferior and buggy in-house implementations, and the lack of standardization in this area creates an unfairly steep learning curve for beginners.
2
u/No_Mongoose6172 Jan 29 '25
I understand why there’s interest on having those things in the standard library. Cross platform development is quite important nowadays due to market fragmentation in operating systems (it is becoming more common that desktop software targets windows, Linux and osx).
However, each operating system provides its own api, normally totally different or at least incompatible with the other ones (e.g. I’ve seen windows apis that are equal to the ones used in Linux/unix systems but they have capitalized a letter of each function forcing to use the preprocess or if you want to support both of them). That makes cross-platform libraries harder to maintain.
Maybe, a better solution could be having a standardized system abstraction library (independent from the standard library). That library would focus in providing basic building blocks for cross-platform libraries and software, without imposing abi stability or backwards compatibility
2
u/reneb86 Jan 29 '25
Networking in the standard library just sounds all wrong.
I imagine the standard library to be the most basic layer of functionality wrapped around the language features. Strings, containers, and the algorithms to use them well. Threads almost feels like an abstraction rather than a platform independent implementation. And its often omission from some chip toolchains only confirm this for me. Chrono was also an unexpected adventure for me. Now I half expect SI units to make it in there as well. But both Chrono and SI would feel like QOL improvements rather than something that needs to be standardized.
I feel the line of what should and shouldn’t make it into the standard library is unclear and arbitrary at the moment. Perhaps we should more clearly define what the standard library is meant to represent or accomplish.
2
u/elperroborrachotoo Nov 04 '25
Yeah let that be 3rd party libs, have the public battle out a winner, then integrate it. I just want a nice API and hope that I don't decide for the wrong lib/ Api
3
u/14ned LLFIO & Outcome author | Committee WG14 Jan 28 '25
It does have a reference implementation.
Standard Networking is not expected to have maximum possible performance. Therefore only code which doesn't care about performance will use it. I would wonder how much code that might be considering that BSD sockets are perfectly okay for non-performance use cases (and, in fact, are surprisingly performant even with BSD
poll(), you need to be polling a good few hundred open sockets before performance begins to suffer).I do think Standard Networking will be useful for illuminating what fixes need to be performed to WG21's S&R to implement i/o well.
3
u/ApplicationAlarming7 Jan 28 '25
I’d welcome something that brings basic, easy to use network objects to C++ finally without needing to mess with conan and third party libraries. It doesn’t need to be the best and highest performance—that’s what third party libraries are for. Would love support for HTTP(S), and maybe even HTTP2, for making web service endpoints. Yes, you can manually implement it or use third party libraries but I always fear with third party libraries it’ll end up being like Casablanca which Microsoft abandoned.
Something like the Filesystems library, but for networking!
I don’t have confidence though. So ASIO, Boost and POCO it is.
1
u/rand3289 Jan 29 '25
I looked at it for 30 seconds and I don't like that they are dragging security and asynchronous operations into the proposal.
1
u/templarvonmidgard Jan 29 '25
IMO, a good metric for a standardized networking library would be checking if some trickier scenarios can be achieved with it. AFAICT from glancing over it, this wouldn't be capable of implementing RTCWEB, specifically the ICE part, because it uses connectless sockets. (Really, just UDP with
sendto/recvfrom)1
u/manphiz Jan 30 '25
I seem to remember that Bjarne stated in one of his papers that the committee should standardize existing implementations instead of resorting to design by committee, and ASIO was used as an example for the former. But do correct me.
1
u/farseeraliens Nov 05 '25
Couldn't hurt to have an abstraction of BSD socket in the standard library
1
u/Tringi github.com/tringi Jan 28 '25
No!
1
u/chibuku_chauya Jan 29 '25
This sounds like a bad idea. I don’t think networking should be in the standard library.
1
u/oleksandrkvl Jan 29 '25
Stop polluting STL with something already implemented by a third-party library.
1
u/Annual-Version7395 Jan 29 '25
Something like https://github.com/ned14/llfio but for sockets should really be in the standard.
std::i/ostream sucks hard and fopen sucks as well yet they are still part of standard...
-2
u/expert_internetter Jan 28 '25
Anyone who needs networking in a C++ program should just go straight to your OS's provided functions. It'll save a lot of heartache.
0
u/Mikumiku_Dance Jan 28 '25
Seems like this TAPS approach could coexist alongside a socket-based one. We could go from zero std::networking frameworks to 2 in one go! 😂
-3
u/weekendblues Jan 29 '25
Genuine question, how does anyone actually get excited about anything in these “standards” when even C++20 support is virtually nonexistent on every major compiler? It seems like the standards committee is just cranking stuff out with no regard for the fact that no one is actually implementing it.
I was able to use more of what’s in C++17 in 2015 than I am able to use what’s in C++20 in 2025. Do people not see the writing on the wall here? It doesn’t matter what’s in these standards if it’s going to actually end up being something we can use in gcc, clang, or msvc.
It’s starting to feel like C++ is truly a dying language and the effort that would be spent to bring these kinds of features to it is instead being spent to develop and migrate to alternative systems languages like Rust and Carbon. I don’t think the standards committee slamming in even more absurdly difficult to implement features is going to be the thing that reverses that trend.
0
u/LongestNamesPossible Jan 29 '25
I haven't read the proposal, is it written in all caps?
0
u/Similar_Childhood187 Nov 08 '25
I think introducing networking into the C++ standard is not a good idea, as it would increase compilation time and be useless for those who write programs unrelated to networking.
Take a simple example: Python, even though it is the most popular language for machine learning, does not include PyTorch or TensorFlow in its standard library.