Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

unix: unref fs event watcher

Watchers were being ref-counted twice which wasn't harmful in itself but stopped
uv_unref() from working like you'd expect it to.
  • Loading branch information...
commit 38fc6ad839734a3f76d2535b8f62d92e9cfef8c7 1 parent 43e3ac5
@bnoordhuis bnoordhuis authored
View
2  src/unix/kqueue.c
@@ -43,10 +43,12 @@ static void uv__fs_event_start(uv_fs_event_t* handle) {
handle->fd,
EV_LIBUV_KQUEUE_HACK);
ev_io_start(handle->loop->ev, &handle->event_watcher);
+ ev_unref(handle->loop->ev);
}
static void uv__fs_event_stop(uv_fs_event_t* handle) {
+ ev_ref(handle->loop->ev);
ev_io_stop(handle->loop->ev, &handle->event_watcher);
}
View
2  src/unix/linux.c
@@ -283,12 +283,14 @@ int uv_fs_event_init(uv_loop_t* loop,
ev_io_init(&handle->read_watcher, uv__inotify_read, fd, EV_READ);
ev_io_start(loop->ev, &handle->read_watcher);
+ ev_unref(loop->ev);
return 0;
}
void uv__fs_event_destroy(uv_fs_event_t* handle) {
+ ev_ref(handle->loop->ev);
ev_io_stop(handle->loop->ev, &handle->read_watcher);
uv__close(handle->fd);
handle->fd = -1;
View
2  src/unix/sunos.c
@@ -166,12 +166,14 @@ int uv_fs_event_init(uv_loop_t* loop,
ev_io_init(&handle->event_watcher, uv__fs_event_read, portfd, EV_READ);
ev_io_start(loop->ev, &handle->event_watcher);
+ ev_unref(loop->ev);
return 0;
}
void uv__fs_event_destroy(uv_fs_event_t* handle) {
+ ev_ref(handle->loop->ev);
ev_io_stop(handle->loop->ev, &handle->event_watcher);
uv__close(handle->fd);
handle->fd = -1;
View
20 test/test-fs-event.c
@@ -282,7 +282,7 @@ static void timer_cb(uv_timer_t* handle, int status) {
ASSERT(status == 0);
r = uv_fs_event_init(handle->loop, &fs_event, ".", fs_event_fail, 0);
- ASSERT(r != -1);
+ ASSERT(r == 0);
uv_close((uv_handle_t*)&fs_event, close_cb);
uv_close((uv_handle_t*)handle, close_cb);
@@ -308,3 +308,21 @@ TEST_IMPL(fs_event_immediate_close) {
return 0;
}
+
+
+TEST_IMPL(fs_event_unref) {
+ uv_loop_t* loop;
+ int r;
+
+ loop = uv_default_loop();
+
+ r = uv_fs_event_init(loop, &fs_event, ".", fs_event_fail, 0);
+ ASSERT(r == 0);
+
+ uv_unref(loop);
+
+ r = uv_run(loop);
+ ASSERT(r == 0);
+
+ return 0;
+}
View
2  test/test-list.h
@@ -112,6 +112,7 @@ TEST_DECLARE (fs_event_watch_file)
TEST_DECLARE (fs_event_watch_file_current_dir)
TEST_DECLARE (fs_event_no_callback_on_close)
TEST_DECLARE (fs_event_immediate_close)
+TEST_DECLARE (fs_event_unref)
TEST_DECLARE (fs_readdir_empty_dir)
TEST_DECLARE (fs_readdir_file)
TEST_DECLARE (fs_open_dir)
@@ -268,6 +269,7 @@ TASK_LIST_START
TEST_ENTRY (fs_event_watch_file_current_dir)
TEST_ENTRY (fs_event_no_callback_on_close)
TEST_ENTRY (fs_event_immediate_close)
+ TEST_ENTRY (fs_event_unref)
TEST_ENTRY (fs_readdir_empty_dir)
TEST_ENTRY (fs_readdir_file)
TEST_ENTRY (fs_open_dir)
Please sign in to comment.
Something went wrong with that request. Please try again.