diff --git a/include/uv-private/uv-win.h b/include/uv-private/uv-win.h index 372d65c67e..76b227b50f 100644 --- a/include/uv-private/uv-win.h +++ b/include/uv-private/uv-win.h @@ -151,7 +151,7 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s); #define UV_TCP_PRIVATE_FIELDS \ SOCKET socket; \ - uv_err_t bind_error; \ + int bind_error; \ union { \ struct { uv_tcp_server_fields }; \ struct { uv_tcp_connection_fields }; \ diff --git a/src/unix/cares.c b/src/unix/cares.c index b2bc16f4c7..85cabac46e 100644 --- a/src/unix/cares.c +++ b/src/unix/cares.c @@ -147,7 +147,7 @@ int uv_ares_init_options(uv_loop_t* loop, ares_channel *channelptr, /* only allow single init at a time */ if (loop->channel != NULL) { - uv_err_new_artificial(loop, UV_EALREADY); + uv__set_artificial_error(loop, UV_EALREADY); return -1; } diff --git a/src/unix/core.c b/src/unix/core.c index 80b3bf6ed9..409656df54 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -563,7 +563,7 @@ int uv_timer_stop(uv_timer_t* timer) { int uv_timer_again(uv_timer_t* timer) { if (!ev_is_active(&timer->timer_watcher)) { - uv_err_new(timer->loop, EINVAL); + uv__set_sys_error(timer->loop, EINVAL); return -1; } @@ -595,7 +595,7 @@ static int uv_getaddrinfo_done(eio_req* req) { if (handle->retcode != 0) { /* TODO how to display gai error strings? */ - uv_err_new(handle->loop, handle->retcode); + uv__set_sys_error(handle->loop, handle->retcode); } handle->cb(handle, handle->retcode, res); @@ -626,7 +626,7 @@ int uv_getaddrinfo(uv_loop_t* loop, if (handle == NULL || cb == NULL || (hostname == NULL && service == NULL)) { - uv_err_new_artificial(loop, UV_EINVAL); + uv__set_artificial_error(loop, UV_EINVAL); return -1; } diff --git a/src/unix/cygwin.c b/src/unix/cygwin.c index 6702eb9234..91681248e9 100644 --- a/src/unix/cygwin.c +++ b/src/unix/cygwin.c @@ -58,7 +58,7 @@ int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle, const char* filename, uv_fs_event_cb cb) { - uv_err_new(loop, ENOSYS); + uv__set_sys_error(loop, ENOSYS); return -1; } diff --git a/src/unix/darwin.c b/src/unix/darwin.c index af72b4b0ec..fde515444b 100644 --- a/src/unix/darwin.c +++ b/src/unix/darwin.c @@ -73,7 +73,7 @@ int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle, const char* filename, uv_fs_event_cb cb) { - uv_err_new(loop, ENOSYS); + uv__set_sys_error(loop, ENOSYS); return -1; } diff --git a/src/unix/error.c b/src/unix/error.c index 3520eec719..5f3a50b56b 100644 --- a/src/unix/error.c +++ b/src/unix/error.c @@ -90,21 +90,3 @@ uv_err_code uv_translate_sys_error(int sys_errno) { assert(0 && "unreachable"); return -1; } - - -uv_err_t uv_err_new_artificial(uv_loop_t* loop, int code) { - uv_err_t err; - err.sys_errno_ = 0; - err.code = code; - loop->last_err = err; - return err; -} - - -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); - loop->last_err = err; - return err; -} diff --git a/src/unix/freebsd.c b/src/unix/freebsd.c index 449aad4c21..cd1959a48b 100644 --- a/src/unix/freebsd.c +++ b/src/unix/freebsd.c @@ -72,7 +72,7 @@ int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle, const char* filename, uv_fs_event_cb cb) { - uv_err_new(loop, ENOSYS); + uv__set_sys_error(loop, ENOSYS); return -1; } diff --git a/src/unix/fs.c b/src/unix/fs.c index f1974ca2d6..1bc4f71eeb 100644 --- a/src/unix/fs.c +++ b/src/unix/fs.c @@ -46,7 +46,7 @@ /* async */ \ req->eio = eiofunc(args, EIO_PRI_DEFAULT, uv__fs_after, req); \ if (!req->eio) { \ - uv_err_new(loop, ENOMEM); \ + uv__set_sys_error(loop, ENOMEM); \ return -1; \ } \ uv_ref(loop); \ @@ -54,7 +54,7 @@ /* sync */ \ req->result = func(args); \ if (req->result) { \ - uv_err_new(loop, errno); \ + uv__set_sys_error(loop, errno); \ } \ return req->result; \ } \ @@ -192,7 +192,7 @@ int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, uv_ref(loop); req->eio = eio_open(path, flags, mode, EIO_PRI_DEFAULT, uv__fs_after, req); if (!req->eio) { - uv_err_new(loop, ENOMEM); + uv__set_sys_error(loop, ENOMEM); return -1; } @@ -200,7 +200,7 @@ int uv_fs_open(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, /* sync */ req->result = open(path, flags, mode); if (req->result < 0) { - uv_err_new(loop, errno); + uv__set_sys_error(loop, errno); return -1; } @@ -224,7 +224,7 @@ int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, uv_file fd, void* buf, uv__fs_after, req); if (!req->eio) { - uv_err_new(loop, ENOMEM); + uv__set_sys_error(loop, ENOMEM); return -1; } @@ -235,7 +235,7 @@ int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, uv_file fd, void* buf, pread(fd, buf, length, offset); if (req->result < 0) { - uv_err_new(loop, errno); + uv__set_sys_error(loop, errno); return -1; } @@ -261,7 +261,7 @@ int uv_fs_write(uv_loop_t* loop, uv_fs_t* req, uv_file file, void* buf, req->eio = eio_write(file, buf, length, offset, EIO_PRI_DEFAULT, uv__fs_after, req); if (!req->eio) { - uv_err_new(loop, ENOMEM); + uv__set_sys_error(loop, ENOMEM); return -1; } @@ -272,7 +272,7 @@ int uv_fs_write(uv_loop_t* loop, uv_fs_t* req, uv_file file, void* buf, pwrite(file, buf, length, offset); if (req->result < 0) { - uv_err_new(loop, errno); + uv__set_sys_error(loop, errno); return -1; } @@ -308,7 +308,7 @@ int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, uv_ref(loop); req->eio = eio_readdir(path, flags, EIO_PRI_DEFAULT, uv__fs_after, req); if (!req->eio) { - uv_err_new(loop, ENOMEM); + uv__set_sys_error(loop, ENOMEM); return -1; } @@ -316,7 +316,7 @@ int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, /* sync */ DIR* dir = opendir(path); if (!dir) { - uv_err_new(loop, errno); + uv__set_sys_error(loop, errno); req->result = -1; return -1; } @@ -345,7 +345,7 @@ int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req, const char* path, int flags, r = closedir(dir); if (r) { - uv_err_new(loop, errno); + uv__set_sys_error(loop, errno); req->result = -1; return -1; } @@ -381,7 +381,7 @@ int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { free(pathdup); if (!req->eio) { - uv_err_new(loop, ENOMEM); + uv__set_sys_error(loop, ENOMEM); return -1; } @@ -392,7 +392,7 @@ int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { free(pathdup); if (req->result < 0) { - uv_err_new(loop, errno); + uv__set_sys_error(loop, errno); return -1; } @@ -413,7 +413,7 @@ int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { req->eio = eio_fstat(file, EIO_PRI_DEFAULT, uv__fs_after, req); if (!req->eio) { - uv_err_new(loop, ENOMEM); + uv__set_sys_error(loop, ENOMEM); return -1; } @@ -422,7 +422,7 @@ int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) { req->result = fstat(file, &req->statbuf); if (req->result < 0) { - uv_err_new(loop, errno); + uv__set_sys_error(loop, errno); return -1; } @@ -520,7 +520,7 @@ int uv_fs_futime(uv_loop_t* loop, uv_fs_t* req, uv_file file, double atime, WRAP_EIO(UV_FS_FUTIME, eio_futime, _futime, ARGS3(file, atime, mtime)) #else - uv_err_new(loop, ENOSYS); + uv__set_sys_error(loop, ENOSYS); return -1; #endif } @@ -550,7 +550,7 @@ int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { free(pathdup); if (!req->eio) { - uv_err_new(loop, ENOMEM); + uv__set_sys_error(loop, ENOMEM); return -1; } @@ -561,7 +561,7 @@ int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_fs_cb cb) { free(pathdup); if (req->result < 0) { - uv_err_new(loop, errno); + uv__set_sys_error(loop, errno); return -1; } @@ -600,7 +600,7 @@ int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path, uv_ref(loop); return 0; } else { - uv_err_new(loop, ENOMEM); + uv__set_sys_error(loop, ENOMEM); return -1; } } else { @@ -616,7 +616,7 @@ int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path, } if ((buf = malloc(size + 1)) == NULL) { - uv_err_new(loop, ENOMEM); + uv__set_sys_error(loop, ENOMEM); return -1; } @@ -693,7 +693,7 @@ int uv_queue_work(uv_loop_t* loop, uv_work_t* req, uv_work_cb work_cb, req->eio = eio_custom(uv__work, EIO_PRI_DEFAULT, uv__after_work, req); if (!req->eio) { - uv_err_new(loop, ENOMEM); + uv__set_sys_error(loop, ENOMEM); return -1; } diff --git a/src/unix/internal.h b/src/unix/internal.h index 42283ca2a5..a10cd3d00c 100644 --- a/src/unix/internal.h +++ b/src/unix/internal.h @@ -96,8 +96,6 @@ int uv__socket(int domain, int type, int protocol); /* error */ uv_err_code uv_translate_sys_error(int sys_errno); -uv_err_t uv_err_new(uv_loop_t* loop, int sys_error); -uv_err_t uv_err_new_artificial(uv_loop_t* loop, int code); void uv_fatal_error(const int errorno, const char* syscall); /* stream */ diff --git a/src/unix/linux.c b/src/unix/linux.c index 0b4ce64ddf..dd93e595e0 100644 --- a/src/unix/linux.c +++ b/src/unix/linux.c @@ -145,7 +145,7 @@ int uv_fs_event_init(uv_loop_t* loop, * keep creating new inotify fds. */ if ((fd = new_inotify_fd()) == -1) { - uv_err_new(loop, errno); + uv__set_sys_error(loop, errno); return -1; } @@ -158,7 +158,7 @@ int uv_fs_event_init(uv_loop_t* loop, | IN_MOVED_TO; if (inotify_add_watch(fd, filename, flags) == -1) { - uv_err_new(loop, errno); + uv__set_sys_error(loop, errno); uv__close(fd); return -1; } diff --git a/src/unix/netbsd.c b/src/unix/netbsd.c index 0ba7999754..0483b5e64f 100644 --- a/src/unix/netbsd.c +++ b/src/unix/netbsd.c @@ -75,7 +75,7 @@ int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle, const char* filename, uv_fs_event_cb cb) { - uv_err_new(loop, ENOSYS); + uv__set_sys_error(loop, ENOSYS); return -1; } diff --git a/src/unix/pipe.c b/src/unix/pipe.c index 50dc635b7e..86c11deaa2 100644 --- a/src/unix/pipe.c +++ b/src/unix/pipe.c @@ -53,13 +53,13 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) { /* Already bound? */ if (handle->fd >= 0) { - uv_err_new_artificial(handle->loop, UV_EINVAL); + uv__set_artificial_error(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(handle->loop, ENOMEM); + uv__set_sys_error(handle->loop, ENOMEM); goto out; } @@ -67,7 +67,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(handle->loop, errno); + uv__set_sys_error(handle->loop, errno); goto out; } @@ -88,7 +88,7 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) { || unlink(pipe_fname) == -1 || bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr) == -1) { /* Convert ENOENT to EACCES for compatibility with Windows. */ - uv_err_new(handle->loop, (errno == ENOENT) ? EACCES : errno); + uv__set_sys_error(handle->loop, (errno == ENOENT) ? EACCES : errno); goto out; } } @@ -125,13 +125,13 @@ int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) { status = -1; if (handle->fd == -1) { - uv_err_new_artificial(handle->loop, UV_EINVAL); + uv__set_artificial_error(handle->loop, UV_EINVAL); goto out; } assert(handle->fd >= 0); if ((status = listen(handle->fd, backlog)) == -1) { - uv_err_new(handle->loop, errno); + uv__set_sys_error(handle->loop, errno); } else { handle->connection_cb = cb; ev_io_init(&handle->read_watcher, uv__pipe_accept, handle->fd, EV_READ); @@ -190,7 +190,7 @@ int uv_pipe_connect(uv_connect_t* req, status = -1; if ((sockfd = uv__socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { - uv_err_new(handle->loop, errno); + uv__set_sys_error(handle->loop, errno); goto out; } @@ -207,7 +207,7 @@ int uv_pipe_connect(uv_connect_t* req, while (r == -1 && errno == EINTR); if (r == -1) { - uv_err_new(handle->loop, errno); + uv__set_sys_error(handle->loop, errno); uv__close(sockfd); goto out; } @@ -257,7 +257,7 @@ 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(pipe->loop, errno); + uv__set_sys_error(pipe->loop, errno); } } else { pipe->accepted_fd = sockfd; diff --git a/src/unix/process.c b/src/unix/process.c index 34f12d1737..487f207594 100644 --- a/src/unix/process.c +++ b/src/unix/process.c @@ -277,7 +277,7 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process, return 0; error: - uv_err_new(process->loop, errno); + uv__set_sys_error(process->loop, errno); uv__close(stdin_pipe[0]); uv__close(stdin_pipe[1]); uv__close(stdout_pipe[0]); @@ -292,7 +292,7 @@ int uv_process_kill(uv_process_t* process, int signum) { int r = kill(process->pid, signum); if (r) { - uv_err_new(process->loop, errno); + uv__set_sys_error(process->loop, errno); return -1; } else { return 0; diff --git a/src/unix/stream.c b/src/unix/stream.c index 3983ca23b6..f7c0a68469 100644 --- a/src/unix/stream.c +++ b/src/unix/stream.c @@ -87,7 +87,7 @@ 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(stream->loop, errno); + uv__set_sys_error(stream->loop, errno); return -1; } @@ -118,7 +118,7 @@ void uv__stream_destroy(uv_stream_t* stream) { free(req->bufs); if (req->cb) { - uv_err_new_artificial(req->handle->loop, UV_EINTR); + uv__set_artificial_error(req->handle->loop, UV_EINTR); req->cb(req, -1); } } @@ -129,7 +129,7 @@ void uv__stream_destroy(uv_stream_t* stream) { req = ngx_queue_data(q, uv_write_t, queue); if (req->cb) { - uv_err_new_artificial(stream->loop, req->error); + uv__set_artificial_error(stream->loop, req->error); req->cb(req, req->error ? -1 : 0); } } @@ -167,7 +167,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(stream->loop, errno); + uv__set_sys_error(stream->loop, errno); stream->connection_cb((uv_stream_t*)stream, -1); } } else { @@ -199,7 +199,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(server->loop, EAGAIN); + uv__set_sys_error(server->loop, EAGAIN); goto out; } @@ -272,12 +272,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(stream->loop, errno); + uv__set_sys_error(stream->loop, errno); if (req->cb) { req->cb(req, -1); } } else { - uv_err_new(stream->loop, 0); + uv__set_sys_error(stream->loop, 0); ((uv_handle_t*) stream)->flags |= UV_SHUT; if (req->cb) { req->cb(req, 0); @@ -428,7 +428,7 @@ static void uv__write_callbacks(uv_stream_t* stream) { /* NOTE: call callback AFTER freeing the request data. */ if (req->cb) { - uv_err_new_artificial(stream->loop, req->error); + uv__set_artificial_error(stream->loop, req->error); req->cb(req, req->error ? -1 : 0); } @@ -472,19 +472,19 @@ static void uv__read(uv_stream_t* stream) { if (stream->flags & UV_READING) { ev_io_start(ev, &stream->read_watcher); } - uv_err_new(stream->loop, EAGAIN); + uv__set_sys_error(stream->loop, EAGAIN); stream->read_cb(stream, 0, buf); return; } else { /* Error. User should call uv_close(). */ - uv_err_new(stream->loop, errno); + uv__set_sys_error(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(stream->loop, UV_EOF); + uv__set_artificial_error(stream->loop, UV_EOF); ev_io_stop(ev, &stream->read_watcher); stream->read_cb(stream, -1, buf); return; @@ -505,7 +505,7 @@ 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(stream->loop, EINVAL); + uv__set_sys_error(stream->loop, EINVAL); return -1; } @@ -593,7 +593,7 @@ static void uv__stream_connect(uv_stream_t* stream) { return; } else { /* Error */ - uv_err_new(stream->loop, error); + uv__set_sys_error(stream->loop, error); stream->connect_req = NULL; if (req->cb) { @@ -610,7 +610,7 @@ int uv__connect(uv_connect_t* req, uv_stream_t* stream, struct sockaddr* addr, if (stream->fd <= 0) { if ((sockfd = uv__socket(addr->sa_family, SOCK_STREAM, 0)) == -1) { - uv_err_new(stream->loop, errno); + uv__set_sys_error(stream->loop, errno); return -1; } @@ -627,12 +627,12 @@ int uv__connect(uv_connect_t* req, uv_stream_t* stream, struct sockaddr* addr, ngx_queue_init(&req->queue); if (stream->connect_req) { - uv_err_new(stream->loop, EALREADY); + uv__set_sys_error(stream->loop, EALREADY); return -1; } if (stream->type != UV_TCP) { - uv_err_new(stream->loop, ENOTSOCK); + uv__set_sys_error(stream->loop, ENOTSOCK); return -1; } @@ -656,7 +656,7 @@ int uv__connect(uv_connect_t* req, uv_stream_t* stream, struct sockaddr* addr, break; default: - uv_err_new(stream->loop, errno); + uv__set_sys_error(stream->loop, errno); return -1; } } @@ -684,7 +684,7 @@ int uv_write(uv_write_t* req, uv_stream_t* stream, uv_buf_t bufs[], int bufcnt, "uv_write (unix) does not yet support other types of streams"); if (stream->fd < 0) { - uv_err_new(stream->loop, EBADF); + uv__set_sys_error(stream->loop, EBADF); return -1; } @@ -742,7 +742,7 @@ int uv_read_start(uv_stream_t* stream, uv_alloc_cb alloc_cb, uv_read_cb read_cb) stream->type == UV_TTY); if (stream->flags & UV_CLOSING) { - uv_err_new(stream->loop, EINVAL); + uv__set_sys_error(stream->loop, EINVAL); return -1; } diff --git a/src/unix/sunos.c b/src/unix/sunos.c index 0b5c03b5a6..d80631ea56 100644 --- a/src/unix/sunos.c +++ b/src/unix/sunos.c @@ -67,7 +67,7 @@ int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle, const char* filename, uv_fs_event_cb cb) { - uv_err_new(loop, ENOSYS); + uv__set_sys_error(loop, ENOSYS); return -1; } diff --git a/src/unix/tcp.c b/src/unix/tcp.c index 583cbfd660..162dcce0fc 100644 --- a/src/unix/tcp.c +++ b/src/unix/tcp.c @@ -45,7 +45,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(tcp->loop, errno); + uv__set_sys_error(tcp->loop, errno); goto out; } @@ -64,7 +64,7 @@ static int uv__tcp_bind(uv_tcp_t* tcp, if (errno == EADDRINUSE) { tcp->delayed_error = errno; } else { - uv_err_new(tcp->loop, errno); + uv__set_sys_error(tcp->loop, errno); goto out; } } @@ -78,7 +78,7 @@ static int uv__tcp_bind(uv_tcp_t* tcp, int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) { if (handle->type != UV_TCP || addr.sin_family != AF_INET) { - uv_err_new(handle->loop, EFAULT); + uv__set_sys_error(handle->loop, EFAULT); return -1; } @@ -91,7 +91,7 @@ int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) { int uv_tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr) { if (handle->type != UV_TCP || addr.sin6_family != AF_INET6) { - uv_err_new(handle->loop, EFAULT); + uv__set_sys_error(handle->loop, EFAULT); return -1; } @@ -112,13 +112,13 @@ int uv_tcp_getsockname(uv_tcp_t* handle, struct sockaddr* name, saved_errno = errno; if (handle->delayed_error) { - uv_err_new(handle->loop, handle->delayed_error); + uv__set_sys_error(handle->loop, handle->delayed_error); rv = -1; goto out; } if (handle->fd < 0) { - uv_err_new(handle->loop, EINVAL); + uv__set_sys_error(handle->loop, EINVAL); rv = -1; goto out; } @@ -127,7 +127,7 @@ int uv_tcp_getsockname(uv_tcp_t* handle, struct sockaddr* name, socklen = (socklen_t)*namelen; if (getsockname(handle->fd, name, &socklen) == -1) { - uv_err_new(handle->loop, errno); + uv__set_sys_error(handle->loop, errno); rv = -1; } else { *namelen = (int)socklen; @@ -149,13 +149,13 @@ int uv_tcp_getpeername(uv_tcp_t* handle, struct sockaddr* name, saved_errno = errno; if (handle->delayed_error) { - uv_err_new(handle->loop, handle->delayed_error); + uv__set_sys_error(handle->loop, handle->delayed_error); rv = -1; goto out; } if (handle->fd < 0) { - uv_err_new(handle->loop, EINVAL); + uv__set_sys_error(handle->loop, EINVAL); rv = -1; goto out; } @@ -164,7 +164,7 @@ int uv_tcp_getpeername(uv_tcp_t* handle, struct sockaddr* name, socklen = (socklen_t)*namelen; if (getpeername(handle->fd, name, &socklen) == -1) { - uv_err_new(handle->loop, errno); + uv__set_sys_error(handle->loop, errno); rv = -1; } else { *namelen = (int)socklen; @@ -180,13 +180,13 @@ int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) { int r; if (tcp->delayed_error) { - uv_err_new(tcp->loop, tcp->delayed_error); + uv__set_sys_error(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(tcp->loop, errno); + uv__set_sys_error(tcp->loop, errno); return -1; } @@ -201,7 +201,7 @@ 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(tcp->loop, errno); + uv__set_sys_error(tcp->loop, errno); return -1; } @@ -227,7 +227,7 @@ int uv_tcp_connect(uv_connect_t* req, status = -1; if (handle->type != UV_TCP || address.sin_family != AF_INET) { - uv_err_new(handle->loop, EINVAL); + uv__set_sys_error(handle->loop, EINVAL); goto out; } @@ -254,7 +254,7 @@ int uv_tcp_connect6(uv_connect_t* req, status = -1; if (handle->type != UV_TCP || address.sin6_family != AF_INET6) { - uv_err_new(handle->loop, EINVAL); + uv__set_sys_error(handle->loop, EINVAL); goto out; } diff --git a/src/unix/tty.c b/src/unix/tty.c index 989c09d1bf..0a3075a044 100644 --- a/src/unix/tty.c +++ b/src/unix/tty.c @@ -65,7 +65,7 @@ int uv_tty_set_mode(uv_tty_t* tty, int mode) { return 0; fatal: - uv_err_new(tty->loop, ENOTTY); + uv__set_sys_error(tty->loop, ENOTTY); return -1; } @@ -74,7 +74,7 @@ int uv_tty_get_winsize(uv_tty_t* tty, int* width, int* height) { struct winsize ws; if (ioctl(tty->fd, TIOCGWINSZ, &ws) < 0) { - uv_err_new(tty->loop, errno); + uv__set_sys_error(tty->loop, errno); return -1; } @@ -89,7 +89,7 @@ uv_handle_type uv_guess_handle(uv_file file) { struct stat s; if (file < 0) { - uv_err_new(NULL, EINVAL); /* XXX Need loop? */ + uv__set_sys_error(NULL, EINVAL); /* XXX Need loop? */ return -1; } @@ -98,7 +98,7 @@ uv_handle_type uv_guess_handle(uv_file file) { } if (fstat(file, &s)) { - uv_err_new(NULL, errno); /* XXX Need loop? */ + uv__set_sys_error(NULL, errno); /* XXX Need loop? */ return -1; } diff --git a/src/unix/udp.c b/src/unix/udp.c index 84e4510728..e8a772af71 100644 --- a/src/unix/udp.c +++ b/src/unix/udp.c @@ -84,7 +84,7 @@ 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(handle->loop, UV_EINTR); + uv__set_artificial_error(handle->loop, UV_EINTR); req->send_cb(req, -1); } } @@ -187,7 +187,7 @@ static void uv__udp_run_completed(uv_udp_t* handle) { req->send_cb(req, 0); } else { - uv_err_new(handle->loop, -req->status); + uv__set_sys_error(handle->loop, -req->status); req->send_cb(req, -1); } } @@ -223,11 +223,11 @@ static void uv__udp_recvmsg(uv_udp_t* handle) { if (nread == -1) { if (errno == EAGAIN || errno == EWOULDBLOCK) { - uv_err_new(handle->loop, EAGAIN); + uv__set_sys_error(handle->loop, EAGAIN); handle->recv_cb(handle, 0, buf, NULL, 0); } else { - uv_err_new(handle->loop, errno); + uv__set_sys_error(handle->loop, errno); handle->recv_cb(handle, -1, buf, NULL, 0); } } @@ -305,24 +305,24 @@ static int uv__udp_bind(uv_udp_t* handle, /* Check for bad flags. */ if (flags & ~UV_UDP_IPV6ONLY) { - uv_err_new(handle->loop, EINVAL); + uv__set_sys_error(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(handle->loop, EINVAL); + uv__set_sys_error(handle->loop, EINVAL); goto out; } /* Check for already active socket. */ if (handle->fd != -1) { - uv_err_new_artificial(handle->loop, UV_EALREADY); + uv__set_artificial_error(handle->loop, UV_EALREADY); goto out; } if ((fd = uv__socket(domain, SOCK_DGRAM, 0)) == -1) { - uv_err_new(handle->loop, errno); + uv__set_sys_error(handle->loop, errno); goto out; } @@ -330,17 +330,17 @@ 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(handle->loop, errno); + uv__set_sys_error(handle->loop, errno); goto out; } #else - uv_err_new((uv_handle_t*)handle, ENOTSUP); + uv__set_sys_error((uv_handle_t*)handle, ENOTSUP); goto out; #endif } if (bind(fd, addr, len) == -1) { - uv_err_new(handle->loop, errno); + uv__set_sys_error(handle->loop, errno); goto out; } @@ -417,7 +417,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(handle->loop, ENOMEM); + uv__set_sys_error(handle->loop, ENOMEM); return -1; } memcpy(req->bufs, bufs, bufcnt * sizeof(bufs[0])); @@ -445,7 +445,7 @@ int uv_udp_init(uv_loop_t* loop, uv_udp_t* handle) { int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr, unsigned flags) { if (handle->type != UV_UDP || addr.sin_family != AF_INET) { - uv_err_new(handle->loop, EFAULT); + uv__set_sys_error(handle->loop, EFAULT); return -1; } @@ -459,7 +459,7 @@ int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr, unsigned flags) { int uv_udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr, unsigned flags) { if (handle->type != UV_UDP || addr.sin6_family != AF_INET6) { - uv_err_new(handle->loop, EFAULT); + uv__set_sys_error(handle->loop, EFAULT); return -1; } @@ -481,7 +481,7 @@ int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name, saved_errno = errno; if (handle->fd < 0) { - uv_err_new(handle->loop, EINVAL); + uv__set_sys_error(handle->loop, EINVAL); rv = -1; goto out; } @@ -490,7 +490,7 @@ int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name, socklen = (socklen_t)*namelen; if (getsockname(handle->fd, name, &socklen) == -1) { - uv_err_new(handle->loop, errno); + uv__set_sys_error(handle->loop, errno); rv = -1; } else { *namelen = (int)socklen; @@ -538,12 +538,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(handle->loop, UV_EINVAL); + uv__set_artificial_error(handle->loop, UV_EINVAL); return -1; } if (ev_is_active(&handle->read_watcher)) { - uv_err_new_artificial(handle->loop, UV_EALREADY); + uv__set_artificial_error(handle->loop, UV_EALREADY); return -1; } diff --git a/src/uv-common.c b/src/uv-common.c index 51188337bd..583ad20116 100644 --- a/src/uv-common.c +++ b/src/uv-common.c @@ -95,6 +95,24 @@ const char* uv_err_name(uv_err_t err) { } +void uv__set_error(uv_loop_t* loop, uv_err_code code, int sys_error) { + loop->last_err.code = code; + loop->last_err.sys_errno_ = sys_error; +} + + +void uv__set_sys_error(uv_loop_t* loop, int sys_error) { + loop->last_err.code = uv_translate_sys_error(sys_error); + loop->last_err.sys_errno_ = sys_error; +} + + +void uv__set_artificial_error(uv_loop_t* loop, uv_err_code code) { + loop->last_err.code = code; + loop->last_err.sys_errno_ = 0; +} + + struct sockaddr_in uv_ip4_addr(const char* ip, int port) { struct sockaddr_in addr; diff --git a/src/uv-common.h b/src/uv-common.h index ae54319556..f534d0e197 100644 --- a/src/uv-common.h +++ b/src/uv-common.h @@ -48,5 +48,9 @@ void uv_add_ares_handle(uv_loop_t* loop, uv_ares_task_t* handle); int uv_ares_handles_empty(uv_loop_t* loop); +uv_err_code uv_translate_sys_error(int sys_errno); +void uv__set_error(uv_loop_t* loop, uv_err_code code, int sys_error); +void uv__set_sys_error(uv_loop_t* loop, int sys_error); +void uv__set_artificial_error(uv_loop_t* loop, uv_err_code code); #endif /* UV_COMMON_H_ */ diff --git a/src/win/error.c b/src/win/error.c index 0ed2e16abe..fbbf404b91 100644 --- a/src/win/error.c +++ b/src/win/error.c @@ -143,15 +143,3 @@ uv_err_t uv_new_sys_error(int sys_errno) { e.sys_errno_ = sys_errno; return e; } - - -void uv_set_sys_error(uv_loop_t* loop, int sys_errno) { - loop->last_error.code = uv_translate_sys_error(sys_errno); - loop->last_error.sys_errno_ = sys_errno; -} - - -void uv_set_error(uv_loop_t* loop, uv_err_code code, int sys_errno) { - loop->last_error.code = code; - loop->last_error.sys_errno_ = sys_errno; -} diff --git a/src/win/fs-event.c b/src/win/fs-event.c index a68dfe00de..1ae1c608fe 100644 --- a/src/win/fs-event.c +++ b/src/win/fs-event.c @@ -144,7 +144,7 @@ int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle, if (!uv_utf8_to_utf16(filename, filenamew, name_size / sizeof(wchar_t))) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); return -1; } @@ -252,7 +252,7 @@ int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle, handle->buffer = NULL; } - uv_set_sys_error(loop, last_error); + uv__set_sys_error(loop, last_error); return -1; } diff --git a/src/win/fs.c b/src/win/fs.c index 93fa5eb36b..b6a9a5a383 100644 --- a/src/win/fs.c +++ b/src/win/fs.c @@ -66,7 +66,7 @@ if (!QueueUserWorkItem(&uv_fs_thread_proc, \ req, \ WT_EXECUTELONGFUNCTION)) { \ - uv_set_sys_error((loop), GetLastError()); \ + uv__set_sys_error((loop), GetLastError()); \ return -1; \ } \ req->flags |= UV_FS_ASYNC_QUEUED; \ @@ -75,7 +75,7 @@ #define SET_UV_LAST_ERROR_FROM_REQ(req) \ if (req->flags & UV_FS_LAST_ERROR_SET) { \ - uv_set_sys_error(req->loop, req->last_error); \ + uv__set_sys_error(req->loop, req->last_error); \ } #define SET_REQ_LAST_ERROR(req, error) \ diff --git a/src/win/getaddrinfo.c b/src/win/getaddrinfo.c index 1416f04d62..f0d854216b 100644 --- a/src/win/getaddrinfo.c +++ b/src/win/getaddrinfo.c @@ -256,7 +256,7 @@ int uv_getaddrinfo(uv_loop_t* loop, if (handle == NULL || getaddrinfo_cb == NULL || (node == NULL && service == NULL)) { - uv_set_sys_error(loop, WSAEINVAL); + uv__set_sys_error(loop, WSAEINVAL); goto error; } @@ -271,7 +271,7 @@ int uv_getaddrinfo(uv_loop_t* loop, if (node != NULL) { nodesize = ALIGNED_SIZE(uv_utf8_to_utf16(node, NULL, 0) * sizeof(wchar_t)); if (nodesize == 0) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); goto error; } } @@ -280,7 +280,7 @@ int uv_getaddrinfo(uv_loop_t* loop, servicesize = ALIGNED_SIZE(uv_utf8_to_utf16(service, NULL, 0) * sizeof(wchar_t)); if (servicesize == 0) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); goto error; } } @@ -291,7 +291,7 @@ int uv_getaddrinfo(uv_loop_t* loop, /* allocate memory for inputs, and partition it as needed */ alloc_ptr = (char*)malloc(nodesize + servicesize + hintssize); if (!alloc_ptr) { - uv_set_sys_error(loop, WSAENOBUFS); + uv__set_sys_error(loop, WSAENOBUFS); goto error; } @@ -305,7 +305,7 @@ int uv_getaddrinfo(uv_loop_t* loop, if (uv_utf8_to_utf16(node, (wchar_t*) alloc_ptr, nodesize / sizeof(wchar_t)) == 0) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); goto error; } alloc_ptr += nodesize; @@ -320,7 +320,7 @@ int uv_getaddrinfo(uv_loop_t* loop, if (uv_utf8_to_utf16(service, (wchar_t*) alloc_ptr, servicesize / sizeof(wchar_t)) == 0) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); goto error; } alloc_ptr += servicesize; @@ -352,7 +352,7 @@ int uv_getaddrinfo(uv_loop_t* loop, if (QueueUserWorkItem(&getaddrinfo_thread_proc, handle, WT_EXECUTELONGFUNCTION) == 0) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); goto error; } diff --git a/src/win/internal.h b/src/win/internal.h index fa20e4660c..f3fa4abdfe 100644 --- a/src/win/internal.h +++ b/src/win/internal.h @@ -275,9 +275,6 @@ extern const uv_err_t uv_ok_; void uv_fatal_error(const int errorno, const char* syscall); uv_err_code uv_translate_sys_error(int sys_errno); -uv_err_t uv_new_sys_error(int sys_errno); -void uv_set_sys_error(uv_loop_t* loop, int sys_errno); -void uv_set_error(uv_loop_t* loop, uv_err_code code, int sys_errno); #define SET_REQ_STATUS(req, status) \ (req)->overlapped.Internal = (ULONG_PTR) (status) diff --git a/src/win/pipe.c b/src/win/pipe.c index 8d7891539a..c93043af26 100644 --- a/src/win/pipe.c +++ b/src/win/pipe.c @@ -111,7 +111,7 @@ int uv_stdio_pipe_server(uv_loop_t* loop, uv_pipe_t* handle, DWORD access, errno = GetLastError(); if (errno != ERROR_PIPE_BUSY && errno != ERROR_ACCESS_DENIED) { - uv_set_sys_error(loop, errno); + uv__set_sys_error(loop, errno); err = -1; goto done; } @@ -124,7 +124,7 @@ int uv_stdio_pipe_server(uv_loop_t* loop, uv_pipe_t* handle, DWORD access, loop->iocp, (ULONG_PTR)handle, 0) == NULL) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); err = -1; goto done; } @@ -209,7 +209,7 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) { /* Failure */ handle->flags &= ~UV_HANDLE_SHUTTING; if (req->cb) { - uv_set_sys_error(loop, pRtlNtStatusToDosError(nt_status)); + uv__set_sys_error(loop, pRtlNtStatusToDosError(nt_status)); req->cb(req, -1); } DECREASE_PENDING_REQ_COUNT(handle); @@ -237,7 +237,7 @@ void uv_pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) { /* Failure. */ handle->flags &= ~UV_HANDLE_SHUTTING; if (req->cb) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); req->cb(req, -1); } DECREASE_PENDING_REQ_COUNT(handle); @@ -274,12 +274,12 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) { uv_pipe_accept_t* req; if (handle->flags & UV_HANDLE_BOUND) { - uv_set_sys_error(loop, WSAEINVAL); + uv__set_sys_error(loop, WSAEINVAL); return -1; } if (!name) { - uv_set_sys_error(loop, WSAEINVAL); + uv__set_sys_error(loop, WSAEINVAL); return -1; } @@ -300,7 +300,7 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) { } if (!uv_utf8_to_utf16(name, handle->name, nameSize / sizeof(wchar_t))) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); return -1; } @@ -317,17 +317,17 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) { if (handle->accept_reqs[0].pipeHandle == INVALID_HANDLE_VALUE) { errno = GetLastError(); if (errno == ERROR_ACCESS_DENIED) { - uv_set_error(loop, UV_EADDRINUSE, errno); + uv__set_error(loop, UV_EADDRINUSE, errno); } else if (errno == ERROR_PATH_NOT_FOUND || errno == ERROR_INVALID_NAME) { - uv_set_error(loop, UV_EACCESS, errno); + uv__set_error(loop, UV_EACCESS, errno); } else { - uv_set_sys_error(loop, errno); + uv__set_sys_error(loop, errno); } goto error; } if (uv_set_pipe_handle(loop, handle, handle->accept_reqs[0].pipeHandle)) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); goto error; } @@ -473,7 +473,7 @@ int uv_pipe_connect(uv_connect_t* req, uv_pipe_t* handle, if (pipeHandle != INVALID_HANDLE_VALUE) { CloseHandle(pipeHandle); } - uv_set_sys_error(loop, errno); + uv__set_sys_error(loop, errno); return -1; } @@ -575,7 +575,7 @@ int uv_pipe_accept(uv_pipe_t* server, uv_pipe_t* client) { if (!req) { /* No valid connections found, so we error out. */ - uv_set_sys_error(loop, WSAEWOULDBLOCK); + uv__set_sys_error(loop, WSAEWOULDBLOCK); return -1; } @@ -607,19 +607,19 @@ int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) { if (!(handle->flags & UV_HANDLE_BOUND) && !(handle->flags & UV_HANDLE_GIVEN_OS_HANDLE)) { - uv_set_error(loop, UV_EINVAL, 0); + uv__set_artificial_error(loop, UV_EINVAL); return -1; } if (handle->flags & UV_HANDLE_LISTENING || handle->flags & UV_HANDLE_READING) { - uv_set_error(loop, UV_EALREADY, 0); + uv__set_artificial_error(loop, UV_EALREADY); return -1; } if (!(handle->flags & UV_HANDLE_PIPESERVER) && !(handle->flags & UV_HANDLE_GIVEN_OS_HANDLE)) { - uv_set_error(loop, UV_ENOTSUP, 0); + uv__set_artificial_error(loop, UV_ENOTSUP); return -1; } @@ -638,7 +638,7 @@ int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) { req->next_pending = NULL; if (uv_set_pipe_handle(loop, handle, pipeHandle)) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); return -1; } @@ -698,17 +698,17 @@ int uv_pipe_read_start(uv_pipe_t* handle, uv_alloc_cb alloc_cb, uv_loop_t* loop = handle->loop; if (!(handle->flags & UV_HANDLE_CONNECTION)) { - uv_set_error(loop, UV_EINVAL, 0); + uv__set_artificial_error(loop, UV_EINVAL); return -1; } if (handle->flags & UV_HANDLE_READING) { - uv_set_error(loop, UV_EALREADY, 0); + uv__set_artificial_error(loop, UV_EALREADY); return -1; } if (handle->flags & UV_HANDLE_EOF) { - uv_set_error(loop, UV_EOF, 0); + uv__set_artificial_error(loop, UV_EOF); return -1; } @@ -730,19 +730,19 @@ int uv_pipe_write(uv_loop_t* loop, uv_write_t* req, uv_pipe_t* handle, int result; if (bufcnt != 1) { - uv_set_error(loop, UV_ENOTSUP, 0); + uv__set_artificial_error(loop, UV_ENOTSUP); return -1; } assert(handle->handle != INVALID_HANDLE_VALUE); if (!(handle->flags & UV_HANDLE_CONNECTION)) { - uv_set_error(loop, UV_EINVAL, 0); + uv__set_artificial_error(loop, UV_EINVAL); return -1; } if (handle->flags & UV_HANDLE_SHUTTING) { - uv_set_error(loop, UV_EOF, 0); + uv__set_artificial_error(loop, UV_EOF); return -1; } @@ -759,7 +759,7 @@ int uv_pipe_write(uv_loop_t* loop, uv_write_t* req, uv_pipe_t* handle, &req->overlapped); if (!result && GetLastError() != ERROR_IO_PENDING) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); return -1; } @@ -788,7 +788,7 @@ static void uv_pipe_read_eof(uv_loop_t* loop, uv_pipe_t* handle, handle->flags |= UV_HANDLE_EOF; uv_read_stop((uv_stream_t*) handle); - uv_set_error(loop, UV_EOF, 0); + uv__set_artificial_error(loop, UV_EOF); handle->read_cb((uv_stream_t*) handle, -1, uv_null_buf_); } @@ -801,7 +801,7 @@ static void uv_pipe_read_error(uv_loop_t* loop, uv_pipe_t* handle, int error, uv_read_stop((uv_stream_t*) handle); - uv_set_sys_error(loop, error); + uv__set_sys_error(loop, error); handle->read_cb((uv_stream_t*)handle, -1, buf); } diff --git a/src/win/process.c b/src/win/process.c index ed8015e0ef..4db0483251 100644 --- a/src/win/process.c +++ b/src/win/process.c @@ -45,7 +45,7 @@ typedef struct env_var { uv_fatal_error(ERROR_OUTOFMEMORY, "malloc"); \ } \ if (!uv_utf8_to_utf16(s, t, size / sizeof(wchar_t))) { \ - uv_set_sys_error(loop, GetLastError()); \ + uv__set_sys_error(loop, GetLastError()); \ err = -1; \ goto done; \ } @@ -746,7 +746,7 @@ static int uv_create_stdio_pipe_pair(uv_loop_t* loop, uv_pipe_t* server_pipe, DWORD mode = PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT; if (server_pipe->type != UV_NAMED_PIPE) { - uv_set_error(loop, UV_EINVAL, 0); + uv__set_artificial_error(loop, UV_EINVAL); err = -1; goto done; } @@ -771,13 +771,13 @@ static int uv_create_stdio_pipe_pair(uv_loop_t* loop, uv_pipe_t* server_pipe, NULL); if (*child_pipe == INVALID_HANDLE_VALUE) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); err = -1; goto done; } if (!SetNamedPipeHandleState(*child_pipe, &mode, NULL, NULL)) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); err = -1; goto done; } @@ -787,7 +787,7 @@ static int uv_create_stdio_pipe_pair(uv_loop_t* loop, uv_pipe_t* server_pipe, */ if (!ConnectNamedPipe(server_pipe->handle, NULL)) { if (GetLastError() != ERROR_PIPE_CONNECTED) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); err = -1; goto done; } @@ -822,7 +822,7 @@ static int duplicate_std_handle(uv_loop_t* loop, DWORD id, HANDLE* dup) { return 0; } else if (handle == INVALID_HANDLE_VALUE) { *dup = INVALID_HANDLE_VALUE; - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); return -1; } @@ -834,7 +834,7 @@ static int duplicate_std_handle(uv_loop_t* loop, DWORD id, HANDLE* dup) { TRUE, DUPLICATE_SAME_ACCESS)) { *dup = INVALID_HANDLE_VALUE; - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); return -1; } @@ -854,7 +854,7 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process, PROCESS_INFORMATION info; if (!options.file) { - uv_set_error(loop, UV_EINVAL, 0); + uv__set_artificial_error(loop, UV_EINVAL); return -1; } @@ -877,7 +877,7 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process, } GetCurrentDirectoryW(size, cwd); } else { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); err = -1; goto done; } diff --git a/src/win/stdio.c b/src/win/stdio.c index 30fe2a1d6e..b65e7fb544 100644 --- a/src/win/stdio.c +++ b/src/win/stdio.c @@ -69,7 +69,7 @@ uv_stream_t* uv_std_handle(uv_loop_t* loop, uv_std_type type) { default: assert(0); - uv_set_error(loop, UV_EINVAL, 0); + uv__set_artificial_error(loop, UV_EINVAL); return NULL; } } diff --git a/src/win/stream.c b/src/win/stream.c index 27139016a6..c38e06bb2a 100644 --- a/src/win/stream.c +++ b/src/win/stream.c @@ -115,7 +115,7 @@ int uv_write(uv_write_t* req, uv_stream_t* handle, uv_buf_t bufs[], int bufcnt, return uv_tty_write(loop, req, (uv_tty_t*) handle, bufs, bufcnt, cb); default: assert(0); - uv_set_sys_error(loop, WSAEINVAL); + uv__set_sys_error(loop, WSAEINVAL); return -1; } } @@ -125,12 +125,12 @@ int uv_shutdown(uv_shutdown_t* req, uv_stream_t* handle, uv_shutdown_cb cb) { uv_loop_t* loop = handle->loop; if (!(handle->flags & UV_HANDLE_CONNECTION)) { - uv_set_sys_error(loop, WSAEINVAL); + uv__set_sys_error(loop, WSAEINVAL); return -1; } if (handle->flags & UV_HANDLE_SHUTTING) { - uv_set_sys_error(loop, WSAESHUTDOWN); + uv__set_sys_error(loop, WSAESHUTDOWN); return -1; } diff --git a/src/win/tcp.c b/src/win/tcp.c index c4989e1165..6e42f2282d 100644 --- a/src/win/tcp.c +++ b/src/win/tcp.c @@ -54,13 +54,13 @@ static int uv_tcp_set_socket(uv_loop_t* loop, uv_tcp_t* handle, /* Set the socket to nonblocking mode */ if (ioctlsocket(socket, FIONBIO, &yes) == SOCKET_ERROR) { - uv_set_sys_error(loop, WSAGetLastError()); + uv__set_sys_error(loop, WSAGetLastError()); return -1; } /* Make the socket non-inheritable */ if (!SetHandleInformation((HANDLE)socket, HANDLE_FLAG_INHERIT, 0)) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); return -1; } @@ -70,7 +70,7 @@ static int uv_tcp_set_socket(uv_loop_t* loop, uv_tcp_t* handle, loop->iocp, (ULONG_PTR)socket, 0) == NULL) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); return -1; } @@ -80,7 +80,7 @@ static int uv_tcp_set_socket(uv_loop_t* loop, uv_tcp_t* handle, FILE_SKIP_COMPLETION_PORT_ON_SUCCESS)) { handle->flags |= UV_HANDLE_SYNC_BYPASS_IOCP; } else if (GetLastError() != ERROR_INVALID_FUNCTION) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); return -1; } } @@ -107,8 +107,8 @@ int uv_tcp_init(uv_loop_t* loop, uv_tcp_t* handle) { void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle) { - uv_err_t err; int status; + int sys_error; if (handle->flags & UV_HANDLE_CONNECTION && handle->flags & UV_HANDLE_SHUTTING && @@ -120,11 +120,11 @@ void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle) { handle->flags |= UV_HANDLE_SHUT; } else { status = -1; - err = uv_new_sys_error(WSAGetLastError()); + sys_error = WSAGetLastError(); } if (handle->shutdown_req->cb) { if (status == -1) { - loop->last_error = err; + uv__set_sys_error(sys_error); } handle->shutdown_req->cb(handle->shutdown_req, status); } @@ -163,7 +163,7 @@ static int uv__bind(uv_loop_t* loop, uv_tcp_t* handle, int domain, if (handle->socket == INVALID_SOCKET) { sock = socket(domain, SOCK_STREAM, 0); if (sock == INVALID_SOCKET) { - uv_set_sys_error(loop, WSAGetLastError()); + uv__set_sys_error(loop, WSAGetLastError()); return -1; } @@ -179,10 +179,10 @@ static int uv__bind(uv_loop_t* loop, uv_tcp_t* handle, int domain, err = WSAGetLastError(); if (err == WSAEADDRINUSE) { /* Some errors are not to be reported until connect() or listen() */ - handle->bind_error = uv_new_sys_error(err); + handle->bind_error = err; handle->flags |= UV_HANDLE_BIND_ERROR; } else { - uv_set_sys_error(loop, err); + uv__set_sys_error(loop, err); return -1; } } @@ -197,7 +197,7 @@ int uv_tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr) { uv_loop_t* loop = handle->loop; if (handle->type != UV_TCP || addr.sin_family != AF_INET) { - uv_set_sys_error(loop, WSAEFAULT); + uv__set_sys_error(loop, WSAEFAULT); return -1; } @@ -213,7 +213,7 @@ int uv_tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr) { uv_loop_t* loop = handle->loop; if (handle->type != UV_TCP || addr.sin6_family != AF_INET6) { - uv_set_sys_error(loop, WSAEFAULT); + uv__set_sys_error(loop, WSAEFAULT); return -1; } @@ -226,7 +226,7 @@ int uv_tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr) { sizeof(struct sockaddr_in6)); } else { - uv_set_sys_error(loop, WSAEAFNOSUPPORT); + uv__set_sys_error(loop, WSAEAFNOSUPPORT); return -1; } } @@ -356,14 +356,14 @@ int uv_tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb) { assert(backlog > 0); if (handle->flags & UV_HANDLE_BIND_ERROR) { - loop->last_error = handle->bind_error; + uv__set_sys_error(handle->bind_error); return -1; } if (handle->flags & UV_HANDLE_LISTENING || handle->flags & UV_HANDLE_READING) { /* Already listening. */ - uv_set_sys_error(loop, WSAEALREADY); + uv__set_sys_error(loop, WSAEALREADY); return -1; } @@ -372,7 +372,7 @@ int uv_tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb) { return -1; if (listen(handle->socket, backlog) == SOCKET_ERROR) { - uv_set_sys_error(loop, WSAGetLastError()); + uv__set_sys_error(loop, WSAGetLastError()); return -1; } @@ -407,12 +407,12 @@ int uv_tcp_accept(uv_tcp_t* server, uv_tcp_t* client) { if (!req) { /* No valid connections found, so we error out. */ - uv_set_sys_error(loop, WSAEWOULDBLOCK); + uv__set_sys_error(loop, WSAEWOULDBLOCK); return -1; } if (req->accept_socket == INVALID_SOCKET) { - uv_set_sys_error(loop, WSAENOTCONN); + uv__set_sys_error(loop, WSAENOTCONN); return -1; } @@ -445,17 +445,17 @@ int uv_tcp_read_start(uv_tcp_t* handle, uv_alloc_cb alloc_cb, uv_loop_t* loop = handle->loop; if (!(handle->flags & UV_HANDLE_CONNECTION)) { - uv_set_sys_error(loop, WSAEINVAL); + uv__set_sys_error(loop, WSAEINVAL); return -1; } if (handle->flags & UV_HANDLE_READING) { - uv_set_sys_error(loop, WSAEALREADY); + uv__set_sys_error(loop, WSAEALREADY); return -1; } if (handle->flags & UV_HANDLE_EOF) { - uv_set_sys_error(loop, WSAESHUTDOWN); + uv__set_sys_error(loop, WSAESHUTDOWN); return -1; } @@ -480,12 +480,12 @@ int uv_tcp_connect(uv_connect_t* req, uv_tcp_t* handle, DWORD bytes; if (handle->flags & UV_HANDLE_BIND_ERROR) { - loop->last_error = handle->bind_error; + uv__set_sys_error(handle->bind_error); return -1; } if (handle->type != UV_TCP || address.sin_family != AF_INET) { - uv_set_sys_error(loop, WSAEFAULT); + uv__set_sys_error(loop, WSAEFAULT); return -1; } @@ -515,7 +515,7 @@ int uv_tcp_connect(uv_connect_t* req, uv_tcp_t* handle, /* The req will be processed with IOCP. */ handle->reqs_pending++; } else { - uv_set_sys_error(loop, WSAGetLastError()); + uv__set_sys_error(loop, WSAGetLastError()); return -1; } @@ -536,12 +536,12 @@ int uv_tcp_connect6(uv_connect_t* req, uv_tcp_t* handle, } if (handle->flags & UV_HANDLE_BIND_ERROR) { - loop->last_error = handle->bind_error; + uv__set_sys_error(handle->bind_error); return -1; } if (handle->type != UV_TCP || address.sin6_family != AF_INET6) { - uv_set_sys_error(loop, WSAEFAULT); + uv__set_sys_error(loop, WSAEFAULT); return -1; } @@ -569,7 +569,7 @@ int uv_tcp_connect6(uv_connect_t* req, uv_tcp_t* handle, } else if (UV_SUCCEEDED_WITH_IOCP(success)) { handle->reqs_pending++; } else { - uv_set_sys_error(loop, WSAGetLastError()); + uv__set_sys_error(loop, WSAGetLastError()); return -1; } @@ -583,18 +583,18 @@ int uv_tcp_getsockname(uv_tcp_t* handle, struct sockaddr* name, int result; if (!(handle->flags & UV_HANDLE_BOUND)) { - uv_set_sys_error(loop, WSAEINVAL); + uv__set_sys_error(loop, WSAEINVAL); return -1; } if (handle->flags & UV_HANDLE_BIND_ERROR) { - loop->last_error = handle->bind_error; + uv__set_sys_error(handle->bind_error); return -1; } result = getsockname(handle->socket, name, namelen); if (result != 0) { - uv_set_sys_error(loop, WSAGetLastError()); + uv__set_sys_error(loop, WSAGetLastError()); return -1; } @@ -608,18 +608,18 @@ int uv_tcp_getpeername(uv_tcp_t* handle, struct sockaddr* name, int result; if (!(handle->flags & UV_HANDLE_BOUND)) { - uv_set_sys_error(loop, WSAEINVAL); + uv__set_sys_error(loop, WSAEINVAL); return -1; } if (handle->flags & UV_HANDLE_BIND_ERROR) { - loop->last_error = handle->bind_error; + uv__set_sys_error(handle->bind_error); return -1; } result = getpeername(handle->socket, name, namelen); if (result != 0) { - uv_set_sys_error(loop, WSAGetLastError()); + uv__set_sys_error(loop, WSAGetLastError()); return -1; } @@ -633,12 +633,12 @@ int uv_tcp_write(uv_loop_t* loop, uv_write_t* req, uv_tcp_t* handle, DWORD bytes; if (!(handle->flags & UV_HANDLE_CONNECTION)) { - uv_set_sys_error(loop, WSAEINVAL); + uv__set_sys_error(loop, WSAEINVAL); return -1; } if (handle->flags & UV_HANDLE_SHUTTING) { - uv_set_sys_error(loop, WSAESHUTDOWN); + uv__set_sys_error(loop, WSAESHUTDOWN); return -1; } @@ -670,7 +670,7 @@ int uv_tcp_write(uv_loop_t* loop, uv_write_t* req, uv_tcp_t* handle, handle->write_queue_size += req->queued_bytes; } else { /* Send failed due to an error. */ - uv_set_sys_error(loop, WSAGetLastError()); + uv__set_sys_error(loop, WSAGetLastError()); return -1; } @@ -753,11 +753,11 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle, err = WSAGetLastError(); if (err == WSAEWOULDBLOCK) { /* Read buffer was completely empty, report a 0-byte read. */ - uv_set_sys_error(loop, WSAEWOULDBLOCK); + uv__set_sys_error(loop, WSAEWOULDBLOCK); handle->read_cb((uv_stream_t*)handle, 0, buf); } else { /* Ouch! serious error. */ - uv_set_sys_error(loop, err); + uv__set_sys_error(loop, err); handle->flags &= ~UV_HANDLE_READING; handle->read_cb((uv_stream_t*)handle, -1, buf); } @@ -859,7 +859,7 @@ void uv_process_tcp_connect_req(uv_loop_t* loop, uv_tcp_t* handle, active_tcp_streams++; ((uv_connect_cb)req->cb)(req, 0); } else { - uv_set_sys_error(loop, WSAGetLastError()); + uv__set_sys_error(loop, WSAGetLastError()); ((uv_connect_cb)req->cb)(req, -1); } } else { diff --git a/src/win/threadpool.c b/src/win/threadpool.c index c40613e1f5..4fb20d34bc 100644 --- a/src/win/threadpool.c +++ b/src/win/threadpool.c @@ -57,7 +57,7 @@ int uv_queue_work(uv_loop_t* loop, uv_work_t* req, uv_work_cb work_cb, uv_work_req_init(loop, req, work_cb, after_work_cb); if (!QueueUserWorkItem(&uv_work_thread_proc, req, WT_EXECUTELONGFUNCTION)) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); return -1; } diff --git a/src/win/timer.c b/src/win/timer.c index ac20925293..58f2eef05f 100644 --- a/src/win/timer.c +++ b/src/win/timer.c @@ -77,12 +77,12 @@ uint64_t uv_hrtime(void) { /* If the performance frequency is zero, there's no support. */ if (!uv_hrtime_frequency_) { - /* uv_set_sys_error(loop, ERROR_NOT_SUPPORTED); */ + /* uv__set_sys_error(loop, ERROR_NOT_SUPPORTED); */ return 0; } if (!QueryPerformanceCounter(&counter)) { - /* uv_set_sys_error(loop, GetLastError()); */ + /* uv__set_sys_error(loop, GetLastError()); */ return 0; } @@ -181,7 +181,7 @@ int uv_timer_again(uv_timer_t* handle) { /* If timer_cb is NULL that means that the timer was never started. */ if (!handle->timer_cb) { - uv_set_sys_error(loop, ERROR_INVALID_DATA); + uv__set_sys_error(loop, ERROR_INVALID_DATA); return -1; } diff --git a/src/win/tty.c b/src/win/tty.c index 1a4bf11a33..1a944691fc 100644 --- a/src/win/tty.c +++ b/src/win/tty.c @@ -92,12 +92,12 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, uv_file fd) { win_handle = (HANDLE) _get_osfhandle(fd); if (win_handle == INVALID_HANDLE_VALUE) { - uv_set_sys_error(loop, ERROR_INVALID_HANDLE); + uv__set_sys_error(loop, ERROR_INVALID_HANDLE); return -1; } if (!GetConsoleMode(win_handle, &tty->original_console_mode)) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); return -1; } @@ -163,7 +163,7 @@ int uv_tty_set_mode(uv_tty_t* tty, int mode) { } if (!SetConsoleMode(tty->handle, flags)) { - uv_set_sys_error(tty->loop, GetLastError()); + uv__set_sys_error(tty->loop, GetLastError()); return -1; } @@ -203,7 +203,7 @@ int uv_tty_get_winsize(uv_tty_t* tty, int* width, int* height) { CONSOLE_SCREEN_BUFFER_INFO info; if (!GetConsoleScreenBufferInfo(tty->handle, &info)) { - uv_set_sys_error(tty->loop, GetLastError()); + uv__set_sys_error(tty->loop, GetLastError()); return -1; } @@ -461,7 +461,7 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle, /* Fetch the number of events */ if (!GetNumberOfConsoleInputEvents(handle->handle, &records_left)) { handle->flags &= ~UV_HANDLE_READING; - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); handle->read_cb((uv_stream_t*)handle, -1, uv_null_buf_); goto out; } @@ -479,7 +479,7 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle, &handle->last_input_record, 1, &records_read)) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); handle->flags &= ~UV_HANDLE_READING; handle->read_cb((uv_stream_t*) handle, -1, buf); goto out; @@ -579,7 +579,7 @@ void uv_process_tty_read_raw_req(uv_loop_t* loop, uv_tty_t* handle, /* If the utf16 character(s) couldn't be converted something must */ /* be wrong. */ if (!char_len) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); handle->flags &= ~UV_HANDLE_READING; handle->read_cb((uv_stream_t*) handle, -1, buf); goto out; @@ -693,7 +693,7 @@ void uv_process_tty_read_line_req(uv_loop_t* loop, uv_tty_t* handle, handle->read_cb((uv_stream_t*) handle, -1, buf); } else { /* The read was cancelled, or whatever we don't care */ - uv_set_sys_error(loop, WSAEWOULDBLOCK); /* maps to UV_EAGAIN */ + uv__set_sys_error(loop, WSAEWOULDBLOCK); /* maps to UV_EAGAIN */ handle->read_cb((uv_stream_t*) handle, 0, buf); } @@ -702,7 +702,7 @@ void uv_process_tty_read_line_req(uv_loop_t* loop, uv_tty_t* handle, /* TODO: read unicode, convert to utf-8 */ DWORD bytes = req->overlapped.InternalHigh; if (bytes == 0) { - uv_set_sys_error(loop, WSAEWOULDBLOCK); /* maps to UV_EAGAIN */ + uv__set_sys_error(loop, WSAEWOULDBLOCK); /* maps to UV_EAGAIN */ } handle->read_cb((uv_stream_t*) handle, bytes, buf); } @@ -770,7 +770,7 @@ int uv_tty_read_stop(uv_tty_t* handle) { DWORD written; memset(&record, 0, sizeof record); if (!WriteConsoleInputW(handle->handle, &record, 1, &written)) { - uv_set_sys_error(handle->loop, GetLastError()); + uv__set_sys_error(handle->loop, GetLastError()); return -1; } } diff --git a/src/win/udp.c b/src/win/udp.c index 1d14fb83b3..0e225a2d66 100644 --- a/src/win/udp.c +++ b/src/win/udp.c @@ -46,13 +46,13 @@ int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name, int result; if (!(handle->flags & UV_HANDLE_BOUND)) { - uv_set_sys_error(loop, WSAEINVAL); + uv__set_sys_error(loop, WSAEINVAL); return -1; } result = getsockname(handle->socket, name, namelen); if (result != 0) { - uv_set_sys_error(loop, WSAGetLastError()); + uv__set_sys_error(loop, WSAGetLastError()); return -1; } @@ -68,13 +68,13 @@ static int uv_udp_set_socket(uv_loop_t* loop, uv_udp_t* handle, /* Set the socket to nonblocking mode */ if (ioctlsocket(socket, FIONBIO, &yes) == SOCKET_ERROR) { - uv_set_sys_error(loop, WSAGetLastError()); + uv__set_sys_error(loop, WSAGetLastError()); return -1; } /* Make the socket non-inheritable */ if (!SetHandleInformation((HANDLE)socket, HANDLE_FLAG_INHERIT, 0)) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); return -1; } @@ -84,14 +84,14 @@ static int uv_udp_set_socket(uv_loop_t* loop, uv_udp_t* handle, loop->iocp, (ULONG_PTR)socket, 0) == NULL) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); return -1; } if (pSetFileCompletionNotificationModes) { if (!pSetFileCompletionNotificationModes((HANDLE)socket, FILE_SKIP_SET_EVENT_ON_HANDLE | FILE_SKIP_COMPLETION_PORT_ON_SUCCESS)) { - uv_set_sys_error(loop, GetLastError()); + uv__set_sys_error(loop, GetLastError()); return -1; } @@ -148,14 +148,14 @@ static int uv__bind(uv_udp_t* handle, int domain, struct sockaddr* addr, if ((flags & UV_UDP_IPV6ONLY) && domain != AF_INET6) { /* UV_UDP_IPV6ONLY is supported only for IPV6 sockets */ - uv_set_sys_error(loop, UV_EINVAL); + uv__set_sys_error(loop, UV_EINVAL); return -1; } if (handle->socket == INVALID_SOCKET) { sock = socket(domain, SOCK_DGRAM, 0); if (sock == INVALID_SOCKET) { - uv_set_sys_error(loop, WSAGetLastError()); + uv__set_sys_error(loop, WSAGetLastError()); return -1; } @@ -184,7 +184,7 @@ static int uv__bind(uv_udp_t* handle, int domain, struct sockaddr* addr, if (r == SOCKET_ERROR) { err = WSAGetLastError(); - uv_set_sys_error(loop, WSAGetLastError()); + uv__set_sys_error(loop, WSAGetLastError()); return -1; } @@ -199,7 +199,7 @@ int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr, uv_loop_t* loop = handle->loop; if (handle->type != UV_UDP || addr.sin_family != AF_INET) { - uv_set_sys_error(loop, WSAEFAULT); + uv__set_sys_error(loop, WSAEFAULT); return -1; } @@ -216,7 +216,7 @@ int uv_udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr, uv_loop_t* loop = handle->loop; if (handle->type != UV_UDP || addr.sin6_family != AF_INET6) { - uv_set_sys_error(loop, WSAEFAULT); + uv__set_sys_error(loop, WSAEFAULT); return -1; } @@ -330,7 +330,7 @@ int uv_udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb, uv_loop_t* loop = handle->loop; if (handle->flags & UV_HANDLE_READING) { - uv_set_sys_error(loop, WSAEALREADY); + uv__set_sys_error(loop, WSAEALREADY); return -1; } @@ -396,7 +396,7 @@ static int uv__udp_send(uv_udp_send_t* req, uv_udp_t* handle, uv_buf_t bufs[], handle->reqs_pending++; } else { /* Send failed due to an error. */ - uv_set_sys_error(loop, WSAGetLastError()); + uv__set_sys_error(loop, WSAGetLastError()); return -1; } @@ -510,11 +510,11 @@ void uv_process_udp_recv_req(uv_loop_t* loop, uv_udp_t* handle, } else { err = WSAGetLastError(); if (err == WSAEWOULDBLOCK) { - uv_set_sys_error(loop, WSAEWOULDBLOCK); + uv__set_sys_error(loop, WSAEWOULDBLOCK); handle->recv_cb(handle, 0, buf, NULL, 0); } else { /* Ouch! serious error. */ - uv_set_sys_error(loop, err); + uv__set_sys_error(loop, err); handle->recv_cb(handle, -1, buf, NULL, 0); } } diff --git a/src/win/util.c b/src/win/util.c index 67de53e5c0..c57a72981d 100644 --- a/src/win/util.c +++ b/src/win/util.c @@ -69,7 +69,7 @@ int uv_exepath(char* buffer, size_t* size) { /* Get the path as UTF-16 */ utf16Size = GetModuleFileNameW(NULL, utf16Buffer, *size - 1); if (utf16Size <= 0) { - /* uv_set_sys_error(loop, GetLastError()); */ + /* uv__set_sys_error(loop, GetLastError()); */ retVal = -1; goto done; } @@ -79,7 +79,7 @@ int uv_exepath(char* buffer, size_t* size) { /* Convert to UTF-8 */ *size = uv_utf16_to_utf8(utf16Buffer, utf16Size, buffer, *size); if (!*size) { - /* uv_set_sys_error(loop, GetLastError()); */ + /* uv__set_sys_error(loop, GetLastError()); */ retVal = -1; goto done; }