diff --git a/include/uv.h b/include/uv.h index e2b63f13c1..d2a5e09ceb 100644 --- a/include/uv.h +++ b/include/uv.h @@ -262,16 +262,26 @@ UV_EXTERN void uv_update_time(uv_loop_t*); UV_EXTERN int64_t uv_now(uv_loop_t*); /* - * Get backend file descriptor and get polling timeout for it. - * (only kqueue, epoll and event ports are supported). + * Get backend file descriptor. Only kqueue, epoll and event ports are + * supported. * * This can be used in conjuction with uv_run_once() to poll in one thread and * run the event loop's event callbacks in another. * * Useful for embedding libuv's event loop in another event loop. + * See test/test-embed.c for an example. + * + * Note that embedding a kqueue fd in another kqueue pollset doesn't work on + * all platforms. It's not an error to add the fd but it never generates + * events. */ UV_EXTERN int uv_backend_fd(const uv_loop_t*); -UV_EXTERN unsigned int uv_backend_timeout(uv_loop_t*); + +/* + * Get the poll timeout. The return value is in milliseconds, or -1 for no + * timeout. + */ +UV_EXTERN int uv_backend_timeout(const uv_loop_t*); /* diff --git a/src/unix/core.c b/src/unix/core.c index 19ccc28360..ece96738cd 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -253,7 +253,7 @@ int uv_backend_fd(const uv_loop_t* loop) { } -unsigned int uv_backend_timeout(uv_loop_t* loop) { +int uv_backend_timeout(const uv_loop_t* loop) { if (!uv__has_active_handles(loop) && !uv__has_active_reqs(loop)) return 0; diff --git a/src/unix/internal.h b/src/unix/internal.h index 6054461822..a82b86192f 100644 --- a/src/unix/internal.h +++ b/src/unix/internal.h @@ -163,7 +163,7 @@ int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb); /* timer */ void uv__run_timers(uv_loop_t* loop); -unsigned int uv__next_timeout(uv_loop_t* loop); +int uv__next_timeout(const uv_loop_t* loop); /* signal */ void uv__signal_close(uv_signal_t* handle); diff --git a/src/unix/timer.c b/src/unix/timer.c index a560584dea..9708dbd89b 100644 --- a/src/unix/timer.c +++ b/src/unix/timer.c @@ -102,13 +102,14 @@ int64_t uv_timer_get_repeat(uv_timer_t* handle) { } -unsigned int uv__next_timeout(uv_loop_t* loop) { - uv_timer_t* handle; +int uv__next_timeout(const uv_loop_t* loop) { + const uv_timer_t* handle; - handle = RB_MIN(uv__timers, &loop->timer_handles); + /* RB_MIN expects a non-const tree root. That's okay, it doesn't modify it. */ + handle = RB_MIN(uv__timers, (struct uv__timers*) &loop->timer_handles); if (handle == NULL) - return (unsigned int) -1; /* block indefinitely */ + return -1; /* block indefinitely */ if (handle->timeout <= loop->time) return 0; diff --git a/src/win/core.c b/src/win/core.c index 4e2129be42..56b15d45c0 100644 --- a/src/win/core.c +++ b/src/win/core.c @@ -176,7 +176,7 @@ int uv_backend_fd(const uv_loop_t* loop) { } -unsigned int uv_backend_timeout(uv_loop_t* loop) { +int uv_backend_timeout(const uv_loop_t* loop) { return 0; } diff --git a/test/test-embed.c b/test/test-embed.c index ebf99c34bd..e635596e7a 100644 --- a/test/test-embed.c +++ b/test/test-embed.c @@ -61,7 +61,7 @@ static int embed_timer_called; static void embed_thread_runner(void* arg) { int r; int fd; - unsigned int timeout; + int timeout; while (!embed_closed) { fd = uv_backend_fd(uv_default_loop());