diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-05-15 15:55:12 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-05-15 15:55:12 -0600 |
commit | 18ddce6270391e5c1924394f8b5d8079ad73289e (patch) | |
tree | 6b647d225665cd4fb2733a57bdfa5f0e96692995 /lib9p/tests/test_server/main.c | |
parent | 811d9700e1414dae3357361b3ca565f673f63b08 (diff) | |
parent | e38a2d29292ad3fad64729ef958ff07e3bca02cf (diff) |
Merge branch 'lukeshu/simple-call-graph'
Diffstat (limited to 'lib9p/tests/test_server/main.c')
-rw-r--r-- | lib9p/tests/test_server/main.c | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/lib9p/tests/test_server/main.c b/lib9p/tests/test_server/main.c index d7819eb..4caff16 100644 --- a/lib9p/tests/test_server/main.c +++ b/lib9p/tests/test_server/main.c @@ -38,9 +38,9 @@ static lo_interface lib9p_srv_file get_root(struct lib9p_srv_ctx *, struct lib9p_s); -const char *hexdig = "0123456789abcdef"; +static const char *hexdig = "0123456789abcdef"; -struct { +static struct { uint16_t port; struct hostnet_tcp_listener listeners[_CONFIG_9P_MAX_CONNS]; struct lib9p_srv srv; @@ -67,7 +67,7 @@ struct { __VA_OPT__(,) __VA_ARGS__ \ })) -struct lib9p_srv_file root = +static struct lib9p_srv_file root = STATIC_DIR(1, "", STATIC_DIR(2, "Documentation", STATIC_FILE(3, "x", Documentation_x_txt), @@ -128,22 +128,26 @@ static COROUTINE init_cr(void *) { cr_exit(); } -static void log_fct(char character, void *_stream) { - FILE *stream = _stream; - putc(character, stream); - putchar(character); +struct tstlog_stdout {}; +LO_IMPLEMENTATION_H(fmt_dest, struct tstlog_stdout, tstlog_stdout); +LO_IMPLEMENTATION_C(fmt_dest, struct tstlog_stdout, tstlog_stdout, static); + +static size_t tstlog_bytes = 0; + +static void tstlog_stdout_putb(struct tstlog_stdout *, uint8_t b) { + putc(b, globals.logstream); + putchar(b); + tstlog_bytes++; } -static void log_msg(struct lib9p_srv_ctx *ctx, enum lib9p_msg_type typ, void *hostmsg) { - /* It sucks that %v trips -Wformat and -Wformat-extra-args - * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47781 */ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wformat" -#pragma GCC diagnostic ignored "-Wformat-extra-args" - fmt_fctprintf(log_fct, globals.logstream, - "%c %v\n", typ % 2 ? '<' : '>', - lo_box_lib9p_msg_as_fmt_formatter(&ctx->basectx, typ, hostmsg)); -#pragma GCC diagnostic pop +static size_t tstlog_stdout_tell(struct tstlog_stdout *) { + return tstlog_bytes; +} + +static lo_interface fmt_dest tstlog_dest = { .vtable = &_lo_tstlog_stdout_fmt_dest_vtable }; + +static void tstlog_msg(struct lib9p_srv_ctx *ctx, enum lib9p_msg_type typ, void *hostmsg) { + fmt_print(tstlog_dest, typ % 2 ? "< " : "> ", (lib9p_msg, &ctx->basectx, typ, hostmsg), "\n"); fflush(globals.logstream); } @@ -155,7 +159,7 @@ int main(int argc, char *argv[]) { globals.logstream = fopen(argv[2], "w"); if (!globals.logstream) error(2, errno, "fopen"); - globals.srv.msglog = log_msg; + globals.srv.msglog = tstlog_msg; struct hostclock clock_monotonic = { .clock_id = CLOCK_MONOTONIC, |