From f78a30aaccffddc3e3eab07870e02157322af956 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Sun, 12 Apr 2026 13:29:59 -0400 Subject: Header shuffle, update deps Signed-off-by: Andrew Opalach --- include/nnwt/buffer.h | 3 +++ include/nnwt/common.h | 3 --- include/nnwt/error.h | 3 +++ include/nnwt/thread.h | 1 - include/nnwt/time.h | 3 +++ src/common.c | 2 +- src/multiplex.c | 2 +- src/packet_stream.c | 11 +++-------- src/util/error.c | 3 +++ subprojects/libalabaster.wrap | 4 ++-- subprojects/libcurl.wrap | 4 ++-- tests/command_line_args.c | 31 +++++++++++++++++++++++++++++++ tests/meson.build | 15 +++++++++------ tests/timer_loop.c | 1 + tests/timer_thread.c | 2 ++ 15 files changed, 64 insertions(+), 24 deletions(-) create mode 100644 include/nnwt/buffer.h create mode 100644 include/nnwt/error.h create mode 100644 include/nnwt/time.h create mode 100644 tests/command_line_args.c diff --git a/include/nnwt/buffer.h b/include/nnwt/buffer.h new file mode 100644 index 0000000..27efb8d --- /dev/null +++ b/include/nnwt/buffer.h @@ -0,0 +1,3 @@ +#pragma once + +#include "../../src/util/buffer.h" diff --git a/include/nnwt/common.h b/include/nnwt/common.h index 71b0ed7..7da1720 100644 --- a/include/nnwt/common.h +++ b/include/nnwt/common.h @@ -1,6 +1,3 @@ #pragma once #include "../../src/common.h" -#include "../../src/util/error.h" -#include "../../src/util/buffer.h" -#include "../../src/util/timer/timer.h" diff --git a/include/nnwt/error.h b/include/nnwt/error.h new file mode 100644 index 0000000..0db5935 --- /dev/null +++ b/include/nnwt/error.h @@ -0,0 +1,3 @@ +#pragma once + +#include "../../src/util/error.h" diff --git a/include/nnwt/thread.h b/include/nnwt/thread.h index 729b1d4..4759077 100644 --- a/include/nnwt/thread.h +++ b/include/nnwt/thread.h @@ -1,4 +1,3 @@ #pragma once #include "../../src/util/thread/thread.h" -#include "../../src/util/timer/timer.h" diff --git a/include/nnwt/time.h b/include/nnwt/time.h new file mode 100644 index 0000000..f64956d --- /dev/null +++ b/include/nnwt/time.h @@ -0,0 +1,3 @@ +#pragma once + +#include "../../src/util/timer/timer.h" diff --git a/src/common.c b/src/common.c index 01483f0..d0bd863 100644 --- a/src/common.c +++ b/src/common.c @@ -88,7 +88,7 @@ bool nn_common_init(const char *thread_name) free, malloc_lock, malloc_unlock); #endif - al_rand_init((u32)(nn_get_timestamp() / 1000000)); + al_random_init((u32)(nn_get_timestamp() / 1000000)); #ifdef NAUNET_ON_WINDOWS if (!nn_windows_init()) return false; diff --git a/src/multiplex.c b/src/multiplex.c index 9744957..2de4621 100644 --- a/src/multiplex.c +++ b/src/multiplex.c @@ -34,7 +34,7 @@ static void socket_read_callback(struct ev_loop *loop, ev_io *w, s32 revents) return; } - log_trace("ID byte: 0x%hhx.\n", id); + log_trace("ID byte: 0x%hhx.", id); switch (id) { case 0x48: // '(H)EAD' break; diff --git a/src/packet_stream.c b/src/packet_stream.c index 0cf296c..7868242 100644 --- a/src/packet_stream.c +++ b/src/packet_stream.c @@ -31,13 +31,6 @@ static void stop_write_internal(struct nn_packet_stream *stream) ev_io_stop(stream->loop->ev, &stream->wevent); } -static void shutdown_internal(struct nn_packet_stream *stream) -{ - stream->connect = PACKET_STREAM_DISCONNECTING; - // This assumes select()/poll() will return after shutdown(). - nn_socket_shutdown(&stream->sock); -} - static void discard_out_queue_internal(struct nn_packet_stream *stream) { // stream->out.running can be true here. The stream will stop the @@ -352,7 +345,9 @@ void nn_packet_stream_disconnect(struct nn_packet_stream *stream) // This relies on stream_read_callback() to resolve and call stop_internal(). // Note that read() can still return data after shutdown(). This is why we have to // check if connect = DISCONNECTING in send_packet(). - shutdown_internal(stream); + stream->connect = PACKET_STREAM_DISCONNECTING; + // This assumes select()/poll() will return after shutdown(). + nn_socket_shutdown(&stream->sock); } } diff --git a/src/util/error.c b/src/util/error.c index 61c6136..97c7502 100644 --- a/src/util/error.c +++ b/src/util/error.c @@ -22,6 +22,7 @@ char *nn_strerror(s32 errnum) // https://stackoverflow.com/a/46104456 char *nn_win32_error_message(s32 err) { + /* DWORD ret = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, @@ -30,5 +31,7 @@ char *nn_win32_error_message(s32 err) NNWT_ERROR_STR_MAXLEN, NULL); return !ret ? NULL : errorbuf; + */ + return NULL; } #endif diff --git a/subprojects/libalabaster.wrap b/subprojects/libalabaster.wrap index 3f7a977..c48903d 100644 --- a/subprojects/libalabaster.wrap +++ b/subprojects/libalabaster.wrap @@ -1,5 +1,5 @@ [wrap-git] -directory = libalabaster-dd7a1d1 +directory = libalabaster-c633226 url = https://git.akon.city/libalabaster.git -revision = dd7a1d1afb8b3e93ab1005abdc21edb6efca840a +revision = c633226d2b615f46ef38cc99603775dccdf96ecd depth = 1 diff --git a/subprojects/libcurl.wrap b/subprojects/libcurl.wrap index d1bf82a..19e3c96 100644 --- a/subprojects/libcurl.wrap +++ b/subprojects/libcurl.wrap @@ -1,6 +1,6 @@ [wrap-git] -directory = libcurl-8.17.0 +directory = libcurl-8.19.0 url = https://github.com/curl/curl.git -revision = curl-8_17_0 +revision = curl-8_19_0 depth = 1 method = cmake diff --git a/tests/command_line_args.c b/tests/command_line_args.c new file mode 100644 index 0000000..cda9328 --- /dev/null +++ b/tests/command_line_args.c @@ -0,0 +1,31 @@ +#ifndef _UNICODE +#define _UNICODE +#endif +#ifndef UNICODE +#define UNICODE +#endif +#include +#include +#include +#include + +#ifdef NAUNET_ON_WINDOWS +s32 wmain(s32 argc, wchar_t **argv) +#else +s32 main(s32 argc, char *argv[]) +#endif +{ + if (!nn_common_init(NULL)) { + return EXIT_FAILURE; + } + + for (s32 i = 0; i < argc; i++) { +#ifdef NAUNET_ON_WINDOWS + al_printf("%d: %ls %zu\n", i, argv[i], al_wcsnlen(argv[i], MAX_ALLOC_32 / sizeof(wchar_t))); +#else + al_printf("%d: %.*s %zu\n", i, al_str_x(&al_str_cr(argv[i])), al_strlen(argv[i])); +#endif + } + + return EXIT_SUCCESS; +} diff --git a/tests/meson.build b/tests/meson.build index 0482bec..0ff6ffb 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1,9 +1,12 @@ -executable('timer_thread', ['timer_thread.c'], dependencies: naunet) -executable('timer_loop', ['timer_loop.c'], dependencies: naunet) -executable('loop_sleep', ['loop_sleep.c'], dependencies: naunet) executable('misc_file', ['misc_file.c'], dependencies: naunet) executable('condition_variable', ['condition_variable.c'], dependencies: naunet) -if not is_windows - executable('stdin_lines', ['stdin_lines.c'], dependencies: naunet) - executable('fs_event', ['fs_event_local.c'], dependencies: naunet) +executable('timer_thread', ['timer_thread.c'], dependencies: naunet) +if get_option('event-loop').enabled() + executable('timer_loop', ['timer_loop.c'], dependencies: naunet) + executable('loop_sleep', ['loop_sleep.c'], dependencies: naunet) + if not is_windows + executable('stdin_lines', ['stdin_lines.c'], dependencies: naunet) + executable('fs_event', ['fs_event_local.c'], dependencies: naunet) + endif endif +executable('cmd_args', ['command_line_args.c'], dependencies: naunet, link_args: is_windows ? ['-mwindows', '-municode'] : []) diff --git a/tests/timer_loop.c b/tests/timer_loop.c index 1df6863..77ea956 100644 --- a/tests/timer_loop.c +++ b/tests/timer_loop.c @@ -1,6 +1,7 @@ #include #include #include +#include #define DELAY 100000 #define REPEAT 21 diff --git a/tests/timer_thread.c b/tests/timer_thread.c index 8ffbbc2..26a638b 100644 --- a/tests/timer_thread.c +++ b/tests/timer_thread.c @@ -1,5 +1,7 @@ +#include #include #include +#include #define DELAY 100000 #define REPEAT 21 -- cgit v1.2.3-101-g0448