ext/asyncengine/libuv/src/unix/linux/inotify.c in asyncengine-0.0.1.testing1 vs ext/asyncengine/libuv/src/unix/linux/inotify.c in asyncengine-0.0.2.alpha1
- old
+ new
@@ -49,11 +49,11 @@
RB_GENERATE_STATIC(uv__inotify_watchers, uv_fs_event_s, node, compare_watchers)
-static void uv__inotify_read(EV_P_ ev_io* w, int revents);
+static void uv__inotify_read(uv_loop_t* loop, uv__io_t* w, int revents);
static int new_inotify_fd(void) {
int fd;
@@ -83,16 +83,15 @@
if (loop->inotify_fd == -1) {
uv__set_sys_error(loop, errno);
return -1;
}
- ev_io_init(&loop->inotify_read_watcher,
- uv__inotify_read,
- loop->inotify_fd,
- EV_READ);
- ev_io_start(loop->ev, &loop->inotify_read_watcher);
- ev_unref(loop->ev);
+ uv__io_init(&loop->inotify_read_watcher,
+ uv__inotify_read,
+ loop->inotify_fd,
+ UV__IO_READ);
+ uv__io_start(loop, &loop->inotify_read_watcher);
return 0;
}
@@ -111,26 +110,22 @@
static void remove_watcher(uv_fs_event_t* handle) {
RB_REMOVE(uv__inotify_watchers, &handle->loop->inotify_watchers, handle);
}
-static void uv__inotify_read(EV_P_ ev_io* w, int revents) {
+static void uv__inotify_read(uv_loop_t* loop, uv__io_t* w, int events) {
const struct uv__inotify_event* e;
uv_fs_event_t* handle;
- uv_loop_t* uv_loop;
const char* filename;
ssize_t size;
- int events;
const char *p;
/* needs to be large enough for sizeof(inotify_event) + strlen(filename) */
char buf[4096];
- uv_loop = container_of(w, uv_loop_t, inotify_read_watcher);
-
while (1) {
do {
- size = read(uv_loop->inotify_fd, buf, sizeof buf);
+ size = read(loop->inotify_fd, buf, sizeof buf);
}
while (size == -1 && errno == EINTR);
if (size == -1) {
assert(errno == EAGAIN || errno == EWOULDBLOCK);
@@ -147,11 +142,11 @@
if (e->mask & (UV__IN_ATTRIB|UV__IN_MODIFY))
events |= UV_CHANGE;
if (e->mask & ~(UV__IN_ATTRIB|UV__IN_MODIFY))
events |= UV_RENAME;
- handle = find_watcher(uv_loop, e->wd);
+ handle = find_watcher(loop, e->wd);
if (handle == NULL)
continue; /* Handle has already been closed. */
/* inotify does not return the filename when monitoring a single file
* for modifications. Repurpose the filename for API compatibility.
@@ -183,17 +178,19 @@
events = UV__IN_ATTRIB
| UV__IN_CREATE
| UV__IN_MODIFY
| UV__IN_DELETE
| UV__IN_DELETE_SELF
+ | UV__IN_MOVE_SELF
| UV__IN_MOVED_FROM
| UV__IN_MOVED_TO;
wd = uv__inotify_add_watch(loop->inotify_fd, filename, events);
if (wd == -1) return uv__set_sys_error(loop, errno);
uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT);
+ uv__handle_start(handle); /* FIXME shouldn't start automatically */
handle->filename = strdup(filename);
handle->cb = cb;
handle->fd = wd;
add_watcher(handle);
@@ -206,6 +203,7 @@
remove_watcher(handle);
handle->fd = -1;
free(handle->filename);
handle->filename = NULL;
+ uv__handle_stop(handle);
}