Skip to content

Commit 5a58f02

Browse files
[uv] added fs_start_wrap_ex (#924)
This allow exposing the full fs_event api with the recursive parameter and the whole argument list for the callback
1 parent 5b646f8 commit 5a58f02

1 file changed

Lines changed: 42 additions & 2 deletions

File tree

libs/uv/uv.c

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ typedef struct sockaddr uv_sockaddr;
2222
#define EVT_CONNECT 0 // connect_t
2323

2424
#define EVT_FS 0
25+
#define EVT_FS_EX 3
2526

26-
#define EVT_MAX 2
27+
#define EVT_MAX 3
2728

2829
typedef struct {
2930
vclosure *events[EVT_MAX + 1];
@@ -236,6 +237,22 @@ static void on_fs_event(uv_fs_event_t* handle, const char* filename, int events,
236237
trigger_callb((uv_handle_t*)handle, EVT_FS, args, 1, true);
237238
}
238239

240+
static void on_fs_event_ex(uv_fs_event_t* handle, const char* filename, int events, int status) {
241+
vdynamic name;
242+
name.t = &hlt_bytes;
243+
name.v.ptr = (void*)filename;
244+
245+
vdynamic ev;
246+
ev.t = &hlt_i32;
247+
ev.v.i = events;
248+
249+
vdynamic* args[2];
250+
args[0] = &name;
251+
args[1] = &ev;
252+
253+
trigger_callb((uv_handle_t*)handle, EVT_FS_EX, args, 2, true);
254+
}
255+
239256
HL_PRIM uv_fs_event_t* HL_NAME(fs_start_wrap)(uv_loop_t* loop, vclosure* cb, char* path) {
240257
uv_fs_event_t* handle = UV_ALLOC(uv_fs_event_t);
241258
if (uv_fs_event_init(loop, handle) < 0) {
@@ -252,20 +269,43 @@ HL_PRIM uv_fs_event_t* HL_NAME(fs_start_wrap)(uv_loop_t* loop, vclosure* cb, cha
252269
return handle;
253270
}
254271

272+
HL_PRIM uv_fs_event_t* HL_NAME(fs_start_wrap_ex)(uv_loop_t* loop, vclosure* cb, char* path, bool recursive) {
273+
// Uv only implements the recursive flag on Windows and MacOs
274+
#if !defined(HL_WIN) && !defined(HL_MAC)
275+
if (recursive)
276+
return NULL;
277+
#endif
278+
uv_fs_event_t* handle = UV_ALLOC(uv_fs_event_t);
279+
if (uv_fs_event_init(loop, handle) < 0) {
280+
free(handle);
281+
return NULL;
282+
}
283+
init_hl_data((uv_handle_t*)handle);
284+
register_callb((uv_handle_t*)handle, cb, EVT_FS_EX);
285+
286+
if (uv_fs_event_start(handle, on_fs_event_ex, path, recursive ? UV_FS_EVENT_RECURSIVE : 0) < 0) {
287+
free_handle(handle);
288+
return NULL;
289+
}
290+
return handle;
291+
}
292+
255293
HL_PRIM bool HL_NAME(fs_stop_wrap)(uv_fs_event_t* handle) {
256294
clear_callb((uv_handle_t*)handle, EVT_FS);
295+
clear_callb((uv_handle_t*)handle, EVT_FS_EX);
257296
return uv_fs_event_stop(handle);
258297
}
259298

260299
DEFINE_PRIM(_TCP, tcp_init_wrap, _LOOP);
261-
DEFINE_PRIM(_HANDLE, tcp_connect_wrap, _TCP _I32 _I32 _FUN(_VOID,_BOOL));
300+
DEFINE_PRIM(_HANDLE, tcp_connect_wrap, _TCP _I32 _I32 _FUN(_VOID, _BOOL));
262301
DEFINE_PRIM(_BOOL, tcp_bind_wrap, _TCP _I32 _I32);
263302
DEFINE_PRIM(_HANDLE, tcp_accept_wrap, _HANDLE);
264303
DEFINE_PRIM(_VOID, tcp_nodelay_wrap, _TCP _BOOL);
265304

266305
// handle FS
267306

268307
DEFINE_PRIM(_FS, fs_start_wrap, _LOOP _FUN(_VOID, _I32) _BYTES);
308+
DEFINE_PRIM(_FS, fs_start_wrap_ex, _LOOP _FUN(_VOID, _BYTES _I32) _BYTES _BOOL);
269309
DEFINE_PRIM(_BOOL, fs_stop_wrap, _FS);
270310

271311
// loop

0 commit comments

Comments
 (0)