diff --git a/uv-win.c b/uv-win.c index 0586aff0..c8fddfe5 100644 --- a/uv-win.c +++ b/uv-win.c @@ -296,6 +296,7 @@ static uv_err_code uv_translate_sys_error(int sys_errno) { case ERROR_CONNECTION_REFUSED: return UV_ECONNREFUSED; case WSAECONNREFUSED: return UV_ECONNREFUSED; case WSAEFAULT: return UV_EFAULT; + case ERROR_INVALID_DATA: return UV_EINVAL; case WSAEINVAL: return UV_EINVAL; case ERROR_TOO_MANY_OPEN_FILES: return UV_EMFILE; case WSAEMFILE: return UV_EMFILE; @@ -1212,6 +1213,8 @@ int uv_timer_init(uv_handle_t* handle, uv_close_cb close_cb, void* data) { handle->data = data; handle->flags = 0; handle->error = uv_ok_; + handle->timer_cb = NULL; + handle->repeat = 0; uv_refs_++; @@ -1250,6 +1253,12 @@ int uv_timer_stop(uv_handle_t* handle) { int uv_timer_again(uv_handle_t* handle) { + /* If timer_cb is NULL that means that the timer was never started. */ + if (!handle->timer_cb) { + uv_set_sys_error(ERROR_INVALID_DATA); + return -1; + } + if (handle->flags & UV_HANDLE_ACTIVE) { RB_REMOVE(uv_timer_s, &uv_timers_, handle); handle->flags &= ~UV_HANDLE_ACTIVE; @@ -1269,6 +1278,17 @@ int uv_timer_again(uv_handle_t* handle) { } +int uv_timer_set_repeat(uv_handle_t* handle, int64_t repeat) { + handle->repeat = repeat; + return 0; +} + + +int64_t uv_timer_get_repeat(uv_handle_t* handle) { + return handle->repeat; +} + + void uv_update_time() { LARGE_INTEGER counter; diff --git a/uv.h b/uv.h index 2070309c..d0104e2a 100644 --- a/uv.h +++ b/uv.h @@ -224,7 +224,17 @@ int uv_write(uv_req_t* req, uv_buf_t bufs[], int bufcnt); int uv_timer_init(uv_handle_t* handle, uv_close_cb close_cb, void* data); int uv_timer_start(uv_handle_t* handle, uv_loop_cb cb, int64_t timeout, int64_t repeat); int uv_timer_stop(uv_handle_t* handle); +/* Stop the timer, and if it is repeating restart it using the repeat value + * as the timeout. If the timer has never been started before it returns -1 and + * sets the error to UV_EINVAL. */ int uv_timer_again(uv_handle_t* handle); +/* Set the repeat value. Note that if the repeat value is set from a timer + * callback it does not immediately take effect. If the timer was nonrepeating + * before, it will have been stopped. If it was repeating, then the old repeat + * value will have been used to schedule the next timeout. + */ +int uv_timer_set_repeat(uv_handle_t* handle, int64_t repeat); +int64_t uv_timer_get_repeat(uv_handle_t* handle); /* libev wrapper. Every active prepare handle gets its callback called * exactly once per loop iteration, just before the system blocks to wait