From 4e9c4b8ec81e612b03477fcc68def4b8878cf3ac Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Mon, 8 Jan 2024 16:32:23 -0500 Subject: Partially fix windows build Signed-off-by: Andrew Opalach --- include/aki/fs_event.h | 2 +- meson.build | 6 ++++- src/fs_event.c | 56 ---------------------------------------- src/fs_event.h | 25 ------------------ src/fs_event/fs_event.h | 26 +++++++++++++++++++ src/fs_event/fs_event_inotify.c | 57 +++++++++++++++++++++++++++++++++++++++++ src/winwrap.c | 9 +++---- src/winwrap.h | 4 +++ 8 files changed, 96 insertions(+), 89 deletions(-) delete mode 100644 src/fs_event.c delete mode 100644 src/fs_event.h create mode 100644 src/fs_event/fs_event.h create mode 100644 src/fs_event/fs_event_inotify.c diff --git a/include/aki/fs_event.h b/include/aki/fs_event.h index 76db88a..61f75df 100644 --- a/include/aki/fs_event.h +++ b/include/aki/fs_event.h @@ -1,3 +1,3 @@ #pragma once -#include "../src/fs_event.h" +#include "../src/fs_event/fs_event.h" diff --git a/meson.build b/meson.build index 3ee5e95..103f4d3 100644 --- a/meson.build +++ b/meson.build @@ -35,7 +35,6 @@ if get_option('event-loop').enabled() akiyo_src += [ 'src/loop.c', 'src/poll.c', - 'src/fs_event.c', 'src/timer.c', 'src/signal.c', 'src/packet_pool.c', @@ -96,6 +95,11 @@ if host_machine.system() != 'windows' 'src/util/file/file_linux.c', 'src/socket/socket_linux.c' ] + if get_option('event-loop').enabled() + akiyo_src += [ + 'src/fs_event/fs_event_inotify.c' + ] + endif akiyo_args += ['-D_GNU_SOURCE'] akiyo_has_mmap = true else diff --git a/src/fs_event.c b/src/fs_event.c deleted file mode 100644 index 8edce13..0000000 --- a/src/fs_event.c +++ /dev/null @@ -1,56 +0,0 @@ -#include - -#include "util/error.h" - -#include "fs_event.h" - -static void event_callback(struct ev_loop *loop, ev_io *w, s32 revents) -{ - (void)loop; - struct aki_fs_event *fs = (struct aki_fs_event *)w->data; - (void)revents; - struct inotify_event event = { 0 }; - ssize_t ret = aki_read(fs->fd, &event, sizeof(struct inotify_event)); - if (ret == sizeof(struct inotify_event)) { - al_assert(event.wd == fs->wd); - al_assert(event.len == 0); - fs->callback(fs->userdata, &event); - } -} - -void aki_fs_event_init(struct aki_fs_event *fs, str *path, u32 mask, - void (*callback)(void *, struct inotify_event *), void *userdata) -{ - fs->fd = inotify_init(); - aki_fd_set_blocking(fs->fd, true); - fs->mask = mask; - fs->callback = callback; - fs->userdata = userdata; - fs->path = al_str_to_c_str(path); - fs->event.data = fs; - ev_io_init(&fs->event, event_callback, fs->fd, EV_READ); -} - -bool aki_fs_event_start(struct aki_fs_event *fs, struct aki_event_loop *loop) -{ - fs->loop = loop; - fs->wd = inotify_add_watch(fs->fd, fs->path, fs->mask); - if (fs->wd == -1) { - al_log_error("fs_event", "inotify_add_watch(%s) failed (%s)", fs->path, aki_strerror(errno)); - return false; - } - ev_io_start(fs->loop->ev, &fs->event); - return true; -} - -void aki_fs_event_stop(struct aki_fs_event *fs) -{ - inotify_rm_watch(fs->fd, fs->wd); - ev_io_stop(fs->loop->ev, &fs->event); -} - -void aki_fs_event_free(struct aki_fs_event *fs) -{ - close(fs->fd); - al_free(fs->path); -} diff --git a/src/fs_event.h b/src/fs_event.h deleted file mode 100644 index d45d7af..0000000 --- a/src/fs_event.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include -#include - -#include "socket/socket.h" - -#include "loop.h" - -struct aki_fs_event { - s32 fd; - u32 mask; - char *path; - s32 wd; - ev_io event; - struct aki_event_loop *loop; - void (*callback)(void *, struct inotify_event *); - void *userdata; -}; - -void aki_fs_event_init(struct aki_fs_event *fs, str *path, u32 mask, - void (*callback)(void *, struct inotify_event *), void *userdata); -bool aki_fs_event_start(struct aki_fs_event *fs, struct aki_event_loop *loop); -void aki_fs_event_stop(struct aki_fs_event *fs); -void aki_fs_event_free(struct aki_fs_event *fs); diff --git a/src/fs_event/fs_event.h b/src/fs_event/fs_event.h new file mode 100644 index 0000000..0240e6f --- /dev/null +++ b/src/fs_event/fs_event.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +#ifndef _WIN32 +#include +#endif + +#include "../loop.h" + +struct aki_fs_event { + s32 fd; + u32 mask; + char *path; + s32 wd; + ev_io event; + struct aki_event_loop *loop; + void (*callback)(void *, struct inotify_event *); + void *userdata; +}; + +void aki_fs_event_init(struct aki_fs_event *fs, str *path, u32 mask, + void (*callback)(void *, struct inotify_event *), void *userdata); +bool aki_fs_event_start(struct aki_fs_event *fs, struct aki_event_loop *loop); +void aki_fs_event_stop(struct aki_fs_event *fs); +void aki_fs_event_free(struct aki_fs_event *fs); diff --git a/src/fs_event/fs_event_inotify.c b/src/fs_event/fs_event_inotify.c new file mode 100644 index 0000000..0fc19b4 --- /dev/null +++ b/src/fs_event/fs_event_inotify.c @@ -0,0 +1,57 @@ +#include + +#include "../util/error.h" +#include "../socket/socket.h" + +#include "fs_event.h" + +static void event_callback(struct ev_loop *loop, ev_io *w, s32 revents) +{ + (void)loop; + struct aki_fs_event *fs = (struct aki_fs_event *)w->data; + (void)revents; + struct inotify_event event = { 0 }; + ssize_t ret = aki_read(fs->fd, &event, sizeof(struct inotify_event)); + if (ret == sizeof(struct inotify_event)) { + al_assert(event.wd == fs->wd); + al_assert(event.len == 0); + fs->callback(fs->userdata, &event); + } +} + +void aki_fs_event_init(struct aki_fs_event *fs, str *path, u32 mask, + void (*callback)(void *, struct inotify_event *), void *userdata) +{ + fs->fd = inotify_init(); + aki_fd_set_blocking(fs->fd, true); + fs->mask = mask; + fs->callback = callback; + fs->userdata = userdata; + fs->path = al_str_to_c_str(path); + fs->event.data = fs; + ev_io_init(&fs->event, event_callback, fs->fd, EV_READ); +} + +bool aki_fs_event_start(struct aki_fs_event *fs, struct aki_event_loop *loop) +{ + fs->loop = loop; + fs->wd = inotify_add_watch(fs->fd, fs->path, fs->mask); + if (fs->wd == -1) { + al_log_error("fs_event", "inotify_add_watch(%s) failed (%s)", fs->path, aki_strerror(errno)); + return false; + } + ev_io_start(fs->loop->ev, &fs->event); + return true; +} + +void aki_fs_event_stop(struct aki_fs_event *fs) +{ + inotify_rm_watch(fs->fd, fs->wd); + ev_io_stop(fs->loop->ev, &fs->event); +} + +void aki_fs_event_free(struct aki_fs_event *fs) +{ + close(fs->fd); + al_free(fs->path); +} diff --git a/src/winwrap.c b/src/winwrap.c index a0a1229..b1ab115 100644 --- a/src/winwrap.c +++ b/src/winwrap.c @@ -9,14 +9,11 @@ void aki_windows_init(void) WSAStartup(MAKEWORD(2,2), &data); ULONG actual_resolution; - NTSTATUS(__stdcall *ZwSetTimerResolution)( - IN ULONG RequestedResolution, IN BOOLEAN Set, OUT PULONG ActualResolution) = ( - NTSTATUS(__stdcall*)(ULONG, BOOLEAN, PULONG))GetProcAddress( - GetModuleHandleW(L"ntdll"), "ZwSetTimerResolution"); + NTSTATUS(__stdcall *ZwSetTimerResolution)(IN ULONG RequestedResolution, IN BOOLEAN Set, OUT PULONG ActualResolution); + ZwSetTimerResolution = (NTSTATUS(__stdcall *)(ULONG, BOOLEAN, PULONG))GetProcAddress(GetModuleHandleW(L"ntdll"), "ZwSetTimerResolution"); ZwSetTimerResolution(1, TRUE, &actual_resolution); - NtDelayExecution = (NTSTATUS(__stdcall*)(BOOL, PLARGE_INTEGER))GetProcAddress( - GetModuleHandleW(L"ntdll"), "NtDelayExecution"); + NtDelayExecution = (NTSTATUS(__stdcall *)(BOOL, PLARGE_INTEGER))GetProcAddress(GetModuleHandleW(L"ntdll"), "NtDelayExecution"); QueryPerformanceFrequency(&performance_frequency); #endif diff --git a/src/winwrap.h b/src/winwrap.h index 83cf7ea..8a6b90d 100644 --- a/src/winwrap.h +++ b/src/winwrap.h @@ -6,7 +6,11 @@ #include #include #include +#define WIN32_NO_STATUS #include +#undef WIN32_NO_STATUS +#include +#include extern NTSTATUS(__stdcall *NtDelayExecution)(BOOL Alertable, PLARGE_INTEGER DelayInterval); extern LARGE_INTEGER performance_frequency; #endif -- cgit v1.2.3-101-g0448