Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
unix: unref fs event watcher
Browse files Browse the repository at this point in the history
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
bnoordhuis committed Jan 2, 2012
1 parent 43e3ac5 commit 38fc6ad
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/unix/kqueue.c
Expand Up @@ -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);
}

Expand Down
2 changes: 2 additions & 0 deletions src/unix/linux.c
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/unix/sunos.c
Expand Up @@ -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;
Expand Down
20 changes: 19 additions & 1 deletion test/test-fs-event.c
Expand Up @@ -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);
Expand All @@ -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;
}
2 changes: 2 additions & 0 deletions test/test-list.h
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 38fc6ad

Please sign in to comment.