diff --git a/include/uv-private/uv-unix.h b/include/uv-private/uv-unix.h index a3ef25f2..71253bc9 100644 --- a/include/uv-private/uv-unix.h +++ b/include/uv-private/uv-unix.h @@ -78,7 +78,6 @@ typedef void (*uv__io_cb)(struct uv_loop_s* loop, uv__io_t* handle, int events); struct uv__io_s { ev_io io_watcher; - uv__io_cb cb; }; #define UV_REQ_TYPE_PRIVATE /* empty */ diff --git a/src/unix/core.c b/src/unix/core.c index bd15c446..49785da0 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -594,22 +594,31 @@ uv_err_t uv_chdir(const char* dir) { } +static void uv__io_set_cb(uv__io_t* handle, uv__io_cb cb) { + union { void* data; uv__io_cb cb; } u; + u.cb = cb; + handle->io_watcher.data = u.data; +} + + static void uv__io_rw(struct ev_loop* ev, ev_io* w, int events) { + union { void* data; uv__io_cb cb; } u; uv_loop_t* loop = ev_userdata(ev); uv__io_t* handle = container_of(w, uv__io_t, io_watcher); - handle->cb(loop, handle, events & (EV_READ|EV_WRITE|EV_ERROR)); + u.data = handle->io_watcher.data; + u.cb(loop, handle, events & (EV_READ|EV_WRITE|EV_ERROR)); } void uv__io_init(uv__io_t* handle, uv__io_cb cb, int fd, int events) { ev_io_init(&handle->io_watcher, uv__io_rw, fd, events & (EV_READ|EV_WRITE)); - handle->cb = cb; + uv__io_set_cb(handle, cb); } void uv__io_set(uv__io_t* handle, uv__io_cb cb, int fd, int events) { ev_io_set(&handle->io_watcher, fd, events); - handle->cb = cb; + uv__io_set_cb(handle, cb); } diff --git a/src/unix/stream.c b/src/unix/stream.c index fca57dbb..f441c9b9 100644 --- a/src/unix/stream.c +++ b/src/unix/stream.c @@ -918,7 +918,6 @@ int uv_write2(uv_write_t* req, uv_stream_t* stream, uv_buf_t bufs[], int bufcnt, ngx_queue_insert_tail(&stream->write_queue, &req->queue); assert(!ngx_queue_empty(&stream->write_queue)); - assert(stream->write_watcher.cb == uv__stream_io); /* If the queue was empty when this function began, we should attempt to * do the write immediately. Otherwise start the write_watcher and wait @@ -976,9 +975,6 @@ int uv__read_start_common(uv_stream_t* stream, uv_alloc_cb alloc_cb, stream->read2_cb = read2_cb; stream->alloc_cb = alloc_cb; - /* These should have been set by uv_tcp_init. */ - assert(stream->read_watcher.cb == uv__stream_io); - uv__io_start(stream->loop, &stream->read_watcher); uv__handle_start(stream);