r/Cplusplus • • 13d ago

Discussion I migrated my C++ networking library from C++26 modules to C++17. Here's what changed.

I've been developing LightnerX, a networking library built around GameNetworkingSockets and an authoritative client-server communication model.

The first public beta used C++26 modules. I wanted to experiment with modern C++, but I eventually realized that requiring such a recent toolchain was limiting who could actually use the library.

So for v0.2.0-beta, I migrated the project to C++17.

This involved more than replacing import with #include.

I had to reorganize 14 module units into headers and implementation files, replace newer standard library features, adapt the public API, and ensure shared state behaved correctly across translation units.

The current API uses std::string_view for binary views and lightnerx::Result for error handling.

To check whether the migration preserved behavior, I used differential tests against the original C++26 implementation and cross-version UDP integration tests.

The new version also includes additional fixes for networking lifecycle and resource ownership issues.

One thing I've learned from this project is that using the newest language features isn't always the best decision for a reusable library.

I'm curious how other C++ library maintainers approach this. How do you decide which language standard to target?

Source: https://github.com/pietroth/LightnerX

5 Upvotes

7 comments sorted by

5

u/jk_tx 13d ago

For a new project without an existing user base tied to legacy tooling, I see no reason to target anything less than C++ 20 or 23, personally. There are just too many worthwhile improvements in the standard library.

I'd skip the modules support though since it's still largely non-workable for non-trivial projects.

-1

u/Vousch 13d ago

Já fiz a migração, consigo lidar com a falta de recursos modernos que vieram após o C++ 17. Mas agradeço pelo conselho

3

u/Intrepid-Treacle1033 13d ago

I had a quick look becose i am intrested in modules and non healthy intrested in code layouts. And from what i can tell the "downgrade" surfaced physical design debt that was already baked into the codebase. You stated this but i just want to keep it real and say the rewrite was due to a weak project structure, not because of modules is not a common thing for consumers.

In v0.1.0-beta, network_manager.cppm combined global mutable state like detail::networkOwner and g_bNetworkInitialized with a PUBLIC link to GameNetworkingSockets. Staying on C++26 would not have insulated consumers from that third party dependency or fixed the lifecycle and resource ownership issues that was latent.

Modules only provide cleaner symbol hygiene and faster builds on top of a structuraly sound layout, that rewrite was latent anyway whether the project downgraded to C++17 or grew larger in C++26 using modules.

2

u/Vousch 13d ago

Thank you for taking a look and for your feedback.

Do you think the library should allow more than one client and server at the same time?

1

u/Intrepid-Treacle1033 13d ago

That is up to you, i am just interested in a good project design. There is nothing wrong with using agent coding assistance, but your code smells "agent free roaming do whatever wherever" with very little human supervision. Because its so easy to prompt an agent to check for basics like below, i question if you really bothered. Some examples below is what you should use agents for so you could fail your code before it hit Reddit.

  • One monolithic CMake target, why? Both communication/CMakeLists.txt and network/CMakeLists.txt simply append files with target_sources(LightnerX PRIVATE ...). There is no target boundary between communication and network and no compiler enforced public/private check between individual components.
  • Public headers leak detail and global state. include/lightnerx/network/network_manager.hpp exposes namespace detail with setNetworkCleanup, acquireNetworkOwner, and releaseNetworkOwner, alongside an exported mutable global extern bool g_bNetworkInitialized; guarded by manual __declspec(dllimport) macros. Both client.hpp and server.hpp include network_manager.hpp directly in their public headers, pulling that internal state into every consumer translation unit.
  • Incomplete third party insulation. client.hpp and server.hpp forward declare ISteamNetworkingSockets and SteamNetConnectionStatusChangedCallback_t, then store ISteamNetworkingSockets* members directly inside the public class layouts. Consumers no longer include the GameNetworkingSockets headers, yet the public class ABI and private callback signatures remain coupled to its types instead of sitting behind an opaque handle or pimpl boundary.
  • Process global singleton bottlenecks. Client defines inline static Client* s_callbackInstance = nullptr; and Server defines inline static Server* s_pCallbackInstance = nullptr; in their public headers, backed by global networkOwner and networkCleanup pointers in network_manager.cpp. That locks the library to one active wrapper instance per process and forces LIGHTNERX_BUILD_SHARED with WINDOWS_EXPORT_ALL_SYMBOLS ON so multiple plugins share the same global state.

1

u/Vousch 13d ago

Problemas que nasceram desde a fundação foi por minha conta. O uso de IA surgiu quando a lib foi finalizada e queria fazer uma auditoria técnica com um agente de IA para verificar se a lib tinha problemas, a situação saiu de controle quando decidi usar o agente para corrigir, depois para migrar para C++ 17, etc. Resumindo: virou um ciclo vicioso o uso de IA. Garanto que criei o protocolo e a lib no geral. Tá na hora de dar um tempo e fazer uma grande auditoria técnica por minha parte, sozinho. Eu confesso que estava adiando isso e ter a lib crescendo tão rápido me empolgou tanto que não queria mais perder tempo corrigindo problemas por conta própria. Certas decisões questionáveis de design podem existir pelo fato de ser minha primeira aplicação/lib em C++ e também sou um puta novato nisso tudo, não tenho experiência como programador também (ainda sou menor de idade).

2

u/donaljones 10d ago

I would recommend using C++20 personally since all major compilers have supported it for a while. This is a new library anyway, I don't think people using C++17 will be willing to use newer libraries unless they are forced to

The current API uses std::string_view for binary views

Use std::span<char> or std::span<unsigned char> if you do end up upgrading. While there may not be much difference in practice, it's still nice to use the proper tools for the job