unix: clean up uv__req_init()

This commit is contained in:
Ben Noordhuis 2012-04-18 22:29:58 +02:00
parent 5953129353
commit ab3b307df3
5 changed files with 16 additions and 23 deletions

View File

@ -283,12 +283,6 @@ int64_t uv_now(uv_loop_t* loop) {
}
void uv__req_init(uv_loop_t* loop, uv_req_t* req) {
loop->counters.req_init++;
req->type = UV_UNKNOWN_REQ;
}
int uv_is_active(const uv_handle_t* handle) {
switch (handle->type) {
case UV_CHECK:
@ -369,8 +363,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
return -1;
}
uv__req_init(loop, (uv_req_t*)handle);
handle->type = UV_GETADDRINFO;
uv__req_init(loop, handle, UV_GETADDRINFO);
handle->loop = loop;
handle->cb = cb;

View File

@ -66,8 +66,7 @@ static void uv_fs_req_init(uv_loop_t* loop, uv_fs_t* req, uv_fs_type fs_type,
/* Make sure the thread pool is initialized. */
uv_eio_init(loop);
uv__req_init(loop, (uv_req_t*)req);
req->type = UV_FS;
uv__req_init(loop, req, UV_FS);
req->loop = loop;
req->fs_type = fs_type;
req->cb = cb;
@ -689,7 +688,7 @@ int uv_queue_work(uv_loop_t* loop, uv_work_t* req, uv_work_cb work_cb,
uv_eio_init(loop);
uv__req_init(loop, (uv_req_t*)req);
uv__req_init(loop, req, UV_WORK);
uv_ref(loop);
req->loop = loop;
req->data = data;

View File

@ -97,6 +97,15 @@ enum {
UV_TIMER_REPEAT = 0x100
};
inline static void uv__req_init(uv_loop_t* loop,
uv_req_t* req,
uv_req_type type) {
loop->counters.req_init++;
req->type = type;
}
#define uv__req_init(loop, req, type) \
uv__req_init((loop), (uv_req_t*)(req), (type))
/* core */
void uv__handle_init(uv_loop_t* loop, uv_handle_t* handle, uv_handle_type type);
int uv__nonblock(int fd, int set) __attribute__((unused));
@ -112,9 +121,6 @@ void uv__loop_delete(uv_loop_t* loop);
uv_err_code uv_translate_sys_error(int sys_errno);
void uv_fatal_error(const int errorno, const char* syscall);
/* requests */
void uv__req_init(uv_loop_t* loop, uv_req_t*);
/* stream */
void uv__stream_init(uv_loop_t* loop, uv_stream_t* stream,
uv_handle_type type);

View File

@ -700,12 +700,10 @@ int uv_shutdown(uv_shutdown_t* req, uv_stream_t* stream, uv_shutdown_cb cb) {
}
/* Initialize request */
uv__req_init(stream->loop, (uv_req_t*)req);
uv__req_init(stream->loop, req, UV_SHUTDOWN);
req->handle = stream;
req->cb = cb;
stream->shutdown_req = req;
req->type = UV_SHUTDOWN;
((uv_handle_t*)stream)->flags |= UV_SHUTTING;
@ -810,10 +808,9 @@ int uv__connect(uv_connect_t* req, uv_stream_t* stream, struct sockaddr* addr,
}
}
uv__req_init(stream->loop, (uv_req_t*)req);
uv__req_init(stream->loop, req, UV_CONNECT);
req->cb = cb;
req->handle = stream;
req->type = UV_CONNECT;
ngx_queue_init(&req->queue);
if (stream->connect_req) {
@ -887,12 +884,11 @@ int uv_write2(uv_write_t* req, uv_stream_t* stream, uv_buf_t bufs[], int bufcnt,
empty_queue = (stream->write_queue_size == 0);
/* Initialize the req */
uv__req_init(stream->loop, (uv_req_t*)req);
uv__req_init(stream->loop, req, UV_WRITE);
req->cb = cb;
req->handle = stream;
req->error = 0;
req->send_handle = send_handle;
req->type = UV_WRITE;
ngx_queue_init(&req->queue);
if (bufcnt <= UV_REQ_BUFSML_SIZE) {

View File

@ -437,14 +437,13 @@ static int uv__udp_send(uv_udp_send_t* req,
if (uv__udp_maybe_deferred_bind(handle, addr->sa_family))
return -1;
uv__req_init(handle->loop, (uv_req_t*)req);
uv__req_init(handle->loop, req, UV_UDP_SEND);
memcpy(&req->addr, addr, addrlen);
req->addrlen = addrlen;
req->send_cb = send_cb;
req->handle = handle;
req->bufcnt = bufcnt;
req->type = UV_UDP_SEND;
if (bufcnt <= UV_REQ_BUFSML_SIZE) {
req->bufs = req->bufsml;