Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
unix: have uv_strerror() handle getaddrinfo() errors
  • Loading branch information
bnoordhuis committed Oct 27, 2011
1 parent 314d0ee commit f2c6b41
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion include/uv.h
Expand Up @@ -52,6 +52,7 @@ typedef enum {
UV_UNKNOWN = -1,
UV_OK = 0,
UV_EOF,
UV_EADDRINFO,
UV_EACCESS,
UV_EAGAIN,
UV_EADDRINUSE,
Expand Down Expand Up @@ -261,7 +262,7 @@ struct uv_err_s {
* the error code.
*/
uv_err_t uv_last_error(uv_loop_t*);
char* uv_strerror(uv_err_t err);
const char* uv_strerror(uv_err_t err);
const char* uv_err_name(uv_err_t err);


Expand Down
4 changes: 2 additions & 2 deletions src/unix/core.c
Expand Up @@ -594,8 +594,8 @@ static int uv_getaddrinfo_done(eio_req* req) {
free(handle->hostname);

if (handle->retcode != 0) {
/* TODO how to display gai error strings? */
uv__set_sys_error(handle->loop, handle->retcode);
handle->loop->last_err.code = UV_EADDRINFO;
handle->loop->last_err.sys_errno_ = handle->retcode;
}

handle->cb(handle, handle->retcode, res);
Expand Down
5 changes: 4 additions & 1 deletion src/unix/error.c
Expand Up @@ -118,14 +118,17 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
* a) rely on what the system provides us
* b) reverse-map the error codes
*/
char* uv_strerror(uv_err_t err) {
const char* uv_strerror(uv_err_t err) {
int errorno;

if (err.sys_errno_)
errorno = err.sys_errno_;
else
errorno = uv__translate_lib_error(err.code);

if (err.code == UV_EADDRINFO)
return gai_strerror(errorno);

if (errorno == -1)
return "Unknown error";
else
Expand Down
1 change: 1 addition & 0 deletions src/uv-common.c
Expand Up @@ -53,6 +53,7 @@ const char* uv_err_name(uv_err_t err) {
case UV_UNKNOWN: return "UNKNOWN";
case UV_OK: return "OK";
case UV_EOF: return "EOF";
case UV_EADDRINFO: return "EADDRINFO";
case UV_EACCESS: return "EACCESS";
case UV_EAGAIN: return "EAGAIN";
case UV_EADDRINUSE: return "EADDRINUSE";
Expand Down
2 changes: 1 addition & 1 deletion src/win/error.c
Expand Up @@ -70,7 +70,7 @@ void uv_fatal_error(const int errorno, const char* syscall) {
/* TODO: thread safety */
static char* last_err_str_ = NULL;

char* uv_strerror(uv_err_t err) {
const char* uv_strerror(uv_err_t err) {
if (last_err_str_ != NULL) {
LocalFree(last_err_str_);
}
Expand Down

0 comments on commit f2c6b41

Please sign in to comment.