From ab75884371a3545f7548498549e2faebbc465ed6 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Tue, 12 Aug 2025 17:38:09 -0400 Subject: Improve inotify usage, copy path in file_stdio Signed-off-by: Andrew Opalach --- src/curl/websocket.c | 2 +- src/fs_event/fs_event.h | 5 +++-- src/fs_event/fs_event_inotify.c | 18 ++++++++++-------- src/util/file/file_stdio.c | 3 +++ 4 files changed, 17 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/curl/websocket.c b/src/curl/websocket.c index d40dd0e..ebd8f79 100644 --- a/src/curl/websocket.c +++ b/src/curl/websocket.c @@ -59,7 +59,7 @@ bool nn_websocket_connect(struct nn_websocket *ws, struct nn_event_loop *loop, struct nn_curl *curl = &ws->curl; al_assert(curl->loop == NULL); curl->loop = loop; - curl_easy_setopt(curl->handle, CURLOPT_CONNECT_ONLY, 0); + curl_easy_setopt(curl->handle, CURLOPT_CONNECT_ONLY, 0L); ws->callback = callback; ws->userdata = userdata; curl_easy_setopt(curl->handle, CURLOPT_WRITEFUNCTION, stream_write_callback); diff --git a/src/fs_event/fs_event.h b/src/fs_event/fs_event.h index 2cfef07..b25270e 100644 --- a/src/fs_event/fs_event.h +++ b/src/fs_event/fs_event.h @@ -4,10 +4,11 @@ #ifdef NAUNET_ON_WINDOWS struct inotify_event {}; -#define NNWT_CLOSE_WRITE 0 +#define NNWT_FS_CLOSE_WRITE 0 #else #include -#define NNWT_CLOSE_WRITE IN_CLOSE_WRITE +#define NNWT_FS_CLOSE_WRITE IN_CLOSE_WRITE +#define NNWT_FS_CREATE IN_CREATE #endif #include "../loop.h" diff --git a/src/fs_event/fs_event_inotify.c b/src/fs_event/fs_event_inotify.c index 7def7a3..757d393 100644 --- a/src/fs_event/fs_event_inotify.c +++ b/src/fs_event/fs_event_inotify.c @@ -6,21 +6,23 @@ #include "fs_event.h" +#define EVENT_MAX_SIZE (sizeof(struct inotify_event) + NAME_MAX + 1) + static void event_callback(struct ev_loop *loop, ev_io *w, s32 revents) { (void)loop; struct nn_fs_event *fs = (struct nn_fs_event *)w->data; (void)revents; - struct inotify_event event = { 0 }; - ssize_t ret = nn_read(fs->fd, &event, sizeof(struct inotify_event)); - if (!(event.mask & IN_CLOSE_WRITE)) { - // Expecting IN_IGNORED. + struct inotify_event *event = al_malloc(EVENT_MAX_SIZE); + ssize_t ret = nn_read(fs->fd, event, EVENT_MAX_SIZE); + al_assert(ret > 0); + if (!(event->mask & fs->mask)) { + al_assert(event->mask & IN_IGNORED); return; } - al_assert(ret == sizeof(struct inotify_event)); - al_assert(event.wd == fs->wd); - al_assert(event.len == 0); - fs->callback(fs->userdata, &event); + al_assert(event->wd == fs->wd); + fs->callback(fs->userdata, event); + al_free(event); } void nn_fs_event_init(struct nn_fs_event *fs, str *path, u32 mask, diff --git a/src/util/file/file_stdio.c b/src/util/file/file_stdio.c index 97dd0f0..fa74be7 100644 --- a/src/util/file/file_stdio.c +++ b/src/util/file/file_stdio.c @@ -49,6 +49,8 @@ bool nn_file_open(struct nn_file *file, str *path, s32 flags) return false; } + al_str_clone(&file->path, path); + return true; } @@ -112,6 +114,7 @@ void *nn_file_mmap(struct nn_file *file) void nn_file_close(struct nn_file *file) { fclose(file->file); + al_str_free(&file->path); } bool nn_dir_open(struct nn_dir *dir, str *path) { (void)dir; (void)path; return false; } -- cgit v1.2.3-101-g0448