diff --git a/include/eio.h b/include/eio.h index 380048c0..450df6ba 100644 --- a/include/eio.h +++ b/include/eio.h @@ -195,7 +195,7 @@ enum enum { EIO_MCL_CURRENT = 1, - EIO_MCL_FUTURE = 2, + EIO_MCL_FUTURE = 2 }; /* request priorities */ @@ -203,7 +203,7 @@ enum enum { EIO_PRI_MIN = -4, EIO_PRI_MAX = 4, - EIO_PRI_DEFAULT = 0, + EIO_PRI_DEFAULT = 0 }; /* eio request structure */ diff --git a/include/uv-unix.h b/include/uv-unix.h index 31335a92..b7f01ae7 100644 --- a/include/uv-unix.h +++ b/include/uv-unix.h @@ -42,6 +42,16 @@ typedef struct { typedef int uv_file; +#define UV_LOOP_PRIVATE_FIELDS \ + ares_channel channel; \ + /* \ + * While the channel is active this timer is called once per second to be \ + * sure that we're always calling ares_process. See the warning above the \ + * definition of ares_timeout(). \ + */ \ + ev_timer timer; \ + struct ev_loop* ev; + #define UV_REQ_BUFSML_SIZE (4) #define UV_REQ_PRIVATE_FIELDS /* empty */ diff --git a/include/uv.h b/include/uv.h index 63d93d12..ea6712e5 100644 --- a/include/uv.h +++ b/include/uv.h @@ -19,7 +19,7 @@ * IN THE SOFTWARE. */ -/* See uv_init for an introduction. */ +/* See uv_loop_new for an introduction. */ #ifndef UV_H #define UV_H @@ -41,6 +41,8 @@ extern "C" { typedef intptr_t ssize_t; #endif +typedef struct uv_loop_s uv_loop_t; +typedef struct uv_ares_task_s uv_ares_task_t; typedef struct uv_err_s uv_err_t; typedef struct uv_handle_s uv_handle_t; typedef struct uv_stream_s uv_stream_t; @@ -54,6 +56,7 @@ typedef struct uv_idle_s uv_idle_t; typedef struct uv_async_s uv_async_t; typedef struct uv_getaddrinfo_s uv_getaddrinfo_t; typedef struct uv_process_s uv_process_t; +typedef struct uv_counters_s uv_counters_t; /* Request types */ typedef struct uv_req_s uv_req_t; typedef struct uv_shutdown_s uv_shutdown_t; @@ -73,32 +76,35 @@ typedef struct uv_work_s uv_work_t; /* * This function must be called before any other functions in libuv. * - * At the moment libuv is single threaded but this will likely change in the - * near future. Basically it will change by uv_init() taking a 'loop' - * argument and all other _init having a first argument as the the 'loop'. - * * All functions besides uv_run() are non-blocking. * * All callbacks in libuv are made asynchronously. That is they are never * made by the function that takes them as a parameter. */ -void uv_init(); +uv_loop_t* uv_loop_new(); + +void uv_loop_delete(uv_loop_t*); + +/* + * Returns the default loop. + */ +uv_loop_t* uv_default_loop(); /* * This function starts the event loop. It blocks until the reference count * of the loop drops to zero. */ -int uv_run(); +int uv_run(uv_loop_t*); /* * Manually modify the event loop's reference count. Useful if the user wants * to have a handle or timeout that doesn't keep the loop alive. */ -void uv_ref(); -void uv_unref(); +void uv_ref(uv_loop_t*); +void uv_unref(uv_loop_t*); -void uv_update_time(); -int64_t uv_now(); +void uv_update_time(uv_loop_t*); +int64_t uv_now(uv_loop_t*); /* @@ -223,13 +229,14 @@ struct uv_err_s { * On error the user should then call uv_last_error() to determine * the error code. */ -uv_err_t uv_last_error(); +uv_err_t uv_last_error(uv_loop_t*); char* uv_strerror(uv_err_t err); const char* uv_err_name(uv_err_t err); #define UV_REQ_FIELDS \ /* read-only */ \ + uv_loop_t* loop; \ uv_req_type type; \ /* public */ \ void* data; \ @@ -266,6 +273,7 @@ struct uv_shutdown_s { #define UV_HANDLE_FIELDS \ /* read-only */ \ + uv_loop_t* loop; \ uv_handle_type type; \ /* public */ \ uv_close_cb close_cb; \ @@ -358,7 +366,7 @@ typedef enum { UV_STDERR } uv_std_type; -uv_stream_t* uv_std_handle(uv_std_type type); +uv_stream_t* uv_std_handle(uv_loop_t*, uv_std_type type); /* * Write data to stream. Buffers are written in order. Example: @@ -402,7 +410,7 @@ struct uv_tcp_s { UV_TCP_PRIVATE_FIELDS }; -int uv_tcp_init(uv_tcp_t* handle); +int uv_tcp_init(uv_loop_t*, uv_tcp_t* handle); int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in); int uv_tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6); @@ -485,7 +493,7 @@ struct uv_udp_send_s { * Initialize a new UDP handle. The actual socket is created lazily. * Returns 0 on success. */ -int uv_udp_init(uv_udp_t* handle); +int uv_udp_init(uv_loop_t*, uv_udp_t* handle); /* * Bind to a IPv4 address and port. @@ -590,7 +598,7 @@ struct uv_pipe_s { UV_PIPE_PRIVATE_FIELDS }; -int uv_pipe_init(uv_pipe_t* handle); +int uv_pipe_init(uv_loop_t*, uv_pipe_t* handle); int uv_pipe_bind(uv_pipe_t* handle, const char* name); @@ -610,7 +618,7 @@ struct uv_prepare_s { UV_PREPARE_PRIVATE_FIELDS }; -int uv_prepare_init(uv_prepare_t* prepare); +int uv_prepare_init(uv_loop_t*, uv_prepare_t* prepare); int uv_prepare_start(uv_prepare_t* prepare, uv_prepare_cb cb); @@ -628,7 +636,7 @@ struct uv_check_s { UV_CHECK_PRIVATE_FIELDS }; -int uv_check_init(uv_check_t* check); +int uv_check_init(uv_loop_t*, uv_check_t* check); int uv_check_start(uv_check_t* check, uv_check_cb cb); @@ -648,7 +656,7 @@ struct uv_idle_s { UV_IDLE_PRIVATE_FIELDS }; -int uv_idle_init(uv_idle_t* idle); +int uv_idle_init(uv_loop_t*, uv_idle_t* idle); int uv_idle_start(uv_idle_t* idle, uv_idle_cb cb); @@ -670,7 +678,7 @@ struct uv_async_s { UV_ASYNC_PRIVATE_FIELDS }; -int uv_async_init(uv_async_t* async, uv_async_cb async_cb); +int uv_async_init(uv_loop_t*, uv_async_t* async, uv_async_cb async_cb); /* * This can be called from other threads to wake up a libuv thread. @@ -691,7 +699,7 @@ struct uv_timer_s { UV_TIMER_PRIVATE_FIELDS }; -int uv_timer_init(uv_timer_t* timer); +int uv_timer_init(uv_loop_t*, uv_timer_t* timer); int uv_timer_start(uv_timer_t* timer, uv_timer_cb cb, int64_t timeout, int64_t repeat); @@ -717,11 +725,13 @@ int64_t uv_timer_get_repeat(uv_timer_t* timer); /* c-ares integration initialize and terminate */ -int uv_ares_init_options(ares_channel *channelptr, +int uv_ares_init_options(uv_loop_t*, + ares_channel *channelptr, struct ares_options *options, int optmask); -void uv_ares_destroy(ares_channel channel); +/* TODO remove the loop argument from this function? */ +void uv_ares_destroy(uv_loop_t*, ares_channel channel); /* @@ -745,7 +755,8 @@ struct uv_getaddrinfo_s { * Input arguments may be released after return from this call. Callback * must not call freeaddrinfo. */ - int uv_getaddrinfo(uv_getaddrinfo_t* handle, + int uv_getaddrinfo(uv_loop_t*, + uv_getaddrinfo_t* handle, uv_getaddrinfo_cb getaddrinfo_cb, const char* node, const char* service, @@ -799,7 +810,7 @@ struct uv_process_s { }; /* Initializes uv_process_t and starts the process. */ -int uv_spawn(uv_process_t*, uv_process_options_t options); +int uv_spawn(uv_loop_t*, uv_process_t*, uv_process_options_t options); /* * Kills the process with the specified signal. The user must still @@ -941,8 +952,8 @@ union uv_any_req { }; -/* Diagnostic counters */ -typedef struct { +struct uv_counters_s { + uint64_t eio_init; uint64_t req_init; uint64_t handle_init; uint64_t stream_init; @@ -955,9 +966,24 @@ typedef struct { uint64_t async_init; uint64_t timer_init; uint64_t process_init; -} uv_counters_t; +}; -uv_counters_t* uv_counters(); + +struct uv_loop_s { + UV_LOOP_PRIVATE_FIELDS + /* list used for ares task handles */ + uv_ares_task_t* uv_ares_handles_; + /* Various thing for libeio. */ + uv_async_t uv_eio_want_poll_notifier; + uv_async_t uv_eio_done_poll_notifier; + uv_idle_t uv_eio_poller; + /* Diagnostic counters */ + uv_counters_t counters; + /* The last error */ + uv_err_t last_err; + /* User data - use this for whatever. */ + void* data; +}; /* Don't export the private CPP symbols. */ diff --git a/src/uv-common.c b/src/uv-common.c index 2428fdd3..8e85db27 100644 --- a/src/uv-common.c +++ b/src/uv-common.c @@ -31,9 +31,6 @@ #include "ares/inet_net_pton.h" #include "ares/inet_ntop.h" -/* list used for ares task handles */ -static uv_ares_task_t* uv_ares_handles_ = NULL; - static uv_counters_t counters; @@ -135,20 +132,23 @@ int uv_ip6_name(struct sockaddr_in6* src, char* dst, size_t size) { /* find matching ares handle in list */ -void uv_add_ares_handle(uv_ares_task_t* handle) { - handle->ares_next = uv_ares_handles_; +void uv_add_ares_handle(uv_loop_t* loop, uv_ares_task_t* handle) { + handle->loop = loop; + handle->ares_next = loop->uv_ares_handles_; handle->ares_prev = NULL; - if (uv_ares_handles_) { - uv_ares_handles_->ares_prev = handle; + if (loop->uv_ares_handles_) { + loop->uv_ares_handles_->ares_prev = handle; } - uv_ares_handles_ = handle; + + loop->uv_ares_handles_ = handle; } /* find matching ares handle in list */ /* TODO: faster lookup */ -uv_ares_task_t* uv_find_ares_handle(ares_socket_t sock) { - uv_ares_task_t* handle = uv_ares_handles_; +uv_ares_task_t* uv_find_ares_handle(uv_loop_t* loop, ares_socket_t sock) { + uv_ares_task_t* handle = loop->uv_ares_handles_; + while (handle != NULL) { if (handle->sock == sock) { break; @@ -161,8 +161,10 @@ uv_ares_task_t* uv_find_ares_handle(ares_socket_t sock) { /* remove ares handle in list */ void uv_remove_ares_handle(uv_ares_task_t* handle) { - if (handle == uv_ares_handles_) { - uv_ares_handles_ = handle->ares_next; + uv_loop_t* loop = handle->loop; + + if (handle == loop->uv_ares_handles_) { + loop->uv_ares_handles_ = handle->ares_next; } if (handle->ares_next) { @@ -176,6 +178,6 @@ void uv_remove_ares_handle(uv_ares_task_t* handle) { /* Returns 1 if the uv_ares_handles_ list is empty. 0 otherwise. */ -int uv_ares_handles_empty() { - return uv_ares_handles_ ? 0 : 1; +int uv_ares_handles_empty(uv_loop_t* loop) { + return loop->uv_ares_handles_ ? 0 : 1; } diff --git a/src/uv-common.h b/src/uv-common.h index a1e74c61..985412d7 100644 --- a/src/uv-common.h +++ b/src/uv-common.h @@ -38,11 +38,6 @@ req->errorno = errno; \ } -/* - * Subclass of uv_handle_t. Used for integration of c-ares. - */ -typedef struct uv_ares_task_s uv_ares_task_t; - struct uv_ares_task_s { UV_HANDLE_FIELDS UV_ARES_TASK_PRIVATE_FIELDS @@ -52,9 +47,12 @@ struct uv_ares_task_s { void uv_remove_ares_handle(uv_ares_task_t* handle); -uv_ares_task_t* uv_find_ares_handle(ares_socket_t sock); -void uv_add_ares_handle(uv_ares_task_t* handle); -int uv_ares_handles_empty(); +uv_ares_task_t* uv_find_ares_handle(uv_loop_t*, ares_socket_t sock); + +/* TODO Rename to uv_ares_task_init? */ +void uv_add_ares_handle(uv_loop_t* loop, uv_ares_task_t* handle); + +int uv_ares_handles_empty(uv_loop_t* loop); #endif /* UV_COMMON_H_ */ diff --git a/src/uv-eio.c b/src/uv-eio.c index b07735ca..068b7656 100644 --- a/src/uv-eio.c +++ b/src/uv-eio.c @@ -25,48 +25,46 @@ #include -static uv_async_t uv_eio_want_poll_notifier; -static uv_async_t uv_eio_done_poll_notifier; -static uv_idle_t uv_eio_poller; -static int uv_eio_init_count; - - static void uv_eio_do_poll(uv_idle_t* watcher, int status) { - assert(watcher == &uv_eio_poller); + assert(watcher == &(watcher->loop->uv_eio_poller)); /* printf("uv_eio_poller\n"); */ - if (eio_poll() != -1 && uv_is_active((uv_handle_t*) &uv_eio_poller)) { + if (eio_poll() != -1 && uv_is_active((uv_handle_t*) watcher)) { /* printf("uv_eio_poller stop\n"); */ - uv_idle_stop(&uv_eio_poller); - uv_unref(); + uv_idle_stop(watcher); + uv_unref(watcher->loop); } } /* Called from the main thread. */ static void uv_eio_want_poll_notifier_cb(uv_async_t* watcher, int status) { - assert(watcher == &uv_eio_want_poll_notifier); + uv_loop_t* loop = watcher->loop; + + assert(watcher == &loop->uv_eio_want_poll_notifier); /* printf("want poll notifier\n"); */ - if (eio_poll() == -1 && !uv_is_active((uv_handle_t*) &uv_eio_poller)) { + if (eio_poll() == -1 && !uv_is_active((uv_handle_t*) &loop->uv_eio_poller)) { /* printf("uv_eio_poller start\n"); */ - uv_idle_start(&uv_eio_poller, uv_eio_do_poll); - uv_ref(); + uv_idle_start(&loop->uv_eio_poller, uv_eio_do_poll); + uv_ref(loop); } } static void uv_eio_done_poll_notifier_cb(uv_async_t* watcher, int revents) { - assert(watcher == &uv_eio_done_poll_notifier); + uv_loop_t* loop = watcher->loop; + + assert(watcher == &loop->uv_eio_done_poll_notifier); /* printf("done poll notifier\n"); */ - if (eio_poll() != -1 && uv_is_active((uv_handle_t*) &uv_eio_poller)) { + if (eio_poll() != -1 && uv_is_active((uv_handle_t*) &loop->uv_eio_poller)) { /* printf("uv_eio_poller stop\n"); */ - uv_idle_stop(&uv_eio_poller); - uv_unref(); + uv_idle_stop(&loop->uv_eio_poller); + uv_unref(loop); } } @@ -77,7 +75,15 @@ static void uv_eio_done_poll_notifier_cb(uv_async_t* watcher, int revents) { */ static void uv_eio_want_poll(void) { /* Signal the main thread that eio_poll need to be processed. */ + +#if 0 + /* + * TODO need to select the correct uv_loop_t and async_send to + * uv_eio_want_poll_notifier. + */ + uv_async_send(&uv_eio_want_poll_notifier); +#endif } @@ -86,22 +92,27 @@ static void uv_eio_done_poll(void) { * Signal the main thread that we should stop calling eio_poll(). * from the idle watcher. */ + +#if 0 uv_async_send(&uv_eio_done_poll_notifier); +#endif } -void uv_eio_init() { - if (uv_eio_init_count == 0) { - uv_eio_init_count++; +void uv_eio_init(uv_loop_t* loop) { + if (loop->counters.eio_init == 0) { + loop->counters.eio_init++; - uv_idle_init(&uv_eio_poller); - uv_idle_start(&uv_eio_poller, uv_eio_do_poll); + uv_idle_init(loop, &loop->uv_eio_poller); + uv_idle_start(&loop->uv_eio_poller, uv_eio_do_poll); - uv_async_init(&uv_eio_want_poll_notifier, uv_eio_want_poll_notifier_cb); - uv_unref(); + uv_async_init(loop, &loop->uv_eio_want_poll_notifier, + uv_eio_want_poll_notifier_cb); + uv_unref(loop); - uv_async_init(&uv_eio_done_poll_notifier, uv_eio_done_poll_notifier_cb); - uv_unref(); + uv_async_init(loop, &loop->uv_eio_done_poll_notifier, + uv_eio_done_poll_notifier_cb); + uv_unref(loop); eio_init(uv_eio_want_poll, uv_eio_done_poll); /* diff --git a/src/uv-eio.h b/src/uv-eio.h index 2f2d3486..711d0cf2 100644 --- a/src/uv-eio.h +++ b/src/uv-eio.h @@ -9,5 +9,5 @@ * safe to call more than once. * TODO: uv_eio_deinit */ -void uv_eio_init(void); +void uv_eio_init(uv_loop_t*); #endif diff --git a/src/uv-unix.c b/src/uv-unix.c index 914cd15c..74e1c77c 100644 --- a/src/uv-unix.c +++ b/src/uv-unix.c @@ -85,20 +85,14 @@ extern char **environ; # endif -static uv_err_t last_err; +#define container_of ngx_queue_data -struct uv_ares_data_s { - ares_channel channel; - /* - * While the channel is active this timer is called once per second to be sure - * that we're always calling ares_process. See the warning above the - * definition of ares_timeout(). - */ - ev_timer timer; -}; +static uv_loop_t default_loop_struct; +static uv_loop_t* default_loop_ptr; static struct uv_ares_data_s ares_data; +void uv__req_init(uv_loop_t*, uv_req_t*); void uv__next(EV_P_ ev_idle* watcher, int revents); static int uv__stream_open(uv_stream_t*, int fd, int flags); static void uv__finish_close(uv_handle_t* handle); @@ -180,8 +174,8 @@ static void uv_fatal_error(const int errorno, const char* syscall) { } -uv_err_t uv_last_error() { - return last_err; +uv_err_t uv_last_error(uv_loop_t* loop) { + return loop->last_err; } @@ -210,20 +204,20 @@ static uv_err_code uv_translate_sys_error(int sys_errno) { } -static uv_err_t uv_err_new_artificial(uv_handle_t* handle, int code) { +static uv_err_t uv_err_new_artificial(uv_loop_t* loop, int code) { uv_err_t err; err.sys_errno_ = 0; err.code = code; - last_err = err; + loop->last_err = err; return err; } -uv_err_t uv_err_new(uv_handle_t* handle, int sys_error) { +static uv_err_t uv_err_new(uv_loop_t* loop, int sys_error) { uv_err_t err; err.sys_errno_ = sys_error; err.code = uv_translate_sys_error(sys_error); - last_err = err; + loop->last_err = err; return err; } @@ -246,7 +240,7 @@ void uv_close(uv_handle_t* handle, uv_close_cb close_cb) { stream = (uv_stream_t*)handle; uv_read_stop(stream); - ev_io_stop(EV_DEFAULT_ &stream->write_watcher); + ev_io_stop(stream->loop->ev, &stream->write_watcher); uv__close(stream->fd); stream->fd = -1; @@ -282,21 +276,21 @@ void uv_close(uv_handle_t* handle, uv_close_cb close_cb) { case UV_ASYNC: async = (uv_async_t*)handle; - ev_async_stop(EV_DEFAULT_ &async->async_watcher); - ev_ref(EV_DEFAULT_UC); + ev_async_stop(async->loop->ev, &async->async_watcher); + ev_ref(async->loop->ev); break; case UV_TIMER: timer = (uv_timer_t*)handle; if (ev_is_active(&timer->timer_watcher)) { - ev_ref(EV_DEFAULT_UC); + ev_ref(timer->loop->ev); } - ev_timer_stop(EV_DEFAULT_ &timer->timer_watcher); + ev_timer_stop(timer->loop->ev, &timer->timer_watcher); break; case UV_PROCESS: process = (uv_process_t*)handle; - ev_child_stop(EV_DEFAULT_UC_ &process->child_watcher); + ev_child_stop(process->loop->ev, &process->child_watcher); break; default: @@ -306,31 +300,52 @@ void uv_close(uv_handle_t* handle, uv_close_cb close_cb) { handle->flags |= UV_CLOSING; /* This is used to call the on_close callback in the next loop. */ - ev_idle_start(EV_DEFAULT_ &handle->next_watcher); - ev_feed_event(EV_DEFAULT_ &handle->next_watcher, EV_IDLE); + ev_idle_start(handle->loop->ev, &handle->next_watcher); + ev_feed_event(handle->loop->ev, &handle->next_watcher, EV_IDLE); assert(ev_is_pending(&handle->next_watcher)); } -void uv_init() { - /* Initialize the default ev loop. */ -#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 - ev_default_loop(EVBACKEND_KQUEUE); -#else - ev_default_loop(EVFLAG_AUTO); -#endif +uv_loop_t* uv_loop_new() { + uv_loop_t* loop = calloc(1, sizeof(uv_loop_t)); + loop->ev = ev_loop_new(0); + return loop; } -int uv_run() { - ev_run(EV_DEFAULT_ 0); +void uv_loop_delete(uv_loop_t* loop) { + uv_ares_destroy(loop, loop->channel); + ev_loop_destroy(loop->ev); + free(loop); +} + + +uv_loop_t* uv_default_loop() { + default_loop_ptr = &default_loop_struct; + +#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 + default_loop_struct.ev = ev_default_loop(EVBACKEND_KQUEUE); +#else + default_loop_struct.ev = ev_default_loop(EVFLAG_AUTO); +#endif + + return default_loop_ptr; +} + + + + +int uv_run(uv_loop_t* loop) { + ev_run(loop->ev, 0); return 0; } -static void uv__handle_init(uv_handle_t* handle, uv_handle_type type) { - uv_counters()->handle_init++; +static void uv__handle_init(uv_loop_t* loop, uv_handle_t* handle, + uv_handle_type type) { + loop->counters.handle_init++; + handle->loop = loop; handle->type = type; handle->flags = 0; @@ -338,7 +353,7 @@ static void uv__handle_init(uv_handle_t* handle, uv_handle_type type) { handle->next_watcher.data = handle; /* Ref the loop until this handle is closed. See uv__finish_close. */ - ev_ref(EV_DEFAULT_UC); + ev_ref(loop->ev); } @@ -353,7 +368,7 @@ static void uv__udp_watcher_start(uv_udp_t* handle, ev_io* w) { w->data = handle; ev_set_cb(w, uv__udp_io); ev_io_set(w, handle->fd, flags); - ev_io_start(EV_DEFAULT_UC_ w); + ev_io_start(handle->loop->ev, w); } @@ -365,7 +380,7 @@ static void uv__udp_watcher_stop(uv_udp_t* handle, ev_io* w) { flags = (w == &handle->read_watcher ? EV_READ : EV_WRITE); - ev_io_stop(EV_DEFAULT_UC_ w); + ev_io_stop(handle->loop->ev, w); ev_io_set(w, -1, flags); ev_set_cb(w, NULL); w->data = (void*)0xDEADBABE; @@ -385,7 +400,7 @@ static void uv__udp_destroy(uv_udp_t* handle) { req = ngx_queue_data(q, uv_udp_send_t, queue); if (req->send_cb) { /* FIXME proper error code like UV_EABORTED */ - uv_err_new_artificial((uv_handle_t*)handle, UV_EINTR); + uv_err_new_artificial(handle->loop, UV_EINTR); req->send_cb(req, -1); } } @@ -488,7 +503,7 @@ static void uv__udp_run_completed(uv_udp_t* handle) { req->send_cb(req, 0); } else { - uv_err_new((uv_handle_t*)handle, -req->status); + uv_err_new(handle->loop, -req->status); req->send_cb(req, -1); } } @@ -524,11 +539,11 @@ static void uv__udp_recvmsg(uv_udp_t* handle) { if (nread == -1) { if (errno == EAGAIN || errno == EWOULDBLOCK) { - uv_err_new((uv_handle_t*)handle, EAGAIN); + uv_err_new(handle->loop, EAGAIN); handle->recv_cb(handle, 0, buf, NULL, 0); } else { - uv_err_new((uv_handle_t*)handle, errno); + uv_err_new(handle->loop, errno); handle->recv_cb(handle, -1, buf, NULL, 0); } } @@ -564,7 +579,7 @@ static void uv__udp_sendmsg(uv_udp_t* handle) { if (!ngx_queue_empty(&handle->write_completed_queue)) { /* Schedule completion callbacks. */ - ev_feed_event(EV_DEFAULT_ &handle->write_watcher, EV_WRITE); + ev_feed_event(handle->loop->ev, &handle->write_watcher, EV_WRITE); } else if (ngx_queue_empty(&handle->write_queue)) { /* Pending queue and completion queue empty, stop watcher. */ @@ -605,24 +620,24 @@ static int uv__udp_bind(uv_udp_t* handle, /* Check for bad flags. */ if (flags & ~UV_UDP_IPV6ONLY) { - uv_err_new((uv_handle_t*)handle, EINVAL); + uv_err_new(handle->loop, EINVAL); goto out; } /* Cannot set IPv6-only mode on non-IPv6 socket. */ if ((flags & UV_UDP_IPV6ONLY) && domain != AF_INET6) { - uv_err_new((uv_handle_t*)handle, EINVAL); + uv_err_new(handle->loop, EINVAL); goto out; } /* Check for already active socket. */ if (handle->fd != -1) { - uv_err_new_artificial((uv_handle_t*)handle, UV_EALREADY); + uv_err_new_artificial(handle->loop, UV_EALREADY); goto out; } if ((fd = uv__socket(domain, SOCK_DGRAM, 0)) == -1) { - uv_err_new((uv_handle_t*)handle, errno); + uv_err_new(handle->loop, errno); goto out; } @@ -630,7 +645,7 @@ static int uv__udp_bind(uv_udp_t* handle, #ifdef IPV6_V6ONLY yes = 1; if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof yes) == -1) { - uv_err_new((uv_handle_t*)handle, errno); + uv_err_new(handle->loop, errno); goto out; } #else @@ -640,7 +655,7 @@ static int uv__udp_bind(uv_udp_t* handle, } if (bind(fd, addr, len) == -1) { - uv_err_new((uv_handle_t*)handle, errno); + uv_err_new(handle->loop, errno); goto out; } @@ -704,7 +719,7 @@ static int uv__udp_send(uv_udp_send_t* req, return -1; /* Don't use uv__req_init(), it zeroes the data field. */ - uv_counters()->req_init++; + handle->loop->counters.req_init++; memcpy(&req->addr, addr, addrlen); req->addrlen = addrlen; @@ -717,7 +732,7 @@ static int uv__udp_send(uv_udp_send_t* req, req->bufs = req->bufsml; } else if ((req->bufs = malloc(bufcnt * sizeof(bufs[0]))) == NULL) { - uv_err_new((uv_handle_t*)handle, ENOMEM); + uv_err_new(handle->loop, ENOMEM); return -1; } memcpy(req->bufs, bufs, bufcnt * sizeof(bufs[0])); @@ -729,11 +744,11 @@ static int uv__udp_send(uv_udp_send_t* req, } -int uv_udp_init(uv_udp_t* handle) { +int uv_udp_init(uv_loop_t* loop, uv_udp_t* handle) { memset(handle, 0, sizeof *handle); - uv__handle_init((uv_handle_t*)handle, UV_UDP); - uv_counters()->udp_init++; + uv__handle_init(loop, (uv_handle_t*)handle, UV_UDP); + loop->counters.udp_init++; handle->fd = -1; ngx_queue_init(&handle->write_queue); @@ -797,12 +812,12 @@ int uv_udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb, uv_udp_recv_cb recv_cb) { if (alloc_cb == NULL || recv_cb == NULL) { - uv_err_new_artificial((uv_handle_t*)handle, UV_EINVAL); + uv_err_new_artificial(handle->loop, UV_EINVAL); return -1; } if (ev_is_active(&handle->read_watcher)) { - uv_err_new_artificial((uv_handle_t*)handle, UV_EALREADY); + uv_err_new_artificial(handle->loop, UV_EALREADY); return -1; } @@ -825,9 +840,9 @@ int uv_udp_recv_stop(uv_udp_t* handle) { } -int uv_tcp_init(uv_tcp_t* tcp) { - uv__handle_init((uv_handle_t*)tcp, UV_TCP); - uv_counters()->tcp_init++; +int uv_tcp_init(uv_loop_t* loop, uv_tcp_t* tcp) { + uv__handle_init(loop, (uv_handle_t*)tcp, UV_TCP); + loop->counters.tcp_init++; tcp->alloc_cb = NULL; tcp->connect_req = NULL; @@ -864,7 +879,7 @@ static int uv__tcp_bind(uv_tcp_t* tcp, if (tcp->fd < 0) { if ((tcp->fd = uv__socket(domain, SOCK_STREAM, 0)) == -1) { - uv_err_new((uv_handle_t*)tcp, errno); + uv_err_new(tcp->loop, errno); goto out; } @@ -883,7 +898,7 @@ static int uv__tcp_bind(uv_tcp_t* tcp, if (errno == EADDRINUSE) { tcp->delayed_error = errno; } else { - uv_err_new((uv_handle_t*)tcp, errno); + uv_err_new(tcp->loop, errno); goto out; } } @@ -897,7 +912,7 @@ out: int uv_tcp_bind(uv_tcp_t* tcp, struct sockaddr_in addr) { if (addr.sin_family != AF_INET) { - uv_err_new((uv_handle_t*)tcp, EFAULT); + uv_err_new(tcp->loop, EFAULT); return -1; } @@ -910,7 +925,7 @@ int uv_tcp_bind(uv_tcp_t* tcp, struct sockaddr_in addr) { int uv_tcp_bind6(uv_tcp_t* tcp, struct sockaddr_in6 addr) { if (addr.sin6_family != AF_INET6) { - uv_err_new((uv_handle_t*)tcp, EFAULT); + uv_err_new(tcp->loop, EFAULT); return -1; } @@ -933,7 +948,7 @@ static int uv__stream_open(uv_stream_t* stream, int fd, int flags) { yes = 1; if (stream->type == UV_TCP && setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) { - uv_err_new((uv_handle_t*)stream, errno); + uv_err_new(stream->loop, errno); return -1; } @@ -961,7 +976,7 @@ void uv__server_io(EV_P_ ev_io* watcher, int revents) { assert(!(stream->flags & UV_CLOSING)); if (stream->accepted_fd >= 0) { - ev_io_stop(EV_DEFAULT_ &stream->read_watcher); + ev_io_stop(EV_A, &stream->read_watcher); return; } @@ -980,7 +995,7 @@ void uv__server_io(EV_P_ ev_io* watcher, int revents) { /* TODO special trick. unlock reserved socket, accept, close. */ return; } else { - uv_err_new((uv_handle_t*)stream, errno); + uv_err_new(stream->loop, errno); stream->connection_cb((uv_stream_t*)stream, -1); } } else { @@ -988,7 +1003,7 @@ void uv__server_io(EV_P_ ev_io* watcher, int revents) { stream->connection_cb((uv_stream_t*)stream, 0); if (stream->accepted_fd >= 0) { /* The user hasn't yet accepted called uv_accept() */ - ev_io_stop(EV_DEFAULT_ &stream->read_watcher); + ev_io_stop(stream->loop->ev, &stream->read_watcher); return; } } @@ -1002,6 +1017,9 @@ int uv_accept(uv_stream_t* server, uv_stream_t* client) { int saved_errno; int status; + /* TODO document this */ + assert(server->loop == client->loop); + saved_errno = errno; status = -1; @@ -1009,7 +1027,7 @@ int uv_accept(uv_stream_t* server, uv_stream_t* client) { streamClient = (uv_stream_t*)client; if (streamServer->accepted_fd < 0) { - uv_err_new((uv_handle_t*)server, EAGAIN); + uv_err_new(server->loop, EAGAIN); goto out; } @@ -1021,7 +1039,7 @@ int uv_accept(uv_stream_t* server, uv_stream_t* client) { goto out; } - ev_io_start(EV_DEFAULT_ &streamServer->read_watcher); + ev_io_start(streamServer->loop->ev, &streamServer->read_watcher); streamServer->accepted_fd = -1; status = 0; @@ -1048,13 +1066,13 @@ static int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) { int r; if (tcp->delayed_error) { - uv_err_new((uv_handle_t*)tcp, tcp->delayed_error); + uv_err_new(tcp->loop, tcp->delayed_error); return -1; } if (tcp->fd < 0) { if ((tcp->fd = uv__socket(AF_INET, SOCK_STREAM, 0)) == -1) { - uv_err_new((uv_handle_t*)tcp, errno); + uv_err_new(tcp->loop, errno); return -1; } @@ -1069,7 +1087,7 @@ static int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) { r = listen(tcp->fd, backlog); if (r < 0) { - uv_err_new((uv_handle_t*)tcp, errno); + uv_err_new(tcp->loop, errno); return -1; } @@ -1078,13 +1096,15 @@ static int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) { /* Start listening for connections. */ ev_io_set(&tcp->read_watcher, tcp->fd, EV_READ); ev_set_cb(&tcp->read_watcher, uv__server_io); - ev_io_start(EV_DEFAULT_ &tcp->read_watcher); + ev_io_start(tcp->loop->ev, &tcp->read_watcher); return 0; } void uv__finish_close(uv_handle_t* handle) { + uv_loop_t* loop = handle->loop; + assert(handle->flags & UV_CLOSING); assert(!(handle->flags & UV_CLOSED)); handle->flags |= UV_CLOSED; @@ -1132,13 +1152,13 @@ void uv__finish_close(uv_handle_t* handle) { break; } - ev_idle_stop(EV_DEFAULT_ &handle->next_watcher); + ev_idle_stop(loop->ev, &handle->next_watcher); if (handle->close_cb) { handle->close_cb(handle); } - ev_unref(EV_DEFAULT_UC); + ev_unref(loop->ev); } @@ -1181,7 +1201,7 @@ static void uv__drain(uv_stream_t* stream) { assert(!uv_write_queue_head(stream)); assert(stream->write_queue_size == 0); - ev_io_stop(EV_DEFAULT_ &stream->write_watcher); + ev_io_stop(stream->loop->ev, &stream->write_watcher); /* Shutdown? */ if ((stream->flags & UV_SHUTTING) && @@ -1193,12 +1213,12 @@ static void uv__drain(uv_stream_t* stream) { if (shutdown(stream->fd, SHUT_WR)) { /* Error. Report it. User should call uv_close(). */ - uv_err_new((uv_handle_t*)stream, errno); + uv_err_new(stream->loop, errno); if (req->cb) { req->cb(req, -1); } } else { - uv_err_new((uv_handle_t*)stream, 0); + uv_err_new(stream->loop, 0); ((uv_handle_t*) stream)->flags |= UV_SHUT; if (req->cb) { req->cb(req, 0); @@ -1253,7 +1273,7 @@ static uv_write_t* uv__write(uv_stream_t* stream) { if (n < 0) { if (errno != EAGAIN) { /* Error */ - uv_err_new((uv_handle_t*)stream, errno); + uv_err_new(stream->loop, errno); return req; } } else { @@ -1301,7 +1321,7 @@ static uv_write_t* uv__write(uv_stream_t* stream) { * TODO: start trying to write the next request. */ ngx_queue_insert_tail(&stream->write_completed_queue, &req->queue); - ev_feed_event(EV_DEFAULT_ &stream->write_watcher, EV_WRITE); + ev_feed_event(stream->loop->ev, &stream->write_watcher, EV_WRITE); return NULL; } } @@ -1312,7 +1332,7 @@ static uv_write_t* uv__write(uv_stream_t* stream) { assert(n == 0 || n == -1); /* We're not done. */ - ev_io_start(EV_DEFAULT_ &stream->write_watcher); + ev_io_start(stream->loop->ev, &stream->write_watcher); return NULL; } @@ -1350,6 +1370,7 @@ static void uv__write_callbacks(uv_stream_t* stream) { static void uv__read(uv_stream_t* stream) { uv_buf_t buf; ssize_t nread; + struct ev_loop* ev = stream->loop->ev; /* XXX: Maybe instead of having UV_READING we just test if * tcp->read_cb is NULL or not? @@ -1372,22 +1393,22 @@ static void uv__read(uv_stream_t* stream) { if (errno == EAGAIN) { /* Wait for the next one. */ if (stream->flags & UV_READING) { - ev_io_start(EV_DEFAULT_UC_ &stream->read_watcher); + ev_io_start(ev, &stream->read_watcher); } - uv_err_new((uv_handle_t*)stream, EAGAIN); + uv_err_new(stream->loop, EAGAIN); stream->read_cb(stream, 0, buf); return; } else { /* Error. User should call uv_close(). */ - uv_err_new((uv_handle_t*)stream, errno); + uv_err_new(stream->loop, errno); stream->read_cb(stream, -1, buf); assert(!ev_is_active(&stream->read_watcher)); return; } } else if (nread == 0) { /* EOF */ - uv_err_new_artificial((uv_handle_t*)stream, UV_EOF); - ev_io_stop(EV_DEFAULT_UC_ &stream->read_watcher); + uv_err_new_artificial(stream->loop, UV_EOF); + ev_io_stop(ev, &stream->read_watcher); stream->read_cb(stream, -1, buf); return; } else { @@ -1407,12 +1428,12 @@ int uv_shutdown(uv_shutdown_t* req, uv_stream_t* stream, uv_shutdown_cb cb) { stream->flags & UV_SHUT || stream->flags & UV_CLOSED || stream->flags & UV_CLOSING) { - uv_err_new((uv_handle_t*)stream, EINVAL); + uv_err_new(stream->loop, EINVAL); return -1; } /* Initialize request */ - uv__req_init((uv_req_t*)req); + uv__req_init(stream->loop, (uv_req_t*)req); req->handle = stream; req->cb = cb; @@ -1422,7 +1443,7 @@ int uv_shutdown(uv_shutdown_t* req, uv_stream_t* stream, uv_shutdown_cb cb) { ((uv_handle_t*)stream)->flags |= UV_SHUTTING; - ev_io_start(EV_DEFAULT_UC_ &stream->write_watcher); + ev_io_start(stream->loop->ev, &stream->write_watcher); return 0; } @@ -1489,7 +1510,7 @@ static void uv__stream_connect(uv_stream_t* stream) { } if (!error) { - ev_io_start(EV_DEFAULT_ &stream->read_watcher); + ev_io_start(stream->loop->ev, &stream->read_watcher); /* Successful connection */ stream->connect_req = NULL; @@ -1502,7 +1523,7 @@ static void uv__stream_connect(uv_stream_t* stream) { return; } else { /* Error */ - uv_err_new((uv_handle_t*)stream, error); + uv_err_new(stream->loop, error); stream->connect_req = NULL; if (req->cb) { @@ -1523,7 +1544,7 @@ static int uv__connect(uv_connect_t* req, if (stream->fd <= 0) { if ((sockfd = uv__socket(addr->sa_family, SOCK_STREAM, 0)) == -1) { - uv_err_new((uv_handle_t*)stream, errno); + uv_err_new(stream->loop, errno); return -1; } @@ -1533,19 +1554,19 @@ static int uv__connect(uv_connect_t* req, } } - uv__req_init((uv_req_t*)req); + uv__req_init(stream->loop, (uv_req_t*)req); req->cb = cb; req->handle = stream; req->type = UV_CONNECT; ngx_queue_init(&req->queue); if (stream->connect_req) { - uv_err_new((uv_handle_t*)stream, EALREADY); + uv_err_new(stream->loop, EALREADY); return -1; } if (stream->type != UV_TCP) { - uv_err_new((uv_handle_t*)stream, ENOTSOCK); + uv_err_new(stream->loop, ENOTSOCK); return -1; } @@ -1569,16 +1590,16 @@ static int uv__connect(uv_connect_t* req, break; default: - uv_err_new((uv_handle_t*)stream, errno); + uv_err_new(stream->loop, errno); return -1; } } assert(stream->write_watcher.data == stream); - ev_io_start(EV_DEFAULT_ &stream->write_watcher); + ev_io_start(stream->loop->ev, &stream->write_watcher); if (stream->delayed_error) { - ev_feed_event(EV_DEFAULT_ &stream->write_watcher, EV_WRITE); + ev_feed_event(stream->loop->ev, &stream->write_watcher, EV_WRITE); } return 0; @@ -1596,12 +1617,12 @@ int uv_tcp_connect(uv_connect_t* req, status = -1; if (handle->type != UV_TCP) { - uv_err_new((uv_handle_t*)handle, EINVAL); + uv_err_new(handle->loop, EINVAL); goto out; } if (address.sin_family != AF_INET) { - uv_err_new((uv_handle_t*)handle, EINVAL); + uv_err_new(handle->loop, EINVAL); goto out; } @@ -1628,12 +1649,12 @@ int uv_tcp_connect6(uv_connect_t* req, status = -1; if (handle->type != UV_TCP) { - uv_err_new((uv_handle_t*)handle, EINVAL); + uv_err_new(handle->loop, EINVAL); goto out; } if (address.sin6_family != AF_INET6) { - uv_err_new((uv_handle_t*)handle, EINVAL); + uv_err_new(handle->loop, EINVAL); goto out; } @@ -1660,7 +1681,7 @@ int uv_getsockname(uv_handle_t* handle, struct sockaddr* name, int* namelen) { socklen = (socklen_t)*namelen; if (getsockname(handle->fd, name, &socklen) == -1) { - uv_err_new((uv_handle_t*)handle, errno); + uv_err_new(handle->loop, errno); } else { *namelen = (int)socklen; } @@ -1693,7 +1714,7 @@ int uv_write(uv_write_t* req, uv_stream_t* handle, uv_buf_t bufs[], int bufcnt, stream = (uv_stream_t*)handle; /* Initialize the req */ - uv__req_init((uv_req_t*) req); + uv__req_init(handle->loop, (uv_req_t*) req); req->cb = cb; req->handle = handle; ngx_queue_init(&req->queue); @@ -1704,7 +1725,7 @@ int uv_write(uv_write_t* req, uv_stream_t* handle, uv_buf_t bufs[], int bufcnt, empty_queue = (stream->write_queue_size == 0); if (stream->fd < 0) { - uv_err_new((uv_handle_t*)stream, EBADF); + uv_err_new(stream->loop, EBADF); return -1; } @@ -1753,35 +1774,35 @@ int uv_write(uv_write_t* req, uv_stream_t* handle, uv_buf_t bufs[], int bufcnt, * fresh stack so we feed the event loop in order to service it. */ if (ngx_queue_empty(&stream->write_queue)) { - ev_feed_event(EV_DEFAULT_ &stream->write_watcher, EV_WRITE); + ev_feed_event(stream->loop->ev, &stream->write_watcher, EV_WRITE); } else { /* Otherwise there is data to write - so we should wait for the file * descriptor to become writable. */ - ev_io_start(EV_DEFAULT_ &stream->write_watcher); + ev_io_start(stream->loop->ev, &stream->write_watcher); } return 0; } -void uv_ref() { - ev_ref(EV_DEFAULT_UC); +void uv_ref(uv_loop_t* loop) { + ev_ref(loop->ev); } -void uv_unref() { - ev_unref(EV_DEFAULT_UC); +void uv_unref(uv_loop_t* loop) { + ev_unref(loop->ev); } -void uv_update_time() { - ev_now_update(EV_DEFAULT_UC); +void uv_update_time(uv_loop_t* loop) { + ev_now_update(loop->ev); } -int64_t uv_now() { - return (int64_t)(ev_now(EV_DEFAULT_UC) * 1000); +int64_t uv_now(uv_loop_t* loop) { + return (int64_t)(ev_now(loop->ev) * 1000); } @@ -1811,7 +1832,7 @@ int uv_read_start(uv_stream_t* stream, uv_alloc_cb alloc_cb, uv_read_cb read_cb) /* These should have been set by uv_tcp_init. */ assert(stream->read_watcher.cb == uv__stream_io); - ev_io_start(EV_DEFAULT_UC_ &stream->read_watcher); + ev_io_start(stream->loop->ev, &stream->read_watcher); return 0; } @@ -1821,16 +1842,17 @@ int uv_read_stop(uv_stream_t* stream) { ((uv_handle_t*)tcp)->flags &= ~UV_READING; - ev_io_stop(EV_DEFAULT_UC_ &tcp->read_watcher); + ev_io_stop(tcp->loop->ev, &tcp->read_watcher); tcp->read_cb = NULL; tcp->alloc_cb = NULL; return 0; } -void uv__req_init(uv_req_t* req) { - uv_counters()->req_init++; +void uv__req_init(uv_loop_t* loop, uv_req_t* req) { + loop->counters.req_init++; req->type = UV_UNKNOWN_REQ; + req->loop = loop; req->data = NULL; } @@ -1844,9 +1866,9 @@ static void uv__prepare(EV_P_ ev_prepare* w, int revents) { } -int uv_prepare_init(uv_prepare_t* prepare) { - uv__handle_init((uv_handle_t*)prepare, UV_PREPARE); - uv_counters()->prepare_init++; +int uv_prepare_init(uv_loop_t* loop, uv_prepare_t* prepare) { + uv__handle_init(loop, (uv_handle_t*)prepare, UV_PREPARE); + loop->counters.prepare_init++; ev_prepare_init(&prepare->prepare_watcher, uv__prepare); prepare->prepare_watcher.data = prepare; @@ -1862,10 +1884,10 @@ int uv_prepare_start(uv_prepare_t* prepare, uv_prepare_cb cb) { prepare->prepare_cb = cb; - ev_prepare_start(EV_DEFAULT_UC_ &prepare->prepare_watcher); + ev_prepare_start(prepare->loop->ev, &prepare->prepare_watcher); if (!was_active) { - ev_unref(EV_DEFAULT_UC); + ev_unref(prepare->loop->ev); } return 0; @@ -1875,10 +1897,10 @@ int uv_prepare_start(uv_prepare_t* prepare, uv_prepare_cb cb) { int uv_prepare_stop(uv_prepare_t* prepare) { int was_active = ev_is_active(&prepare->prepare_watcher); - ev_prepare_stop(EV_DEFAULT_UC_ &prepare->prepare_watcher); + ev_prepare_stop(prepare->loop->ev, &prepare->prepare_watcher); if (was_active) { - ev_ref(EV_DEFAULT_UC); + ev_ref(prepare->loop->ev); } return 0; } @@ -1894,9 +1916,9 @@ static void uv__check(EV_P_ ev_check* w, int revents) { } -int uv_check_init(uv_check_t* check) { - uv__handle_init((uv_handle_t*)check, UV_CHECK); - uv_counters()->check_init++; +int uv_check_init(uv_loop_t* loop, uv_check_t* check) { + uv__handle_init(loop, (uv_handle_t*)check, UV_CHECK); + loop->counters.check_init++; ev_check_init(&check->check_watcher, uv__check); check->check_watcher.data = check; @@ -1912,10 +1934,10 @@ int uv_check_start(uv_check_t* check, uv_check_cb cb) { check->check_cb = cb; - ev_check_start(EV_DEFAULT_UC_ &check->check_watcher); + ev_check_start(check->loop->ev, &check->check_watcher); if (!was_active) { - ev_unref(EV_DEFAULT_UC); + ev_unref(check->loop->ev); } return 0; @@ -1925,10 +1947,10 @@ int uv_check_start(uv_check_t* check, uv_check_cb cb) { int uv_check_stop(uv_check_t* check) { int was_active = ev_is_active(&check->check_watcher); - ev_check_stop(EV_DEFAULT_UC_ &check->check_watcher); + ev_check_stop(check->loop->ev, &check->check_watcher); if (was_active) { - ev_ref(EV_DEFAULT_UC); + ev_ref(check->loop->ev); } return 0; @@ -1945,9 +1967,9 @@ static void uv__idle(EV_P_ ev_idle* w, int revents) { -int uv_idle_init(uv_idle_t* idle) { - uv__handle_init((uv_handle_t*)idle, UV_IDLE); - uv_counters()->idle_init++; +int uv_idle_init(uv_loop_t* loop, uv_idle_t* idle) { + uv__handle_init(loop, (uv_handle_t*)idle, UV_IDLE); + loop->counters.idle_init++; ev_idle_init(&idle->idle_watcher, uv__idle); idle->idle_watcher.data = idle; @@ -1962,10 +1984,10 @@ int uv_idle_start(uv_idle_t* idle, uv_idle_cb cb) { int was_active = ev_is_active(&idle->idle_watcher); idle->idle_cb = cb; - ev_idle_start(EV_DEFAULT_UC_ &idle->idle_watcher); + ev_idle_start(idle->loop->ev, &idle->idle_watcher); if (!was_active) { - ev_unref(EV_DEFAULT_UC); + ev_unref(idle->loop->ev); } return 0; @@ -1975,10 +1997,10 @@ int uv_idle_start(uv_idle_t* idle, uv_idle_cb cb) { int uv_idle_stop(uv_idle_t* idle) { int was_active = ev_is_active(&idle->idle_watcher); - ev_idle_stop(EV_DEFAULT_UC_ &idle->idle_watcher); + ev_idle_stop(idle->loop->ev, &idle->idle_watcher); if (was_active) { - ev_ref(EV_DEFAULT_UC); + ev_ref(idle->loop->ev); } return 0; @@ -2014,9 +2036,9 @@ static void uv__async(EV_P_ ev_async* w, int revents) { } -int uv_async_init(uv_async_t* async, uv_async_cb async_cb) { - uv__handle_init((uv_handle_t*)async, UV_ASYNC); - uv_counters()->async_init++; +int uv_async_init(uv_loop_t* loop, uv_async_t* async, uv_async_cb async_cb) { + uv__handle_init(loop, (uv_handle_t*)async, UV_ASYNC); + loop->counters.async_init++; ev_async_init(&async->async_watcher, uv__async); async->async_watcher.data = async; @@ -2024,15 +2046,15 @@ int uv_async_init(uv_async_t* async, uv_async_cb async_cb) { async->async_cb = async_cb; /* Note: This does not have symmetry with the other libev wrappers. */ - ev_async_start(EV_DEFAULT_UC_ &async->async_watcher); - ev_unref(EV_DEFAULT_UC); + ev_async_start(loop->ev, &async->async_watcher); + ev_unref(loop->ev); return 0; } int uv_async_send(uv_async_t* async) { - ev_async_send(EV_DEFAULT_UC_ &async->async_watcher); + ev_async_send(async->loop->ev, &async->async_watcher); return 0; } @@ -2041,7 +2063,7 @@ static void uv__timer_cb(EV_P_ ev_timer* w, int revents) { uv_timer_t* timer = w->data; if (!ev_is_active(w)) { - ev_ref(EV_DEFAULT_UC); + ev_ref(EV_A); } if (timer->timer_cb) { @@ -2050,9 +2072,9 @@ static void uv__timer_cb(EV_P_ ev_timer* w, int revents) { } -int uv_timer_init(uv_timer_t* timer) { - uv__handle_init((uv_handle_t*)timer, UV_TIMER); - uv_counters()->timer_init++; +int uv_timer_init(uv_loop_t* loop, uv_timer_t* timer) { + uv__handle_init(loop, (uv_handle_t*)timer, UV_TIMER); + loop->counters.timer_init++; ev_init(&timer->timer_watcher, uv__timer_cb); timer->timer_watcher.data = timer; @@ -2069,29 +2091,29 @@ int uv_timer_start(uv_timer_t* timer, uv_timer_cb cb, int64_t timeout, timer->timer_cb = cb; ev_timer_set(&timer->timer_watcher, timeout / 1000.0, repeat / 1000.0); - ev_timer_start(EV_DEFAULT_UC_ &timer->timer_watcher); - ev_unref(EV_DEFAULT_UC); + ev_timer_start(timer->loop->ev, &timer->timer_watcher); + ev_unref(timer->loop->ev); return 0; } int uv_timer_stop(uv_timer_t* timer) { if (ev_is_active(&timer->timer_watcher)) { - ev_ref(EV_DEFAULT_UC); + ev_ref(timer->loop->ev); } - ev_timer_stop(EV_DEFAULT_UC_ &timer->timer_watcher); + ev_timer_stop(timer->loop->ev, &timer->timer_watcher); return 0; } int uv_timer_again(uv_timer_t* timer) { if (!ev_is_active(&timer->timer_watcher)) { - uv_err_new((uv_handle_t*)timer, EINVAL); + uv_err_new(timer->loop, EINVAL); return -1; } - ev_timer_again(EV_DEFAULT_UC_ &timer->timer_watcher); + ev_timer_again(timer->loop->ev, &timer->timer_watcher); return 0; } @@ -2107,23 +2129,28 @@ int64_t uv_timer_get_repeat(uv_timer_t* timer) { /* - * This is called once per second by ares_data.timer. It is used to + * This is called once per second by loop->timer. It is used to * constantly callback into c-ares for possibly processing timeouts. */ -static void uv__ares_timeout(EV_P_ struct ev_timer* watcher, int revents) { - assert(watcher == &ares_data.timer); +static void uv__ares_timeout(struct ev_loop* ev, struct ev_timer* watcher, + int revents) { + uv_loop_t* loop = container_of(ev, uv_loop_t, ev); + assert(watcher == &loop->timer); assert(revents == EV_TIMER); - assert(!uv_ares_handles_empty()); - ares_process_fd(ares_data.channel, ARES_SOCKET_BAD, ARES_SOCKET_BAD); + assert(!uv_ares_handles_empty(loop)); + ares_process_fd(loop->channel, ARES_SOCKET_BAD, ARES_SOCKET_BAD); } -static void uv__ares_io(EV_P_ struct ev_io* watcher, int revents) { +static void uv__ares_io(struct ev_loop* ev, struct ev_io* watcher, + int revents) { + uv_loop_t* loop = container_of(ev, uv_loop_t, ev); + /* Reset the idle timer */ - ev_timer_again(EV_A_ &ares_data.timer); + ev_timer_again(ev, &loop->timer); /* Process DNS responses */ - ares_process_fd(ares_data.channel, + ares_process_fd(loop->channel, revents & EV_READ ? watcher->fd : ARES_SOCKET_BAD, revents & EV_WRITE ? watcher->fd : ARES_SOCKET_BAD); } @@ -2152,32 +2179,35 @@ static uv_ares_task_t* uv__ares_task_create(int fd) { /* Callback from ares when socket operation is started */ static void uv__ares_sockstate_cb(void* data, ares_socket_t sock, int read, int write) { - uv_ares_task_t* h = uv_find_ares_handle(sock); + uv_loop_t* loop = data; + uv_ares_task_t* h; + + h = uv_find_ares_handle(loop, sock); if (read || write) { if (!h) { /* New socket */ /* If this is the first socket then start the timer. */ - if (!ev_is_active(&ares_data.timer)) { - assert(uv_ares_handles_empty()); - ev_timer_again(EV_DEFAULT_UC_ &ares_data.timer); + if (!ev_is_active(&loop->timer)) { + assert(uv_ares_handles_empty(loop)); + ev_timer_again(loop->ev, &loop->timer); } h = uv__ares_task_create(sock); - uv_add_ares_handle(h); + uv_add_ares_handle(loop, h); } if (read) { - ev_io_start(EV_DEFAULT_UC_ &h->read_watcher); + ev_io_start(loop->ev, &h->read_watcher); } else { - ev_io_stop(EV_DEFAULT_UC_ &h->read_watcher); + ev_io_stop(loop->ev, &h->read_watcher); } if (write) { - ev_io_start(EV_DEFAULT_UC_ &h->write_watcher); + ev_io_start(loop->ev, &h->write_watcher); } else { - ev_io_stop(EV_DEFAULT_UC_ &h->write_watcher); + ev_io_stop(loop->ev, &h->write_watcher); } } else { @@ -2188,14 +2218,14 @@ static void uv__ares_sockstate_cb(void* data, ares_socket_t sock, */ assert(h && "When an ares socket is closed we should have a handle for it"); - ev_io_stop(EV_DEFAULT_UC_ &h->read_watcher); - ev_io_stop(EV_DEFAULT_UC_ &h->write_watcher); + ev_io_stop(loop->ev, &h->read_watcher); + ev_io_stop(loop->ev, &h->write_watcher); uv_remove_ares_handle(h); free(h); - if (uv_ares_handles_empty()) { - ev_timer_stop(EV_DEFAULT_UC_ &ares_data.timer); + if (uv_ares_handles_empty(loop)) { + ev_timer_stop(loop->ev, &loop->timer); } } } @@ -2203,20 +2233,19 @@ static void uv__ares_sockstate_cb(void* data, ares_socket_t sock, /* c-ares integration initialize and terminate */ /* TODO: share this with windows? */ -int uv_ares_init_options(ares_channel *channelptr, - struct ares_options *options, - int optmask) { +int uv_ares_init_options(uv_loop_t* loop, ares_channel *channelptr, + struct ares_options *options, int optmask) { int rc; /* only allow single init at a time */ - if (ares_data.channel != NULL) { - uv_err_new_artificial(NULL, UV_EALREADY); + if (loop->channel != NULL) { + uv_err_new_artificial(loop, UV_EALREADY); return -1; } /* set our callback as an option */ options->sock_state_cb = uv__ares_sockstate_cb; - options->sock_state_cb_data = &ares_data; + options->sock_state_cb_data = loop; optmask |= ARES_OPT_SOCK_STATE_CB; /* We do the call to ares_init_option for caller. */ @@ -2224,27 +2253,27 @@ int uv_ares_init_options(ares_channel *channelptr, /* if success, save channel */ if (rc == ARES_SUCCESS) { - ares_data.channel = *channelptr; + loop->channel = *channelptr; } /* * Initialize the timeout timer. The timer won't be started until the * first socket is opened. */ - ev_init(&ares_data.timer, uv__ares_timeout); - ares_data.timer.repeat = 1.0; + ev_init(&loop->timer, uv__ares_timeout); + loop->timer.repeat = 1.0; return rc; } /* TODO share this with windows? */ -void uv_ares_destroy(ares_channel channel) { +void uv_ares_destroy(uv_loop_t* loop, ares_channel channel) { /* only allow destroy if did init */ - if (ares_data.channel != NULL) { - ev_timer_stop(EV_DEFAULT_UC_ &ares_data.timer); + if (loop->channel != NULL) { + ev_timer_stop(loop->ev, &loop->timer); ares_destroy(channel); - ares_data.channel = NULL; + loop->channel = NULL; } } @@ -2252,7 +2281,7 @@ void uv_ares_destroy(ares_channel channel) { static int uv_getaddrinfo_done(eio_req* req) { uv_getaddrinfo_t* handle = req->data; - uv_unref(); + uv_unref(handle->loop); free(handle->hints); free(handle->service); @@ -2260,7 +2289,7 @@ static int uv_getaddrinfo_done(eio_req* req) { if (handle->retcode != 0) { /* TODO how to display gai error strings? */ - uv_err_new(NULL, handle->retcode); + uv_err_new(handle->loop, handle->retcode); } handle->cb(handle, handle->retcode, handle->res); @@ -2283,17 +2312,18 @@ static void getaddrinfo_thread_proc(eio_req *req) { /* stub implementation of uv_getaddrinfo */ -int uv_getaddrinfo(uv_getaddrinfo_t* handle, +int uv_getaddrinfo(uv_loop_t* loop, + uv_getaddrinfo_t* handle, uv_getaddrinfo_cb cb, const char* hostname, const char* service, const struct addrinfo* hints) { eio_req* req; - uv_eio_init(); + uv_eio_init(loop); if (handle == NULL || cb == NULL || (hostname == NULL && service == NULL)) { - uv_err_new_artificial(NULL, UV_EINVAL); + uv_err_new_artificial(loop, UV_EINVAL); return -1; } @@ -2308,6 +2338,7 @@ int uv_getaddrinfo(uv_getaddrinfo_t* handle, /* TODO security! check lengths, check return values. */ + handle->loop = loop; handle->cb = cb; handle->hostname = hostname ? strdup(hostname) : NULL; handle->service = service ? strdup(service) : NULL; @@ -2315,7 +2346,7 @@ int uv_getaddrinfo(uv_getaddrinfo_t* handle, /* TODO check handle->hostname == NULL */ /* TODO check handle->service == NULL */ - uv_ref(); + uv_ref(loop); req = eio_custom(getaddrinfo_thread_proc, EIO_PRI_DEFAULT, uv_getaddrinfo_done, handle); @@ -2326,11 +2357,11 @@ int uv_getaddrinfo(uv_getaddrinfo_t* handle, } -int uv_pipe_init(uv_pipe_t* handle) { +int uv_pipe_init(uv_loop_t* loop, uv_pipe_t* handle) { memset(handle, 0, sizeof *handle); - uv__handle_init((uv_handle_t*)handle, UV_NAMED_PIPE); - uv_counters()->pipe_init++; + uv__handle_init(loop, (uv_handle_t*)handle, UV_NAMED_PIPE); + loop->counters.pipe_init++; handle->type = UV_NAMED_PIPE; handle->pipe_fname = NULL; /* Only set by listener. */ @@ -2365,13 +2396,13 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) { /* Already bound? */ if (handle->fd >= 0) { - uv_err_new_artificial((uv_handle_t*)handle, UV_EINVAL); + uv_err_new_artificial(handle->loop, UV_EINVAL); goto out; } /* Make a copy of the file name, it outlives this function's scope. */ if ((pipe_fname = strdup(name)) == NULL) { - uv_err_new((uv_handle_t*)handle, ENOMEM); + uv_err_new(handle->loop, ENOMEM); goto out; } @@ -2379,7 +2410,7 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) { name = NULL; if ((sockfd = uv__socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { - uv_err_new((uv_handle_t*)handle, errno); + uv_err_new(handle->loop, errno); goto out; } @@ -2400,7 +2431,7 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) { || unlink(pipe_fname) == -1 || bind(sockfd, (struct sockaddr*)&sun, sizeof sun) == -1) { /* Convert ENOENT to EACCES for compatibility with Windows. */ - uv_err_new((uv_handle_t*)handle, (errno == ENOENT) ? EACCES : errno); + uv_err_new(handle->loop, (errno == ENOENT) ? EACCES : errno); goto out; } } @@ -2437,17 +2468,17 @@ static int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) { status = -1; if (handle->fd == -1) { - uv_err_new_artificial((uv_handle_t*)handle, UV_EINVAL); + uv_err_new_artificial(handle->loop, UV_EINVAL); goto out; } assert(handle->fd >= 0); if ((status = listen(handle->fd, backlog)) == -1) { - uv_err_new((uv_handle_t*)handle, errno); + uv_err_new(handle->loop, errno); } else { handle->connection_cb = cb; ev_io_init(&handle->read_watcher, uv__pipe_accept, handle->fd, EV_READ); - ev_io_start(EV_DEFAULT_ &handle->read_watcher); + ev_io_start(handle->loop->ev, &handle->read_watcher); } out: @@ -2497,7 +2528,7 @@ int uv_pipe_connect(uv_connect_t* req, status = -1; if ((sockfd = uv__socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { - uv_err_new((uv_handle_t*)handle, errno); + uv_err_new(handle->loop, errno); goto out; } @@ -2514,15 +2545,15 @@ int uv_pipe_connect(uv_connect_t* req, while (r == -1 && errno == EINTR); if (r == -1) { - uv_err_new((uv_handle_t*)handle, errno); + uv_err_new(handle->loop, errno); uv__close(sockfd); goto out; } uv__stream_open((uv_stream_t*)handle, sockfd, UV_READABLE | UV_WRITABLE); - ev_io_start(EV_DEFAULT_ &handle->read_watcher); - ev_io_start(EV_DEFAULT_ &handle->write_watcher); + ev_io_start(handle->loop->ev, &handle->read_watcher); + ev_io_start(handle->loop->ev, &handle->write_watcher); status = 0; @@ -2535,7 +2566,7 @@ out: ngx_queue_init(&req->queue); /* Run callback on next tick. */ - ev_feed_event(EV_DEFAULT_ &handle->read_watcher, EV_CUSTOM); + ev_feed_event(handle->loop->ev, &handle->read_watcher, EV_CUSTOM); assert(ev_is_pending(&handle->read_watcher)); /* Mimic the Windows pipe implementation, always @@ -2564,14 +2595,14 @@ static void uv__pipe_accept(EV_P_ ev_io* watcher, int revents) { if (errno == EAGAIN || errno == EWOULDBLOCK) { assert(0 && "EAGAIN on uv__accept(pipefd)"); } else { - uv_err_new((uv_handle_t*)pipe, errno); + uv_err_new(pipe->loop, errno); } } else { pipe->accepted_fd = sockfd; pipe->connection_cb((uv_stream_t*)pipe, 0); if (pipe->accepted_fd == sockfd) { /* The user hasn't yet accepted called uv_accept() */ - ev_io_stop(EV_DEFAULT_ &pipe->read_watcher); + ev_io_stop(pipe->loop->ev, &pipe->read_watcher); } } @@ -2702,7 +2733,7 @@ size_t uv__strlcpy(char* dst, const char* src, size_t size) { } -uv_stream_t* uv_std_handle(uv_std_type type) { +uv_stream_t* uv_std_handle(uv_loop_t* loop, uv_std_type type) { assert(0 && "implement me"); return NULL; } @@ -2736,7 +2767,8 @@ static void uv__chld(EV_P_ ev_child* watcher, int revents) { # define SPAWN_WAIT_EXEC 1 #endif -int uv_spawn(uv_process_t* process, uv_process_options_t options) { +int uv_spawn(uv_loop_t* loop, uv_process_t* process, + uv_process_options_t options) { /* * Save environ in the case that we get it clobbered * by the child process. @@ -2752,8 +2784,8 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) { int status; pid_t pid; - uv__handle_init((uv_handle_t*)process, UV_PROCESS); - uv_counters()->process_init++; + uv__handle_init(loop, (uv_handle_t*)process, UV_PROCESS); + loop->counters.process_init++; process->exit_cb = options.exit_cb; @@ -2900,7 +2932,7 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) { process->pid = pid; ev_child_init(&process->child_watcher, uv__chld, pid, 0); - ev_child_start(EV_DEFAULT_UC_ &process->child_watcher); + ev_child_start(process->loop->ev, &process->child_watcher); process->child_watcher.data = process; if (stdin_pipe[1] >= 0) { @@ -2933,7 +2965,7 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) { return 0; error: - uv_err_new((uv_handle_t*)process, errno); + uv_err_new(process->loop, errno); uv__close(stdin_pipe[0]); uv__close(stdin_pipe[1]); uv__close(stdout_pipe[0]); @@ -2948,7 +2980,7 @@ int uv_process_kill(uv_process_t* process, int signum) { int r = kill(process->pid, signum); if (r) { - uv_err_new((uv_handle_t*)process, errno); + uv_err_new(process->loop, errno); return -1; } else { return 0; diff --git a/test/benchmark-ares.c b/test/benchmark-ares.c index d4d88e03..0023f5c5 100644 --- a/test/benchmark-ares.c +++ b/test/benchmark-ares.c @@ -84,7 +84,7 @@ BENCHMARK_IMPL(gethostbyname) { return 1; } - uv_init(); + ares_callbacks = 0; ares_errors = 0; diff --git a/test/benchmark-getaddrinfo.c b/test/benchmark-getaddrinfo.c index 00366e61..d7f294c3 100644 --- a/test/benchmark-getaddrinfo.c +++ b/test/benchmark-getaddrinfo.c @@ -66,7 +66,7 @@ static void getaddrinfo_initiate(uv_getaddrinfo_t* handle) { BENCHMARK_IMPL(getaddrinfo) { int i; - uv_init(); + uv_update_time(); start_time = uv_now(); diff --git a/test/benchmark-ping-pongs.c b/test/benchmark-ping-pongs.c index 80567239..6509f56b 100644 --- a/test/benchmark-ping-pongs.c +++ b/test/benchmark-ping-pongs.c @@ -198,7 +198,7 @@ static void pinger_new() { BENCHMARK_IMPL(ping_pongs) { - uv_init(); + start_time = uv_now(); pinger_new(); diff --git a/test/benchmark-pound.c b/test/benchmark-pound.c index bae5e46f..9a3a8e3c 100644 --- a/test/benchmark-pound.c +++ b/test/benchmark-pound.c @@ -275,7 +275,7 @@ static int pound_it(int concurrency, uint64_t start_time; /* in ns */ uint64_t end_time; - uv_init(); + uv_update_time(); start = uv_now(); diff --git a/test/benchmark-pump.c b/test/benchmark-pump.c index 7713a585..5de9f017 100644 --- a/test/benchmark-pump.c +++ b/test/benchmark-pump.c @@ -366,7 +366,7 @@ HELPER_IMPL(tcp_pump_server) { int r; type = TCP; - uv_init(); + listen_addr = uv_ip4_addr("0.0.0.0", TEST_PORT); /* Server */ @@ -388,7 +388,7 @@ HELPER_IMPL(pipe_pump_server) { int r; type = PIPE; - uv_init(); + /* Server */ server = (uv_stream_t*)&pipeServer; @@ -410,7 +410,7 @@ void tcp_pump(int n) { TARGET_CONNECTIONS = n; type = TCP; - uv_init(); + connect_addr = uv_ip4_addr("127.0.0.1", TEST_PORT); @@ -426,7 +426,7 @@ void pipe_pump(int n) { TARGET_CONNECTIONS = n; type = PIPE; - uv_init(); + /* Start making connections */ maybe_connect_some(); diff --git a/test/benchmark-spawn.c b/test/benchmark-spawn.c index 46ddca0e..61c29a66 100644 --- a/test/benchmark-spawn.c +++ b/test/benchmark-spawn.c @@ -130,7 +130,7 @@ BENCHMARK_IMPL(spawn) { int r; static int64_t start_time, end_time; - uv_init(); + r = uv_exepath(exepath, &exepath_size); ASSERT(r == 0); diff --git a/test/dns-server.c b/test/dns-server.c index 2e4a8f39..a0655097 100644 --- a/test/dns-server.c +++ b/test/dns-server.c @@ -314,7 +314,7 @@ static int dns_start(int port) { HELPER_IMPL(dns_server) { - uv_init(); + if (dns_start(TEST_PORT_2)) return 1; diff --git a/test/echo-server.c b/test/echo-server.c index 270af378..9f67adcb 100644 --- a/test/echo-server.c +++ b/test/echo-server.c @@ -46,7 +46,7 @@ static void after_write(uv_write_t* req, int status) { write_req_t* wr; if (status) { - uv_err_t err = uv_last_error(); + uv_err_t err = uv_last_error(uv_default_loop()); fprintf(stderr, "uv_write error: %s\n", uv_strerror(err)); ASSERT(0); } @@ -72,7 +72,7 @@ static void after_read(uv_stream_t* handle, ssize_t nread, uv_buf_t buf) { if (nread < 0) { /* Error or EOF */ - ASSERT (uv_last_error().code == UV_EOF); + ASSERT (uv_last_error(uv_default_loop()).code == UV_EOF); if (buf.base) { free(buf.base); @@ -133,7 +133,8 @@ static void on_connection(uv_stream_t* server, int status) { int r; if (status != 0) { - fprintf(stderr, "Connect error %d\n", uv_last_error().code); + fprintf(stderr, "Connect error %d\n", + uv_last_error(uv_default_loop()).code); } ASSERT(status == 0); @@ -141,13 +142,13 @@ static void on_connection(uv_stream_t* server, int status) { case TCP: stream = malloc(sizeof(uv_tcp_t)); ASSERT(stream != NULL); - uv_tcp_init((uv_tcp_t*)stream); + uv_tcp_init(uv_default_loop(), (uv_tcp_t*)stream); break; case PIPE: stream = malloc(sizeof(uv_pipe_t)); ASSERT(stream != NULL); - uv_pipe_init((uv_pipe_t*)stream); + uv_pipe_init(uv_default_loop(), (uv_pipe_t*)stream); break; default: @@ -178,7 +179,7 @@ static int tcp4_echo_start(int port) { server = (uv_handle_t*)&tcpServer; serverType = TCP; - r = uv_tcp_init(&tcpServer); + r = uv_tcp_init(uv_default_loop(), &tcpServer); if (r) { /* TODO: Error codes */ fprintf(stderr, "Socket creation error\n"); @@ -195,7 +196,8 @@ static int tcp4_echo_start(int port) { r = uv_listen((uv_stream_t*)&tcpServer, SOMAXCONN, on_connection); if (r) { /* TODO: Error codes */ - fprintf(stderr, "Listen error %s\n", uv_err_name(uv_last_error())); + fprintf(stderr, "Listen error %s\n", + uv_err_name(uv_last_error(uv_default_loop()))); return 1; } @@ -210,7 +212,7 @@ static int tcp6_echo_start(int port) { server = (uv_handle_t*)&tcpServer; serverType = TCP; - r = uv_tcp_init(&tcpServer); + r = uv_tcp_init(uv_default_loop(), &tcpServer); if (r) { /* TODO: Error codes */ fprintf(stderr, "Socket creation error\n"); @@ -242,21 +244,24 @@ static int pipe_echo_start(char* pipeName) { server = (uv_handle_t*)&pipeServer; serverType = PIPE; - r = uv_pipe_init(&pipeServer); + r = uv_pipe_init(uv_default_loop(), &pipeServer); if (r) { - fprintf(stderr, "uv_pipe_init: %s\n", uv_strerror(uv_last_error())); + fprintf(stderr, "uv_pipe_init: %s\n", + uv_strerror(uv_last_error(uv_default_loop()))); return 1; } r = uv_pipe_bind(&pipeServer, pipeName); if (r) { - fprintf(stderr, "uv_pipe_bind: %s\n", uv_strerror(uv_last_error())); + fprintf(stderr, "uv_pipe_bind: %s\n", + uv_strerror(uv_last_error(uv_default_loop()))); return 1; } r = uv_listen((uv_stream_t*)&pipeServer, SOMAXCONN, on_connection); if (r) { - fprintf(stderr, "uv_pipe_listen: %s\n", uv_strerror(uv_last_error())); + fprintf(stderr, "uv_pipe_listen: %s\n", + uv_strerror(uv_last_error(uv_default_loop()))); return 1; } @@ -265,31 +270,33 @@ static int pipe_echo_start(char* pipeName) { HELPER_IMPL(tcp4_echo_server) { - uv_init(); + uv_loop_t* loop = uv_default_loop(); + if (tcp4_echo_start(TEST_PORT)) return 1; - uv_run(); + uv_run(loop); return 0; } HELPER_IMPL(tcp6_echo_server) { - uv_init(); + uv_loop_t* loop = uv_default_loop(); + if (tcp6_echo_start(TEST_PORT)) return 1; - uv_run(); + uv_run(loop); return 0; } HELPER_IMPL(pipe_echo_server) { - uv_init(); + uv_loop_t* loop = uv_default_loop(); if (pipe_echo_start(TEST_PIPENAME)) return 1; - uv_run(); + uv_run(loop); return 0; } diff --git a/test/test-async.c b/test/test-async.c index 2a3a1bfa..3d841518 100644 --- a/test/test-async.c +++ b/test/test-async.c @@ -182,14 +182,12 @@ static void prepare_cb(uv_prepare_t* handle, int status) { TEST_IMPL(async) { int r; - uv_init(); - - r = uv_prepare_init(&prepare_handle); + r = uv_prepare_init(uv_default_loop(), &prepare_handle); ASSERT(r == 0); r = uv_prepare_start(&prepare_handle, prepare_cb); ASSERT(r == 0); - r = uv_async_init(&async1_handle, async1_cb); + r = uv_async_init(uv_default_loop(), &async1_handle, async1_cb); ASSERT(r == 0); #if 0 @@ -197,7 +195,7 @@ TEST_IMPL(async) { ASSERT(r == 0); #endif - r = uv_run(); + r = uv_run(uv_default_loop()); ASSERT(r == 0); r = uv_wait_thread(thread1_id); diff --git a/test/test-callback-stack.c b/test/test-callback-stack.c index 64cc4d9e..4af63648 100644 --- a/test/test-callback-stack.c +++ b/test/test-callback-stack.c @@ -76,11 +76,11 @@ static void read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { free(buf.base); if (nread == 0) { - ASSERT(uv_last_error().code == UV_EAGAIN); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EAGAIN); return; } else if (nread == -1) { - ASSERT(uv_last_error().code == UV_EOF); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EOF); nested++; uv_close((uv_handle_t*)tcp, close_cb); @@ -140,7 +140,7 @@ static void write_cb(uv_write_t* req, int status) { /* back to our receive buffer when we start reading. This maximizes the */ /* tempation for the backend to use dirty stack for calling read_cb. */ nested++; - r = uv_timer_init(&timer); + r = uv_timer_init(uv_default_loop(), &timer); ASSERT(r == 0); r = uv_timer_start(&timer, timer_cb, 500, 0); ASSERT(r == 0); @@ -176,9 +176,7 @@ static void connect_cb(uv_connect_t* req, int status) { TEST_IMPL(callback_stack) { struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT); - uv_init(); - - if (uv_tcp_init(&client)) { + if (uv_tcp_init(uv_default_loop(), &client)) { FATAL("uv_tcp_init failed"); } @@ -191,7 +189,7 @@ TEST_IMPL(callback_stack) { } nested--; - uv_run(); + uv_run(uv_default_loop()); ASSERT(nested == 0); ASSERT(connect_cb_called == 1 && "connect_cb must be called exactly once"); diff --git a/test/test-connection-fail.c b/test/test-connection-fail.c index 1c2d2121..203049e0 100644 --- a/test/test-connection-fail.c +++ b/test/test-connection-fail.c @@ -69,7 +69,7 @@ static void timer_cb(uv_timer_t* handle, int status) { static void on_connect_with_close(uv_connect_t *req, int status) { ASSERT((uv_stream_t*) &tcp == req->handle); ASSERT(status == -1); - ASSERT(uv_last_error().code == UV_ECONNREFUSED); + ASSERT(uv_last_error(uv_default_loop()).code == UV_ECONNREFUSED); connect_cb_calls++; ASSERT(close_cb_calls == 0); @@ -79,7 +79,7 @@ static void on_connect_with_close(uv_connect_t *req, int status) { static void on_connect_without_close(uv_connect_t *req, int status) { ASSERT(status == -1); - ASSERT(uv_last_error().code == UV_ECONNREFUSED); + ASSERT(uv_last_error(uv_default_loop()).code == UV_ECONNREFUSED); connect_cb_calls++; uv_timer_start(&timer, timer_cb, 100, 0); @@ -98,7 +98,7 @@ void connection_fail(uv_connect_cb connect_cb) { server_addr = uv_ip4_addr("127.0.0.1", TEST_PORT); /* Try to connec to the server and do NUM_PINGS ping-pongs. */ - r = uv_tcp_init(&tcp); + r = uv_tcp_init(uv_default_loop(), &tcp); ASSERT(!r); /* We are never doing multiple reads/connects at a time anyway. */ @@ -107,7 +107,7 @@ void connection_fail(uv_connect_cb connect_cb) { r = uv_tcp_connect(&req, &tcp, server_addr, connect_cb); ASSERT(!r); - uv_run(); + uv_run(uv_default_loop()); ASSERT(connect_cb_calls == 1); ASSERT(close_cb_calls == 1); @@ -119,7 +119,7 @@ void connection_fail(uv_connect_cb connect_cb) { * expect an error. */ TEST_IMPL(connection_fail) { - uv_init(); + connection_fail(on_connect_with_close); @@ -136,9 +136,9 @@ TEST_IMPL(connection_fail) { * attempt. */ TEST_IMPL(connection_fail_doesnt_auto_close) { - uv_init(); - uv_timer_init(&timer); + + uv_timer_init(uv_default_loop(), &timer); connection_fail(on_connect_without_close); diff --git a/test/test-delayed-accept.c b/test/test-delayed-accept.c index 5a2704d4..8ef76de6 100644 --- a/test/test-delayed-accept.c +++ b/test/test-delayed-accept.c @@ -57,16 +57,16 @@ static void do_accept(uv_timer_t* timer_handle, int status) { ASSERT(status == 0); ASSERT(accepted_handle != NULL); - uv_tcp_init(accepted_handle); + uv_tcp_init(uv_default_loop(), accepted_handle); - /* Test to that uv_counters()->tcp_init does not increase across the uv_accept. */ - tcpcnt = uv_counters()->tcp_init; + /* Test to that uv_default_loop()->counters.tcp_init does not increase across the uv_accept. */ + tcpcnt = uv_default_loop()->counters.tcp_init; server = (uv_tcp_t*)timer_handle->data; r = uv_accept((uv_stream_t*)server, (uv_stream_t*)accepted_handle); ASSERT(r == 0); - ASSERT(uv_counters()->tcp_init == tcpcnt); + ASSERT(uv_default_loop()->counters.tcp_init == tcpcnt); do_accept_called++; @@ -93,7 +93,7 @@ static void connection_cb(uv_stream_t* tcp, int status) { ASSERT(timer_handle != NULL); /* Accept the client after 1 second */ - r = uv_timer_init(timer_handle); + r = uv_timer_init(uv_default_loop(), timer_handle); ASSERT(r == 0); timer_handle->data = tcp; @@ -112,10 +112,10 @@ static void start_server() { ASSERT(server != NULL); - r = uv_tcp_init(server); + r = uv_tcp_init(uv_default_loop(), server); ASSERT(r == 0); - ASSERT(uv_counters()->tcp_init == 1); - ASSERT(uv_counters()->handle_init == 1); + ASSERT(uv_default_loop()->counters.tcp_init == 1); + ASSERT(uv_default_loop()->counters.handle_init == 1); r = uv_tcp_bind(server, addr); ASSERT(r == 0); @@ -134,11 +134,11 @@ static void read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { if (nread != -1) { ASSERT(nread == 0); - ASSERT(uv_last_error().code == UV_EAGAIN); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EAGAIN); } else { ASSERT(tcp != NULL); ASSERT(nread == -1); - ASSERT(uv_last_error().code == UV_EOF); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EOF); uv_close((uv_handle_t*)tcp, close_cb); } } @@ -170,7 +170,7 @@ static void client_connect() { ASSERT(client != NULL); ASSERT(connect_req != NULL); - r = uv_tcp_init(client); + r = uv_tcp_init(uv_default_loop(), client); ASSERT(r == 0); r = uv_tcp_connect(connect_req, client, addr, connect_cb); @@ -180,14 +180,14 @@ static void client_connect() { TEST_IMPL(delayed_accept) { - uv_init(); + start_server(); client_connect(); client_connect(); - uv_run(); + uv_run(uv_default_loop()); ASSERT(connection_cb_called == 2); ASSERT(do_accept_called == 2); diff --git a/test/test-getaddrinfo.c b/test/test-getaddrinfo.c index a33e3d07..0c803a49 100644 --- a/test/test-getaddrinfo.c +++ b/test/test-getaddrinfo.c @@ -67,16 +67,17 @@ static void getaddrinfo_cuncurrent_cb(uv_getaddrinfo_t* handle, TEST_IMPL(getaddrinfo_basic) { int r; - uv_init(); - r = uv_getaddrinfo(&getaddrinfo_handle, + + r = uv_getaddrinfo(uv_default_loop(), + &getaddrinfo_handle, &getaddrinfo_basic_cb, name, NULL, NULL); ASSERT(r == 0); - uv_run(); + uv_run(uv_default_loop()); ASSERT(getaddrinfo_cbs == 1); @@ -87,20 +88,21 @@ TEST_IMPL(getaddrinfo_basic) { TEST_IMPL(getaddrinfo_concurrent) { int i, r; - uv_init(); + for (i = 0; i < CONCURRENT_COUNT; i++) { callback_counts[i] = 0; - r = uv_getaddrinfo(&getaddrinfo_handles[i], - &getaddrinfo_cuncurrent_cb, - name, - NULL, - NULL); + r = uv_getaddrinfo(uv_default_loop(), + &getaddrinfo_handles[i], + &getaddrinfo_cuncurrent_cb, + name, + NULL, + NULL); ASSERT(r == 0); } - uv_run(); + uv_run(uv_default_loop()); for (i = 0; i < CONCURRENT_COUNT; i++) { ASSERT(callback_counts[i] == 1); diff --git a/test/test-gethostbyname.c b/test/test-gethostbyname.c index cbd25343..10bcca13 100644 --- a/test/test-gethostbyname.c +++ b/test/test-gethostbyname.c @@ -74,7 +74,7 @@ static void prep_tcploopback() { options.tcp_port = htons(TEST_PORT); options.flags = ARES_FLAG_USEVC; - rc = uv_ares_init_options(&channel, &options, optmask); + rc = uv_ares_init_options(uv_default_loop(), &channel, &options, optmask); ASSERT(rc == ARES_SUCCESS); } @@ -91,7 +91,7 @@ TEST_IMPL(gethostbyname) { return 1; } - uv_init(); + printf("Start basic gethostbyname test\n"); prep_tcploopback(); @@ -104,11 +104,11 @@ TEST_IMPL(gethostbyname) { AF_INET, &aresbynamecallback, &bynamecallbacksig); - uv_run(); + uv_run(uv_default_loop()); ASSERT(ares_bynamecallbacks == 1); - uv_ares_destroy(channel); + uv_ares_destroy(uv_default_loop(), channel); printf("Done basic gethostbyname test\n"); @@ -125,7 +125,7 @@ TEST_IMPL(gethostbyname) { AF_INET, &aresbynamecallback, &bynamecallbacksig); - uv_run(); + uv_run(uv_default_loop()); ASSERT(ares_bynamecallbacks == 1); @@ -143,11 +143,11 @@ TEST_IMPL(gethostbyname) { &aresbyaddrcallback, &byaddrcallbacksig); - uv_run(); + uv_run(uv_default_loop()); ASSERT(ares_byaddrcallbacks == 1); - uv_ares_destroy(channel); + uv_ares_destroy(uv_default_loop(), channel); printf("Done gethostbyname and gethostbyaddr sequential test\n"); @@ -179,13 +179,13 @@ TEST_IMPL(gethostbyname) { &aresbyaddrcallback, &byaddrcallbacksig); - uv_run(); + uv_run(uv_default_loop()); ASSERT(ares_bynamecallbacks == 1); ASSERT(ares_byaddrcallbacks == 1); - uv_ares_destroy(channel); + uv_ares_destroy(uv_default_loop(), channel); printf("Done gethostbyname and gethostbyaddr concurrent test\n"); return 0; diff --git a/test/test-getsockname.c b/test/test-getsockname.c index c1fa8215..299d8b3b 100644 --- a/test/test-getsockname.c +++ b/test/test-getsockname.c @@ -78,14 +78,15 @@ static void on_connection(uv_stream_t* server, int status) { int r; if (status != 0) { - fprintf(stderr, "Connect error %d\n", uv_last_error().code); + fprintf(stderr, "Connect error %d\n", + uv_last_error(uv_default_loop()).code); } ASSERT(status == 0); handle = (uv_handle_t*) malloc(sizeof(uv_tcp_t)); ASSERT(handle != NULL); - uv_tcp_init((uv_tcp_t*)handle); + uv_tcp_init(uv_default_loop(), (uv_tcp_t*)handle); /* associate server with stream */ handle->data = server; @@ -95,7 +96,8 @@ static void on_connection(uv_stream_t* server, int status) { status = uv_getsockname(handle, &sockname, &namelen); if (status != 0) { - fprintf(stderr, "uv_getsockname error (accepted) %d\n", uv_last_error().code); + fprintf(stderr, "uv_getsockname error (accepted) %d\n", + uv_last_error(uv_default_loop()).code); } ASSERT(status == 0); @@ -115,7 +117,8 @@ static void on_connect(uv_connect_t* req, int status) { r = uv_getsockname((uv_handle_t*)&tcp, &sockname, &namelen); if (r != 0) { - fprintf(stderr, "uv_getsockname error (connector) %d\n", uv_last_error().code); + fprintf(stderr, "uv_getsockname error (connector) %d\n", + uv_last_error(uv_default_loop()).code); } ASSERT(r == 0); @@ -132,7 +135,7 @@ static int tcp_listener(int port) { char ip[20]; int r; - r = uv_tcp_init(&tcpServer); + r = uv_tcp_init(uv_default_loop(), &tcpServer); if (r) { fprintf(stderr, "Socket creation error\n"); return 1; @@ -154,7 +157,8 @@ static int tcp_listener(int port) { r = uv_getsockname((uv_handle_t*)&tcpServer, &sockname, &namelen); if (r != 0) { - fprintf(stderr, "uv_getsockname error (listening) %d\n", uv_last_error().code); + fprintf(stderr, "uv_getsockname error (listening) %d\n", + uv_last_error(uv_default_loop()).code); } ASSERT(r == 0); @@ -175,7 +179,7 @@ static void tcp_connector() { int r; struct sockaddr_in server_addr = uv_ip4_addr("127.0.0.1", TEST_PORT); - r = uv_tcp_init(&tcp); + r = uv_tcp_init(uv_default_loop(), &tcp); tcp.data = &connect_req; ASSERT(!r); @@ -284,14 +288,14 @@ static void udp_sender(void) { TEST_IMPL(getsockname_tcp) { - uv_init(); + if (tcp_listener(TEST_PORT)) return 1; tcp_connector(); - uv_run(); + uv_run(uv_default_loop()); ASSERT(getsocknamecount == 3); @@ -312,4 +316,4 @@ TEST_IMPL(getsockname_udp) { ASSERT(getsocknamecount == 2); return 0; -} +} \ No newline at end of file diff --git a/test/test-idle.c b/test/test-idle.c index 46917d04..3e7b8f11 100644 --- a/test/test-idle.c +++ b/test/test-idle.c @@ -60,19 +60,19 @@ static void idle_cb(uv_idle_t* handle, int status) { TEST_IMPL(idle_starvation) { int r; - uv_init(); - r = uv_idle_init(&idle_handle); + + r = uv_idle_init(uv_default_loop(), &idle_handle); ASSERT(r == 0); r = uv_idle_start(&idle_handle, idle_cb); ASSERT(r == 0); - r = uv_timer_init(&timer_handle); + r = uv_timer_init(uv_default_loop(), &timer_handle); ASSERT(r == 0); r = uv_timer_start(&timer_handle, timer_cb, 50, 0); ASSERT(r == 0); - r = uv_run(); + r = uv_run(uv_default_loop()); ASSERT(r == 0); ASSERT(idle_cb_called > 0); diff --git a/test/test-loop-handles.c b/test/test-loop-handles.c index 8db6c8c1..fd8d591c 100644 --- a/test/test-loop-handles.c +++ b/test/test-loop-handles.c @@ -153,7 +153,7 @@ static void idle_1_cb(uv_idle_t* handle, int status) { /* Init idle_2 and make it active */ if (!idle_2_is_active) { - r = uv_idle_init(&idle_2_handle); + r = uv_idle_init(uv_default_loop(), &idle_2_handle); ASSERT(r == 0); r = uv_idle_start(&idle_2_handle, idle_2_cb); ASSERT(r == 0); @@ -299,25 +299,25 @@ TEST_IMPL(loop_handles) { int i; int r; - uv_init(); - r = uv_prepare_init(&prepare_1_handle); + + r = uv_prepare_init(uv_default_loop(), &prepare_1_handle); ASSERT(r == 0); r = uv_prepare_start(&prepare_1_handle, prepare_1_cb); ASSERT(r == 0); - r = uv_check_init(&check_handle); + r = uv_check_init(uv_default_loop(), &check_handle); ASSERT(r == 0); r = uv_check_start(&check_handle, check_cb); ASSERT(r == 0); /* initialize only, prepare_2 is started by prepare_1_cb */ - r = uv_prepare_init(&prepare_2_handle); + r = uv_prepare_init(uv_default_loop(), &prepare_2_handle); ASSERT(r == 0); for (i = 0; i < IDLE_COUNT; i++) { /* initialize only, idle_1 handles are started by check_cb */ - r = uv_idle_init(&idle_1_handles[i]); + r = uv_idle_init(uv_default_loop(), &idle_1_handles[i]); ASSERT(r == 0); } @@ -325,13 +325,13 @@ TEST_IMPL(loop_handles) { /* the timer callback is there to keep the event loop polling */ /* unref it as it is not supposed to keep the loop alive */ - r = uv_timer_init(&timer_handle); + r = uv_timer_init(uv_default_loop(), &timer_handle); ASSERT(r == 0); r = uv_timer_start(&timer_handle, timer_cb, TIMEOUT, TIMEOUT); ASSERT(r == 0); - uv_unref(); + uv_unref(uv_default_loop()); - r = uv_run(); + r = uv_run(uv_default_loop()); ASSERT(r == 0); ASSERT(loop_iteration == ITERATIONS); diff --git a/test/test-ping-pong.c b/test/test-ping-pong.c index e9af29ae..b2aa8fbd 100644 --- a/test/test-ping-pong.c +++ b/test/test-ping-pong.c @@ -100,7 +100,7 @@ static void pinger_read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf) { pinger = (pinger_t*)stream->data; if (nread < 0) { - ASSERT(uv_last_error().code == UV_EOF); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EOF); puts("got EOF"); @@ -155,7 +155,7 @@ static void tcp_pinger_v6_new() { pinger->pongs = 0; /* Try to connec to the server and do NUM_PINGS ping-pongs. */ - r = uv_tcp_init(&pinger->tcp); + r = uv_tcp_init(uv_default_loop(), &pinger->tcp); pinger->tcp.data = pinger; ASSERT(!r); @@ -180,7 +180,7 @@ static void tcp_pinger_new() { pinger->pongs = 0; /* Try to connec to the server and do NUM_PINGS ping-pongs. */ - r = uv_tcp_init(&pinger->tcp); + r = uv_tcp_init(uv_default_loop(), &pinger->tcp); pinger->tcp.data = pinger; ASSERT(!r); @@ -204,7 +204,7 @@ static void pipe_pinger_new() { pinger->pongs = 0; /* Try to connec to the server and do NUM_PINGS ping-pongs. */ - r = uv_pipe_init(&pinger->pipe); + r = uv_pipe_init(uv_default_loop(), &pinger->pipe); pinger->pipe.data = pinger; ASSERT(!r); @@ -221,10 +221,10 @@ static void pipe_pinger_new() { TEST_IMPL(tcp_ping_pong) { - uv_init(); + tcp_pinger_new(); - uv_run(); + uv_run(uv_default_loop()); ASSERT(completed_pingers == 1); @@ -233,10 +233,10 @@ TEST_IMPL(tcp_ping_pong) { TEST_IMPL(tcp_ping_pong_v6) { - uv_init(); + tcp_pinger_v6_new(); - uv_run(); + uv_run(uv_default_loop()); ASSERT(completed_pingers == 1); @@ -245,10 +245,10 @@ TEST_IMPL(tcp_ping_pong_v6) { TEST_IMPL(pipe_ping_pong) { - uv_init(); + pipe_pinger_new(); - uv_run(); + uv_run(uv_default_loop()); ASSERT(completed_pingers == 1); diff --git a/test/test-pipe-bind-error.c b/test/test-pipe-bind-error.c index 80c76da8..e9b946b9 100644 --- a/test/test-pipe-bind-error.c +++ b/test/test-pipe-bind-error.c @@ -45,31 +45,31 @@ TEST_IMPL(pipe_bind_error_addrinuse) { uv_pipe_t server1, server2; int r; - uv_init(); - r = uv_pipe_init(&server1); + + r = uv_pipe_init(uv_default_loop(), &server1); ASSERT(r == 0); r = uv_pipe_bind(&server1, TEST_PIPENAME); ASSERT(r == 0); - r = uv_pipe_init(&server2); + r = uv_pipe_init(uv_default_loop(), &server2); ASSERT(r == 0); r = uv_pipe_bind(&server2, TEST_PIPENAME); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EADDRINUSE); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRINUSE); r = uv_listen((uv_stream_t*)&server1, SOMAXCONN, NULL); ASSERT(r == 0); r = uv_listen((uv_stream_t*)&server2, SOMAXCONN, NULL); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EINVAL); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL); uv_close((uv_handle_t*)&server1, close_cb); uv_close((uv_handle_t*)&server2, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 2); @@ -81,18 +81,18 @@ TEST_IMPL(pipe_bind_error_addrnotavail) { uv_pipe_t server; int r; - uv_init(); - r = uv_pipe_init(&server); + + r = uv_pipe_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_pipe_bind(&server, BAD_PIPENAME); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EACCESS); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EACCESS); uv_close((uv_handle_t*)&server, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 1); @@ -104,20 +104,20 @@ TEST_IMPL(pipe_bind_error_inval) { uv_pipe_t server; int r; - uv_init(); - r = uv_pipe_init(&server); + + r = uv_pipe_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_pipe_bind(&server, TEST_PIPENAME); ASSERT(r == 0); r = uv_pipe_bind(&server, TEST_PIPENAME_2); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EINVAL); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL); uv_close((uv_handle_t*)&server, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 1); @@ -129,18 +129,18 @@ TEST_IMPL(pipe_listen_without_bind) { uv_pipe_t server; int r; - uv_init(); - r = uv_pipe_init(&server); + + r = uv_pipe_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_listen((uv_stream_t*)&server, SOMAXCONN, NULL); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EINVAL); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL); uv_close((uv_handle_t*)&server, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 1); diff --git a/test/test-ref.c b/test/test-ref.c index d61b3a6f..e3d37d8d 100644 --- a/test/test-ref.c +++ b/test/test-ref.c @@ -24,51 +24,46 @@ TEST_IMPL(ref) { - uv_init(); - uv_run(); + uv_run(uv_default_loop()); return 0; } TEST_IMPL(idle_ref) { uv_idle_t h; - uv_init(); - uv_idle_init(&h); + uv_idle_init(uv_default_loop(), &h); uv_idle_start(&h, NULL); - uv_unref(); - uv_run(); + uv_unref(uv_default_loop()); + uv_run(uv_default_loop()); return 0; } TEST_IMPL(async_ref) { uv_async_t h; - uv_init(); - uv_async_init(&h, NULL); - uv_unref(); - uv_run(); + uv_async_init(uv_default_loop(), &h, NULL); + uv_unref(uv_default_loop()); + uv_run(uv_default_loop()); return 0; } TEST_IMPL(prepare_ref) { uv_prepare_t h; - uv_init(); - uv_prepare_init(&h); + uv_prepare_init(uv_default_loop(), &h); uv_prepare_start(&h, NULL); - uv_unref(); - uv_run(); + uv_unref(uv_default_loop()); + uv_run(uv_default_loop()); return 0; } TEST_IMPL(check_ref) { uv_check_t h; - uv_init(); - uv_check_init(&h); + uv_check_init(uv_default_loop(), &h); uv_check_start(&h, NULL); - uv_unref(); - uv_run(); + uv_unref(uv_default_loop()); + uv_run(uv_default_loop()); return 0; } @@ -77,15 +72,15 @@ static void prepare_cb(uv_prepare_t* handle, int status) { ASSERT(handle != NULL); ASSERT(status == 0); - uv_unref(); + uv_unref(uv_default_loop()); } TEST_IMPL(unref_in_prepare_cb) { uv_prepare_t h; - uv_init(); - uv_prepare_init(&h); + + uv_prepare_init(uv_default_loop(), &h); uv_prepare_start(&h, prepare_cb); - uv_run(); + uv_run(uv_default_loop()); return 0; } diff --git a/test/test-shutdown-eof.c b/test/test-shutdown-eof.c index cb57ad1e..2e49d538 100644 --- a/test/test-shutdown-eof.c +++ b/test/test-shutdown-eof.c @@ -48,7 +48,7 @@ static uv_buf_t alloc_cb(uv_handle_t* handle, size_t size) { static void read_cb(uv_stream_t* t, ssize_t nread, uv_buf_t buf) { - uv_err_t err = uv_last_error(); + uv_err_t err = uv_last_error(uv_default_loop()); ASSERT((uv_tcp_t*)t == &tcp); @@ -153,22 +153,22 @@ TEST_IMPL(shutdown_eof) { struct sockaddr_in server_addr; int r; - uv_init(); + qbuf.base = "Q"; qbuf.len = 1; - uv_timer_init(&timer); + uv_timer_init(uv_default_loop(), &timer); uv_timer_start(&timer, timer_cb, 100, 0); server_addr = uv_ip4_addr("127.0.0.1", TEST_PORT); - r = uv_tcp_init(&tcp); + r = uv_tcp_init(uv_default_loop(), &tcp); ASSERT(!r); r = uv_tcp_connect(&connect_req, &tcp, server_addr, connect_cb); ASSERT(!r); - uv_run(); + uv_run(uv_default_loop()); ASSERT(called_connect_cb == 1); ASSERT(called_shutdown_cb == 1); diff --git a/test/test-spawn.c b/test/test-spawn.c index f2d84694..1b896886 100644 --- a/test/test-spawn.c +++ b/test/test-spawn.c @@ -75,7 +75,7 @@ uv_buf_t on_alloc(uv_handle_t* handle, size_t suggested_size) { void on_read(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { - uv_err_t err = uv_last_error(); + uv_err_t err = uv_last_error(uv_default_loop()); if (nread > 0) { output_used += nread; @@ -116,14 +116,14 @@ static void timer_cb(uv_timer_t* handle, int status) { TEST_IMPL(spawn_exit_code) { int r; - uv_init(); + init_process_options("spawn_helper1", exit_cb); - r = uv_spawn(&process, options); + r = uv_spawn(uv_default_loop(), &process, options); ASSERT(r == 0); - r = uv_run(); + r = uv_run(uv_default_loop()); ASSERT(r == 0); ASSERT(exit_cb_called == 1); @@ -137,20 +137,20 @@ TEST_IMPL(spawn_stdout) { int r; uv_pipe_t out; - uv_init(); + init_process_options("spawn_helper2", exit_cb); - uv_pipe_init(&out); + uv_pipe_init(uv_default_loop(), &out); options.stdout_stream = &out; - r = uv_spawn(&process, options); + r = uv_spawn(uv_default_loop(), &process, options); ASSERT(r == 0); r = uv_read_start((uv_stream_t*) &out, on_alloc, on_read); ASSERT(r == 0); - r = uv_run(); + r = uv_run(uv_default_loop()); ASSERT(r == 0); ASSERT(exit_cb_called == 1); @@ -170,16 +170,16 @@ int r; uv_buf_t buf; char buffer[] = "hello-from-spawn_stdin"; - uv_init(); + init_process_options("spawn_helper3", exit_cb); - uv_pipe_init(&out); - uv_pipe_init(&in); + uv_pipe_init(uv_default_loop(), &out); + uv_pipe_init(uv_default_loop(), &in); options.stdout_stream = &out; options.stdin_stream = ∈ - r = uv_spawn(&process, options); + r = uv_spawn(uv_default_loop(), &process, options); ASSERT(r == 0); buf.base = buffer; @@ -190,7 +190,7 @@ int r; r = uv_read_start((uv_stream_t*) &out, on_alloc, on_read); ASSERT(r == 0); - r = uv_run(); + r = uv_run(uv_default_loop()); ASSERT(r == 0); ASSERT(exit_cb_called == 1); @@ -204,20 +204,20 @@ int r; TEST_IMPL(spawn_and_kill) { int r; - uv_init(); + init_process_options("spawn_helper4", kill_cb); - r = uv_spawn(&process, options); + r = uv_spawn(uv_default_loop(), &process, options); ASSERT(r == 0); - r = uv_timer_init(&timer); + r = uv_timer_init(uv_default_loop(), &timer); ASSERT(r == 0); r = uv_timer_start(&timer, timer_cb, 500, 0); ASSERT(r == 0); - r = uv_run(); + r = uv_run(uv_default_loop()); ASSERT(r == 0); ASSERT(exit_cb_called == 1); @@ -234,7 +234,7 @@ TEST_IMPL(spawn_detect_pipe_name_collisions_on_windows) { char name[64]; HANDLE pipe_handle; - uv_init(); + init_process_options("spawn_helper2", exit_cb); diff --git a/test/test-tcp-bind-error.c b/test/test-tcp-bind-error.c index b466ef8b..2a49f6ad 100644 --- a/test/test-tcp-bind-error.c +++ b/test/test-tcp-bind-error.c @@ -39,14 +39,14 @@ TEST_IMPL(tcp_bind_error_addrinuse) { uv_tcp_t server1, server2; int r; - uv_init(); - r = uv_tcp_init(&server1); + + r = uv_tcp_init(uv_default_loop(), &server1); ASSERT(r == 0); r = uv_tcp_bind(&server1, addr); ASSERT(r == 0); - r = uv_tcp_init(&server2); + r = uv_tcp_init(uv_default_loop(), &server2); ASSERT(r == 0); r = uv_tcp_bind(&server2, addr); ASSERT(r == 0); @@ -56,12 +56,12 @@ TEST_IMPL(tcp_bind_error_addrinuse) { r = uv_listen((uv_stream_t*)&server2, 128, NULL); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EADDRINUSE); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRINUSE); uv_close((uv_handle_t*)&server1, close_cb); uv_close((uv_handle_t*)&server2, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 2); @@ -74,20 +74,20 @@ TEST_IMPL(tcp_bind_error_addrnotavail_1) { uv_tcp_t server; int r; - uv_init(); - r = uv_tcp_init(&server); + + r = uv_tcp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_tcp_bind(&server, addr); /* It seems that Linux is broken here - bind succeeds. */ if (r == -1) { - ASSERT(uv_last_error().code == UV_EADDRNOTAVAIL); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRNOTAVAIL); } uv_close((uv_handle_t*)&server, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 1); @@ -100,17 +100,15 @@ TEST_IMPL(tcp_bind_error_addrnotavail_2) { uv_tcp_t server; int r; - uv_init(); - - r = uv_tcp_init(&server); + r = uv_tcp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_tcp_bind(&server, addr); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EADDRNOTAVAIL); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRNOTAVAIL); uv_close((uv_handle_t*)&server, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 1); @@ -126,18 +124,18 @@ TEST_IMPL(tcp_bind_error_fault) { garbage_addr = (struct sockaddr_in*) &garbage; - uv_init(); - r = uv_tcp_init(&server); + + r = uv_tcp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_tcp_bind(&server, *garbage_addr); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EFAULT); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EFAULT); uv_close((uv_handle_t*)&server, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 1); @@ -152,20 +150,20 @@ TEST_IMPL(tcp_bind_error_inval) { uv_tcp_t server; int r; - uv_init(); - r = uv_tcp_init(&server); + + r = uv_tcp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_tcp_bind(&server, addr1); ASSERT(r == 0); r = uv_tcp_bind(&server, addr2); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EINVAL); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL); uv_close((uv_handle_t*)&server, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 1); @@ -179,9 +177,9 @@ TEST_IMPL(tcp_bind_localhost_ok) { uv_tcp_t server; int r; - uv_init(); - r = uv_tcp_init(&server); + + r = uv_tcp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_tcp_bind(&server, addr); ASSERT(r == 0); @@ -194,8 +192,8 @@ TEST_IMPL(tcp_listen_without_bind) { int r; uv_tcp_t server; - uv_init(); - r = uv_tcp_init(&server); + + r = uv_tcp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_listen((uv_stream_t*)&server, 128, NULL); ASSERT(r == 0); diff --git a/test/test-tcp-bind6-error.c b/test/test-tcp-bind6-error.c index cf283fa0..836d47ad 100644 --- a/test/test-tcp-bind6-error.c +++ b/test/test-tcp-bind6-error.c @@ -39,14 +39,14 @@ TEST_IMPL(tcp_bind6_error_addrinuse) { uv_tcp_t server1, server2; int r; - uv_init(); - r = uv_tcp_init(&server1); + + r = uv_tcp_init(uv_default_loop(), &server1); ASSERT(r == 0); r = uv_tcp_bind6(&server1, addr); ASSERT(r == 0); - r = uv_tcp_init(&server2); + r = uv_tcp_init(uv_default_loop(), &server2); ASSERT(r == 0); r = uv_tcp_bind6(&server2, addr); ASSERT(r == 0); @@ -56,12 +56,12 @@ TEST_IMPL(tcp_bind6_error_addrinuse) { r = uv_listen((uv_stream_t*)&server2, 128, NULL); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EADDRINUSE); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRINUSE); uv_close((uv_handle_t*)&server1, close_cb); uv_close((uv_handle_t*)&server2, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 2); @@ -74,17 +74,17 @@ TEST_IMPL(tcp_bind6_error_addrnotavail) { uv_tcp_t server; int r; - uv_init(); - r = uv_tcp_init(&server); + + r = uv_tcp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_tcp_bind6(&server, addr); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EADDRNOTAVAIL); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EADDRNOTAVAIL); uv_close((uv_handle_t*)&server, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 1); @@ -100,18 +100,18 @@ TEST_IMPL(tcp_bind6_error_fault) { garbage_addr = (struct sockaddr_in6*) &garbage; - uv_init(); - r = uv_tcp_init(&server); + + r = uv_tcp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_tcp_bind6(&server, *garbage_addr); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EFAULT); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EFAULT); uv_close((uv_handle_t*)&server, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 1); @@ -126,20 +126,20 @@ TEST_IMPL(tcp_bind6_error_inval) { uv_tcp_t server; int r; - uv_init(); - r = uv_tcp_init(&server); + + r = uv_tcp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_tcp_bind6(&server, addr1); ASSERT(r == 0); r = uv_tcp_bind6(&server, addr2); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EINVAL); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL); uv_close((uv_handle_t*)&server, close_cb); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 1); @@ -153,9 +153,9 @@ TEST_IMPL(tcp_bind6_localhost_ok) { uv_tcp_t server; int r; - uv_init(); - r = uv_tcp_init(&server); + + r = uv_tcp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_tcp_bind6(&server, addr); ASSERT(r == 0); diff --git a/test/test-tcp-writealot.c b/test/test-tcp-writealot.c index 6cb5e099..2e994cab 100644 --- a/test/test-tcp-writealot.c +++ b/test/test-tcp-writealot.c @@ -87,7 +87,7 @@ static void read_cb(uv_stream_t* tcp, ssize_t nread, uv_buf_t buf) { ASSERT(tcp != NULL); if (nread < 0) { - ASSERT(uv_last_error().code == UV_EOF); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EOF); printf("GOT EOF\n"); if (buf.base) { @@ -108,7 +108,7 @@ static void write_cb(uv_write_t* req, int status) { ASSERT(req != NULL); if (status) { - uv_err_t err = uv_last_error(); + uv_err_t err = uv_last_error(uv_default_loop()); fprintf(stderr, "uv_write error: %s\n", uv_strerror(err)); ASSERT(0); } @@ -176,15 +176,15 @@ TEST_IMPL(tcp_writealot) { ASSERT(send_buffer != NULL); - uv_init(); - r = uv_tcp_init(client); + + r = uv_tcp_init(uv_default_loop(), client); ASSERT(r == 0); r = uv_tcp_connect(connect_req, client, addr, connect_cb); ASSERT(r == 0); - uv_run(); + uv_run(uv_default_loop()); ASSERT(shutdown_cb_called == 1); ASSERT(connect_cb_called == 1); diff --git a/test/test-timer-again.c b/test/test-timer-again.c index e083b01c..0998ca59 100644 --- a/test/test-timer-again.c +++ b/test/test-timer-again.c @@ -49,14 +49,15 @@ static void repeat_1_cb(uv_timer_t* handle, int status) { ASSERT(uv_timer_get_repeat((uv_timer_t*)handle) == 50); - LOGF("repeat_1_cb called after %ld ms\n", (long int)(uv_now() - start_time)); + LOGF("repeat_1_cb called after %ld ms\n", + (long int)(uv_now(uv_default_loop()) - start_time)); repeat_1_cb_called++; r = uv_timer_again(&repeat_2); ASSERT(r == 0); - if (uv_now() >= start_time + 500) { + if (uv_now(uv_default_loop()) >= start_time + 500) { uv_close((uv_handle_t*)handle, close_cb); /* We're not calling uv_timer_again on repeat_2 any more, so after this */ /* timer_2_cb is expected. */ @@ -71,7 +72,8 @@ static void repeat_2_cb(uv_timer_t* handle, int status) { ASSERT(status == 0); ASSERT(repeat_2_cb_allowed); - LOGF("repeat_2_cb called after %ld ms\n", (long int)(uv_now() - start_time)); + LOGF("repeat_2_cb called after %ld ms\n", + (long int)(uv_now(uv_default_loop()) - start_time)); repeat_2_cb_called++; @@ -93,21 +95,21 @@ static void repeat_2_cb(uv_timer_t* handle, int status) { TEST_IMPL(timer_again) { int r; - uv_init(); - start_time = uv_now(); + + start_time = uv_now(uv_default_loop()); ASSERT(0 < start_time); /* Verify that it is not possible to uv_timer_again a never-started timer. */ - r = uv_timer_init(&dummy); + r = uv_timer_init(uv_default_loop(), &dummy); ASSERT(r == 0); r = uv_timer_again(&dummy); ASSERT(r == -1); - ASSERT(uv_last_error().code == UV_EINVAL); - uv_unref(); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EINVAL); + uv_unref(uv_default_loop()); /* Start timer repeat_1. */ - r = uv_timer_init(&repeat_1); + r = uv_timer_init(uv_default_loop(), &repeat_1); ASSERT(r == 0); r = uv_timer_start(&repeat_1, repeat_1_cb, 50, 0); ASSERT(r == 0); @@ -121,21 +123,21 @@ TEST_IMPL(timer_again) { * Start another repeating timer. It'll be again()ed by the repeat_1 so * it should not time out until repeat_1 stops. */ - r = uv_timer_init(&repeat_2); + r = uv_timer_init(uv_default_loop(), &repeat_2); ASSERT(r == 0); r = uv_timer_start(&repeat_2, repeat_2_cb, 100, 100); ASSERT(r == 0); ASSERT(uv_timer_get_repeat(&repeat_2) == 100); - uv_run(); + uv_run(uv_default_loop()); ASSERT(repeat_1_cb_called == 10); ASSERT(repeat_2_cb_called == 2); ASSERT(close_cb_called == 2); LOGF("Test took %ld ms (expected ~700 ms)\n", - (long int)(uv_now() - start_time)); - ASSERT(700 <= uv_now() - start_time); + (long int)(uv_now(uv_default_loop()) - start_time)); + ASSERT(700 <= uv_now(uv_default_loop()) - start_time); return 0; } diff --git a/test/test-timer.c b/test/test-timer.c index c62a8c68..17bcb84b 100644 --- a/test/test-timer.c +++ b/test/test-timer.c @@ -53,7 +53,7 @@ static void once_cb(uv_timer_t* handle, int status) { uv_close((uv_handle_t*)handle, once_close_cb); /* Just call this randomly for the code coverage. */ - uv_update_time(); + uv_update_time(uv_default_loop()); } @@ -90,37 +90,35 @@ TEST_IMPL(timer) { uv_timer_t repeat, never; int i, r; - uv_init(); - - start_time = uv_now(); + start_time = uv_now(uv_default_loop()); ASSERT(0 < start_time); /* Let 10 timers time out in 500 ms total. */ for (i = 0; i < 10; i++) { once = (uv_timer_t*)malloc(sizeof(*once)); ASSERT(once != NULL); - r = uv_timer_init(once); + r = uv_timer_init(uv_default_loop(), once); ASSERT(r == 0); r = uv_timer_start(once, once_cb, i * 50, 0); ASSERT(r == 0); } /* The 11th timer is a repeating timer that runs 4 times */ - r = uv_timer_init(&repeat); + r = uv_timer_init(uv_default_loop(), &repeat); ASSERT(r == 0); r = uv_timer_start(&repeat, repeat_cb, 100, 100); ASSERT(r == 0); /* The 12th timer should not do anything. */ - r = uv_timer_init(&never); + r = uv_timer_init(uv_default_loop(), &never); ASSERT(r == 0); r = uv_timer_start(&never, never_cb, 100, 100); ASSERT(r == 0); r = uv_timer_stop(&never); ASSERT(r == 0); - uv_unref(); + uv_unref(uv_default_loop()); - uv_run(); + uv_run(uv_default_loop()); ASSERT(once_cb_called == 10); ASSERT(once_close_cb_called == 10); @@ -128,7 +126,7 @@ TEST_IMPL(timer) { ASSERT(repeat_cb_called == 5); ASSERT(repeat_close_cb_called == 1); - ASSERT(500 <= uv_now() - start_time); + ASSERT(500 <= uv_now(uv_default_loop()) - start_time); return 0; } diff --git a/test/test-udp-dgram-too-big.c b/test/test-udp-dgram-too-big.c index 7de9b49a..2d172c06 100644 --- a/test/test-udp-dgram-too-big.c +++ b/test/test-udp-dgram-too-big.c @@ -50,7 +50,7 @@ static void send_cb(uv_udp_send_t* req, int status) { CHECK_HANDLE(req->handle); ASSERT(status == -1); - ASSERT(uv_last_error().code == UV_EMSGSIZE); + ASSERT(uv_last_error(uv_default_loop()).code == UV_EMSGSIZE); uv_close((uv_handle_t*)req->handle, close_cb); send_cb_called++; @@ -65,9 +65,7 @@ TEST_IMPL(udp_dgram_too_big) { memset(dgram, 42, sizeof dgram); /* silence valgrind */ - uv_init(); - - r = uv_udp_init(&handle_); + r = uv_udp_init(uv_default_loop(), &handle_); ASSERT(r == 0); buf = uv_buf_init(dgram, sizeof dgram); @@ -79,7 +77,7 @@ TEST_IMPL(udp_dgram_too_big) { ASSERT(close_cb_called == 0); ASSERT(send_cb_called == 0); - uv_run(); + uv_run(uv_default_loop()); ASSERT(send_cb_called == 1); ASSERT(close_cb_called == 1); diff --git a/test/test-udp-ipv6.c b/test/test-udp-ipv6.c index 489c17cc..6ff36b32 100644 --- a/test/test-udp-ipv6.c +++ b/test/test-udp-ipv6.c @@ -100,11 +100,9 @@ static void do_test(uv_udp_recv_cb recv_cb, int bind_flags) { uv_buf_t buf; int r; - uv_init(); - addr6 = uv_ip6_addr("::0", TEST_PORT); - r = uv_udp_init(&server); + r = uv_udp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_udp_bind6(&server, addr6, bind_flags); @@ -113,7 +111,7 @@ static void do_test(uv_udp_recv_cb recv_cb, int bind_flags) { r = uv_udp_recv_start(&server, alloc_cb, recv_cb); ASSERT(r == 0); - r = uv_udp_init(&client); + r = uv_udp_init(uv_default_loop(), &client); ASSERT(r == 0); buf = uv_buf_init("PING", 4); @@ -122,7 +120,7 @@ static void do_test(uv_udp_recv_cb recv_cb, int bind_flags) { r = uv_udp_send(&req_, &client, &buf, 1, addr, send_cb); ASSERT(r == 0); - r = uv_timer_init(&timeout); + r = uv_timer_init(uv_default_loop(), &timeout); ASSERT(r == 0); r = uv_timer_start(&timeout, timeout_cb, 500, 0); @@ -132,7 +130,7 @@ static void do_test(uv_udp_recv_cb recv_cb, int bind_flags) { ASSERT(send_cb_called == 0); ASSERT(recv_cb_called == 0); - uv_run(); + uv_run(uv_default_loop()); ASSERT(close_cb_called == 3); } diff --git a/test/test-udp-send-and-recv.c b/test/test-udp-send-and-recv.c index 6d61e83f..ab47e91c 100644 --- a/test/test-udp-send-and-recv.c +++ b/test/test-udp-send-and-recv.c @@ -170,9 +170,7 @@ TEST_IMPL(udp_send_and_recv) { addr = uv_ip4_addr("0.0.0.0", TEST_PORT); - uv_init(); - - r = uv_udp_init(&server); + r = uv_udp_init(uv_default_loop(), &server); ASSERT(r == 0); r = uv_udp_bind(&server, addr, 0); @@ -183,7 +181,7 @@ TEST_IMPL(udp_send_and_recv) { addr = uv_ip4_addr("127.0.0.1", TEST_PORT); - r = uv_udp_init(&client); + r = uv_udp_init(uv_default_loop(), &client); ASSERT(r == 0); /* client sends "PING", expects "PONG" */ @@ -198,7 +196,7 @@ TEST_IMPL(udp_send_and_recv) { ASSERT(sv_send_cb_called == 0); ASSERT(sv_recv_cb_called == 0); - uv_run(); + uv_run(uv_default_loop()); ASSERT(cl_send_cb_called == 1); ASSERT(cl_recv_cb_called == 1);