Repository navigation
Split mnet_app.c into focused translation units - #17
Merged
Merged
Conversation
mattsva
force-pushed
the
refactor/split-mnet-app
branch
4 times, most recently
from
October 11, 2026 13:50
c9ccabc to
6f439c0
Compare
mnet_app.c was 2335 lines mixing parsing, connection handling,
worker-pool code, the HTTP client, config and the built-in handlers.
Split it by responsibility:
mnet_log.c - logging (mnet_log_msg, mnet_app_log)
mnet_parse.c - request parsing (request line, headers, query,
cookies, body)
mnet_dispatch.c - route matching, response writing, dispatch
mnet_handlers.c - built-in handlers (welcome page, static files)
mnet_server.c - connection lifecycle, worker pool, mnet_run()
mnet_client.c - client-side HTTP (URL parsing, mnet_call)
mnet_app.c - application lifecycle, config, route registration
struct mnet_app, parsed_request_t, the shared limits and the platform
helpers (now_ms_mono, mnet_poll) moved into src/mnet_internal.h, which
the translation units already shared. The header now defines the
POSIX feature-test macros it needs (realpath/clock_gettime) itself, so
plain -std=c17 consumers no longer need _GNU_SOURCE to compile it.
Functions that cross module boundaries lost their static qualifier and
are declared in mnet_internal.h; everything else stays file-local.
test_welcome.c now includes the real struct instead of duplicating it
(a duplicate that had already diverged from the real layout).
CMake and Meson test targets gained include/mnet on their include path
so mnet_internal.h resolves there too; Make and CI already had it.
Verified: make test, ctest (Debug + Release), meson test (debug +
release), ASan/UBSan across all 11 binaries, TSan across the 6
threaded tests, Valgrind on 4 tests. Zero warnings everywhere.
mattsva
force-pushed
the
refactor/split-mnet-app
branch
from
October 11, 2026 14:01
6f439c0 to
edfa48d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No linked issue — structural change requested after the audit (audit issue 7: "check whether src/mnet_app.c mixes parsing, connection handling and worker-pool code").
src/mnet_app.cwas 2335 lines / 46 functions mixing request parsing, connection handling, worker-pool code, the HTTP client, config and the built-in handlers. Split by responsibility:mnet_log.cmnet_parse.cmnet_dispatch.cmnet_handlers.cmnet_server.cmnet_run()mnet_client.cmnet_call()mnet_app.cShared state (
struct mnet_app,parsed_request_t, the limits, the platform helpers) moved intosrc/mnet_internal.h, which the translation units already shared; cross-module functions lost theirstaticqualifier and are declared there, everything else stays file-local. Code was moved verbatim — a pre-split audit confirmed no line was dropped or claimed twice.Two incidental fixes surfaced:
mnet_internal.hnow defines the POSIX feature-test macros it needs itself (plain-std=c17consumers no longer need_GNU_SOURCEto compile it), and CMake/Meson test targets gainedinclude/mneton their include path.test_welcome.cnow includes the realstruct mnet_appinstead of a duplicate that had already diverged (it was missing theportfield).Public API unchanged (
include/mnet/untouched). Verified: make test, ctest Debug + Release, meson debug + release, ASan/UBSan across all 11 binaries, TSan across 6 threaded tests, Valgrind on 4. Windows/macOS not verified locally — see #1.Stacked on the previous PR in the series; merge in order.