unix: fold uv__io_cb into ev_io struct
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.
This commit is contained in:
parent
3bc9707054
commit
5b9c45120a
@ -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 */
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user