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

Commit

Permalink
unix: clean up uv__req_init()
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis committed Apr 18, 2012
1 parent 5953129 commit ab3b307
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 23 deletions.
9 changes: 1 addition & 8 deletions src/unix/core.c
Expand Up @@ -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:
Expand Down Expand Up @@ -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;

Expand Down
5 changes: 2 additions & 3 deletions src/unix/fs.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 9 additions & 3 deletions src/unix/internal.h
Expand Up @@ -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));
Expand All @@ -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);
Expand Down
10 changes: 3 additions & 7 deletions src/unix/stream.c
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions src/unix/udp.c
Expand Up @@ -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;
Expand Down

0 comments on commit ab3b307

Please sign in to comment.