msocket¶
msocket is a platform-independent, event-driven socket library written in C (C99 and later). It abstracts the details of setting up socket structures directly using the WinSock2 or BSD socket APIs into a clean, callback-driven interface.
It allows applications to register callbacks when lifecycle events occur on a socket (such as connection established, disconnected, or new data received). The msocket library manages the low-level details of the OS-level socket objects and background worker threads, functioning identically across Linux and Windows:
TCP Client and Server: Stream communication supporting IPv4 and IPv6.
UDP Client and Server: Datagram communication with support for unicast and multicast.
UNIX Domain Sockets: High-performance local inter-process communication on Linux and POSIX platforms.
Event-Driven Asynchronous I/O: Integrated worker threads monitor socket activity and dispatch connect, disconnect, and data callbacks.
In-Memory Testing Framework: Built-in mock socket implementation (
testsocketandtestsocket_spy) enabling unit testing of network protocols and message parsing without OS network sockets.C++ RAII Wrapper: Type-safe RAII classes and listener interfaces for modern C++.
Cross-Platform: Native Linux (POSIX) and native Windows (WinSock2) support with clean C99 public headers.
Components Catalog¶
Below is a summary of all modules provided by the msocket library:
Module |
Header |
Description |
|---|---|---|
|
Client/peer event-driven socket handling TCP, UDP, and UNIX domains |
|
|
Server connection listener and client socket lifecycle manager |
|
|
Unified event callback table ( |
|
|
Standardized error codes and error string translation |
|
|
In-memory mock socket engine for protocol testing without network access |
|
|
Mock socket spy for recording sent data and verifying interactions in unit tests |
|
|
Modern C++ RAII socket and server wrappers and listener interfaces |