unix, windows: stat: never pass NULL to cb
Never pass NULL to the fs_poll callback, use a zeroed out statbuf instead. Makes the interface a little more convenient to use.
This commit is contained in:
parent
6e8eb33249
commit
14ffaa668d
@ -316,8 +316,8 @@ typedef void (*uv_fs_event_cb)(uv_fs_event_t* handle, const char* filename,
|
|||||||
|
|
||||||
typedef void (*uv_fs_poll_cb)(uv_fs_poll_t* handle,
|
typedef void (*uv_fs_poll_cb)(uv_fs_poll_t* handle,
|
||||||
int status,
|
int status,
|
||||||
uv_statbuf_t* prev,
|
const uv_statbuf_t* prev,
|
||||||
uv_statbuf_t* curr);
|
const uv_statbuf_t* curr);
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
UV_LEAVE_GROUP = 0,
|
UV_LEAVE_GROUP = 0,
|
||||||
|
|||||||
@ -30,6 +30,8 @@ static int statbuf_eq(const uv_statbuf_t* a, const uv_statbuf_t* b);
|
|||||||
static void timer_cb(uv_timer_t* timer, int status);
|
static void timer_cb(uv_timer_t* timer, int status);
|
||||||
static void poll_cb(uv_fs_t* req);
|
static void poll_cb(uv_fs_t* req);
|
||||||
|
|
||||||
|
static uv_statbuf_t zero_statbuf;
|
||||||
|
|
||||||
|
|
||||||
int uv_fs_poll_init(uv_loop_t* loop, uv_fs_poll_t* handle) {
|
int uv_fs_poll_init(uv_loop_t* loop, uv_fs_poll_t* handle) {
|
||||||
/* TODO(bnoordhuis) Mark fs_req internal. */
|
/* TODO(bnoordhuis) Mark fs_req internal. */
|
||||||
@ -141,7 +143,7 @@ static void poll_cb(uv_fs_t* req) {
|
|||||||
if (req->result != 0) {
|
if (req->result != 0) {
|
||||||
if (handle->busy_polling != -req->errorno) {
|
if (handle->busy_polling != -req->errorno) {
|
||||||
uv__set_artificial_error(handle->loop, req->errorno);
|
uv__set_artificial_error(handle->loop, req->errorno);
|
||||||
handle->poll_cb(handle, -1, NULL, NULL);
|
handle->poll_cb(handle, -1, &handle->statbuf, &zero_statbuf);
|
||||||
handle->busy_polling = -req->errorno;
|
handle->busy_polling = -req->errorno;
|
||||||
}
|
}
|
||||||
goto out;
|
goto out;
|
||||||
|
|||||||
@ -30,8 +30,8 @@ static void timer_cb(uv_timer_t* handle, int status);
|
|||||||
static void close_cb(uv_handle_t* handle);
|
static void close_cb(uv_handle_t* handle);
|
||||||
static void poll_cb(uv_fs_poll_t* handle,
|
static void poll_cb(uv_fs_poll_t* handle,
|
||||||
int status,
|
int status,
|
||||||
uv_statbuf_t* prev,
|
const uv_statbuf_t* prev,
|
||||||
uv_statbuf_t* curr);
|
const uv_statbuf_t* curr);
|
||||||
|
|
||||||
static uv_fs_poll_t poll_handle;
|
static uv_fs_poll_t poll_handle;
|
||||||
static uv_timer_t timer_handle;
|
static uv_timer_t timer_handle;
|
||||||
@ -74,50 +74,49 @@ static void timer_cb(uv_timer_t* handle, int status) {
|
|||||||
|
|
||||||
static void poll_cb(uv_fs_poll_t* handle,
|
static void poll_cb(uv_fs_poll_t* handle,
|
||||||
int status,
|
int status,
|
||||||
uv_statbuf_t* prev,
|
const uv_statbuf_t* prev,
|
||||||
uv_statbuf_t* curr) {
|
const uv_statbuf_t* curr) {
|
||||||
|
const static uv_statbuf_t zero_statbuf;
|
||||||
|
|
||||||
ASSERT(handle == &poll_handle);
|
ASSERT(handle == &poll_handle);
|
||||||
ASSERT(uv_is_active((uv_handle_t*)handle));
|
ASSERT(uv_is_active((uv_handle_t*)handle));
|
||||||
|
ASSERT(prev != NULL);
|
||||||
|
ASSERT(curr != NULL);
|
||||||
|
|
||||||
switch (poll_cb_called++) {
|
switch (poll_cb_called++) {
|
||||||
case 0:
|
case 0:
|
||||||
ASSERT(status == -1);
|
ASSERT(status == -1);
|
||||||
ASSERT(prev == NULL);
|
|
||||||
ASSERT(curr == NULL);
|
|
||||||
ASSERT(uv_last_error(loop).code == UV_ENOENT);
|
ASSERT(uv_last_error(loop).code == UV_ENOENT);
|
||||||
|
ASSERT(0 == memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
|
||||||
|
ASSERT(0 == memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
|
||||||
touch_file(FIXTURE);
|
touch_file(FIXTURE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
ASSERT(status == 0);
|
ASSERT(status == 0);
|
||||||
ASSERT(prev != NULL);
|
ASSERT(0 == memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
|
||||||
ASSERT(curr != NULL);
|
ASSERT(0 != memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
|
||||||
{
|
|
||||||
uv_statbuf_t buf;
|
|
||||||
memset(&buf, 0, sizeof(buf));
|
|
||||||
ASSERT(0 == memcmp(&buf, prev, sizeof(buf)));
|
|
||||||
}
|
|
||||||
ASSERT(0 == uv_timer_start(&timer_handle, timer_cb, 20, 0));
|
ASSERT(0 == uv_timer_start(&timer_handle, timer_cb, 20, 0));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
ASSERT(status == 0);
|
ASSERT(status == 0);
|
||||||
ASSERT(prev != NULL);
|
ASSERT(0 != memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
|
||||||
ASSERT(curr != NULL);
|
ASSERT(0 != memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
|
||||||
ASSERT(0 == uv_timer_start(&timer_handle, timer_cb, 200, 0));
|
ASSERT(0 == uv_timer_start(&timer_handle, timer_cb, 200, 0));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
ASSERT(status == 0);
|
ASSERT(status == 0);
|
||||||
ASSERT(prev != NULL);
|
ASSERT(0 != memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
|
||||||
ASSERT(curr != NULL);
|
ASSERT(0 != memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
|
||||||
remove(FIXTURE);
|
remove(FIXTURE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
ASSERT(status == -1);
|
ASSERT(status == -1);
|
||||||
ASSERT(prev == NULL);
|
ASSERT(0 != memcmp(prev, &zero_statbuf, sizeof(zero_statbuf)));
|
||||||
ASSERT(curr == NULL);
|
ASSERT(0 == memcmp(curr, &zero_statbuf, sizeof(zero_statbuf)));
|
||||||
ASSERT(uv_last_error(loop).code == UV_ENOENT);
|
ASSERT(uv_last_error(loop).code == UV_ENOENT);
|
||||||
uv_close((uv_handle_t*)handle, close_cb);
|
uv_close((uv_handle_t*)handle, close_cb);
|
||||||
break;
|
break;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user