Skip to content

Split mnet_app.c into focused translation units - #17

Merged
mattsva merged 1 commit into
mnet-web:mainfrom
mattsva:refactor/split-mnet-app
Oct 11, 2026
Merged

mattsva merged 1 commit into
mnet-web:mainfrom
mattsva:refactor/split-mnet-app

Conversation

@mattsva

@mattsva mattsva commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

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.c was 2335 lines / 46 functions mixing request parsing, connection handling, worker-pool code, the HTTP client, config and the built-in handlers. Split by responsibility:

File Lines Contents
mnet_log.c 72 logging
mnet_parse.c 547 request line, headers, query, cookies, body
mnet_dispatch.c 289 route matching, response writing, dispatch
mnet_handlers.c 225 welcome page, static files
mnet_server.c 455 connection lifecycle, worker pool, mnet_run()
mnet_client.c 376 client-side HTTP, mnet_call()
mnet_app.c 311 lifecycle, config, route registration

Shared state (struct mnet_app, parsed_request_t, the limits, the platform helpers) moved into src/mnet_internal.h, which the translation units already shared; cross-module functions lost their static qualifier 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.h now defines the POSIX feature-test macros it needs itself (plain -std=c17 consumers no longer need _GNU_SOURCE to compile it), and CMake/Meson test targets gained include/mnet on their include path. test_welcome.c now includes the real struct mnet_app instead of a duplicate that had already diverged (it was missing the port field).

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.

@mattsva
mattsva force-pushed the refactor/split-mnet-app branch 4 times, most recently from c9ccabc to 6f439c0 Compare October 11, 2026 13:50
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
mattsva force-pushed the refactor/split-mnet-app branch from 6f439c0 to edfa48d Compare October 11, 2026 14:01
@mattsva
mattsva merged commit 638cfdd into mnet-web:main Oct 11, 2026
8 checks passed
This was referenced Oct 11, 2026
@mattsva
mattsva deleted the refactor/split-mnet-app branch October 11, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant