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

Commit

Permalink
unix: fold uv__io_cb into ev_io struct
Browse files Browse the repository at this point in the history
Makes the uv__io code a little more obscure but has the advantage that
sizeof(uv__io_t) == sizeof(ev_io), i.e. the sizes of embedding handles
don't change.
  • Loading branch information
bnoordhuis committed May 23, 2012
1 parent 3bc9707 commit 5b9c451
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 0 additions & 1 deletion include/uv-private/uv-unix.h
Expand Up @@ -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 */
Expand Down
15 changes: 12 additions & 3 deletions src/unix/core.c
Expand Up @@ -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);
}


Expand Down
4 changes: 0 additions & 4 deletions src/unix/stream.c
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 5b9c451

Please sign in to comment.