A modern, modular C++20 framework for high-level, type-safe, and efficient I/O: files, TCP/UDP networking, and data serialization. Designed for clarity, extensibility, and leveraging C++20 modules and concepts.
- C++20: Concepts, modules, coroutines, and modern STL.
- CMake: Build system with module support.
- Cross-platform: Linux, Windows, macOS (POSIX and Winsock support).
- No external dependencies: Only standard C++ and system libraries.
- Modules: Each major component (file I/O, TCP, UDP, adapters, data streams) is a C++20 module.
- Adapters: Uniform interfaces for files, TCP, UDP, and custom transports.
- Streams: InputStream/OutputStream concepts for generic, composable I/O.
- Data Streams: Type-safe serialization/deserialization for primitives and strings.
- Buffering: Optional buffered wrappers for performance.
- InputStream/OutputStream: Abstract read/write interfaces.
- Transportable: Network transports (TCP/UDP) with open/close/read/write.
- Adapters: Bridge between transports and stream concepts.
- SharedStream: Shared ownership and method forwarding for streams.
- Executors: Pluggable concurrency for servers.
- C++20 compiler (Clang, GCC, MSVC) with modules support.
- CMake 3.28+.
git clone https://github.com/your-org/modern_io.git
cd modern_io
cmake -B build
cmake --build buildmodern_io/
├── modern_io.ixx # Main module
├── modern_io_concepts.ixx # Stream concepts
├── modern_io_file.ixx # File streams
├── modern_io_data.ixx # Data (de)serialization
├── modern_io_buffered.ixx # Buffered streams
├── net_io.ixx # Network umbrella module
├── net_io_base.ixx # Base concepts/types
├── tcp_endpoint.ixx # TCP endpoint abstraction
├── tcp_client.ixx # TCP client
├── tcp_server.ixx # TCP server
├── udp_endpoint.ixx # UDP endpoint abstraction
├── udp_transport.ixx # UDP transport
├── net_io_adapters.ixx # Adapters and shared streams
├── main.cpp # Example usage
└── CMakeLists.txt
import modern_io;
using namespace modern_io;
// Write to file
FileOutputStream out("hello.bin");
out.write("Hello", 5);
out.flush();
// Read from file
FileInputStream in("hello.bin");
char buf[5];
in.read(buf, 5);import modern_io;
using namespace modern_io;
FileOutputStream fs("data.bin");
DataOutputStream<FileOutputStream> dout(std::move(fs), std::endian::big);
dout.write_int32(42);
dout.write_string("Hello World");
dout.flush();
FileInputStream fi("data.bin");
DataInputStream<FileInputStream> din(std::move(fi), std::endian::big);
int value = din.read_int32();
std::string msg = din.read_string();import modern_io;
import net_io;
import net_io_adapters;
using namespace net_io;
using namespace net_io_adapters;
// Client: Template-Parameter werden automatisch deduziert!
auto stream = make_stream(TcpEndpoint("127.0.0.1", 9000));
DataOutputStream out(stream, std::endian::big);
out.write_string("Hello TCP");
out.flush();import modern_io;
import net_io;
import net_io_adapters;
using namespace net_io;
using namespace net_io_adapters;
// Client: Template-Parameter werden automatisch deduziert!
auto stream = make_stream(UdpEndpoint("127.0.0.1", 9001));
DataOutputStream out(stream, std::endian::big);
out.write_string("Hello UDP");
out.flush();import modern_io;
import net_io;
import net_io_adapters;
using namespace net_io;
using namespace net_io_adapters;
constexpr uint16_t PORT = 9050;
constexpr std::string address = "127.0.0.1";
void tcp_server()
{
std::atomic<bool> running{true};
ThreadExecutor exec;
auto handler = [](auto&& shared_stream) {
DataInputStream<decltype(shared_stream)> in(std::move(shared_stream), std::endian::big);
DataOutputStream<decltype(shared_stream)> out(std::move(shared_stream), std::endian::big);
std::string msg = in.read_string();
std::osyncstream(std::cout) << "[TCP-Server] Received: " << msg << std::endl;
out.write_string("Echo: " + msg);
out.flush();
};
run_tcp_server(
exec,
std::move(handler),
running,
TcpEndpoint{address, PORT}
);
std::this_thread::sleep_for(std::chrono::milliseconds(500));
running = false;
}ThreadExecutor exec;
std::atomic<bool> running{true};
run_server(
exec,
[](auto&& stream) {
DataInputStream in(stream, std::endian::big);
DataOutputStream out(stream, std::endian::big);
std::string msg = in.read_string();
out.write_string("Echo: " + msg);
out.flush();
},
running,
TcpEndpoint{"127.0.0.1", 9050}
);- Unified I/O: Files, TCP, UDP with the same stream interface.
- Type-safe: Concepts and templates ensure correct usage.
- Composable: Streams, adapters, and buffers can be layered.
- Cross-platform: Works on Linux, Windows, macOS.
- Modern C++: Uses modules, concepts, and standard library only.
- Implement your own transport or stream by satisfying the InputStream/OutputStream concepts.
- Add new adapters for custom protocols.
- Use or implement custom executors for concurrency.
MIT License. See LICENSE.
MIT License (Klicken zum Anzeigen)
Copyright (c) 2024 Markus Hocke
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- Markus Hocke
- Contributors welcome!
For questions, bug reports, or contributions, please open an issue or pull request on GitHub.
- Markus Hocke
- Contributors welcome!
For questions, bug reports, or contributions, please open an issue or pull request on GitHub.