Skip to content

Commit

Permalink
unix: change uv_backend_timeout() prototype
Browse files Browse the repository at this point in the history
* change return value to signed int
* constify loop argument
  • Loading branch information
bnoordhuis committed Nov 28, 2012
1 parent 09a7f85 commit 4a69c4b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
16 changes: 13 additions & 3 deletions include/uv.h
Expand Up @@ -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*);


/*
Expand Down
2 changes: 1 addition & 1 deletion src/unix/core.c
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/unix/internal.h
Expand Up @@ -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);
Expand Down
9 changes: 5 additions & 4 deletions src/unix/timer.c
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/win/core.c
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion test/test-embed.c
Expand Up @@ -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());
Expand Down

0 comments on commit 4a69c4b

Please sign in to comment.