From 02b43d4ce8b9a40e438704a3b2a384d83abb27e7 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 16 May 2011 21:07:02 -0700 Subject: [PATCH] add uv_err_tostr --- uv-unix.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- uv.h | 2 +- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/uv-unix.c b/uv-unix.c index 730e55e8..8fc6e5d9 100644 --- a/uv-unix.c +++ b/uv-unix.c @@ -1,5 +1,4 @@ /* Copyright Joyent, Inc. and other Node contributors. All rights reserved. - * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to * deal in the Software without restriction, including without limitation the @@ -45,6 +44,50 @@ int uv_tcp_open(uv_handle_t*, int fd); static void uv__finish_close(uv_handle_t* handle); +const char* uv_err_tostr(uv_err_code code) { + switch (code) { + case UV_UNKNOWN: return "UNKNOWN"; + case UV_OK: return "OK"; + case UV_EOF: return "EOF"; + case UV_EACCESS: return "EACCESS"; + case UV_EAGAIN: return "EAGAIN"; + case UV_EADDRINUSE: return "EADDRINUSE"; + case UV_EADDRNOTAVAIL: return "EADDRNOTAVAIL"; + case UV_EAFNOSUPPORT: return "EAFNOSUPPORT"; + case UV_EALREADY: return "EALREADY"; + case UV_EBADF: return "EBADF"; + case UV_EBUSY: return "EBUSY"; + case UV_ECONNABORTED: return "ECONNABORTED"; + case UV_ECONNREFUSED: return "ECONNREFUSED"; + case UV_ECONNRESET: return "ECONNRESET"; + case UV_EDESTADDRREQ: return "EDESTADDRREQ"; + case UV_EFAULT: return "EFAULT"; + case UV_EHOSTUNREACH: return "EHOSTUNREACH"; + case UV_EINTR: return "EINTR"; + case UV_EINVAL: return "EINVAL"; + case UV_EISCONN: return "EISCONN"; + case UV_EMFILE: return "EMFILE"; + case UV_ENETDOWN: return "ENETDOWN"; + case UV_ENETUNREACH: return "ENETUNREACH"; + case UV_ENFILE: return "ENFILE"; + case UV_ENOBUFS: return "ENOBUFS"; + case UV_ENOMEM: return "ENOMEM"; + case UV_ENONET: return "ENONET"; + case UV_ENOPROTOOPT: return "ENOPROTOOPT"; + case UV_ENOTCONN: return "ENOTCONN"; + case UV_ENOTSOCK: return "ENOTSOCK"; + case UV_ENOTSUP: return "ENOTSUP"; + case UV_EPROTO: return "EPROTO"; + case UV_EPROTONOSUPPORT: return "EPROTONOSUPPORT"; + case UV_EPROTOTYPE: return "EPROTOTYPE"; + case UV_ETIMEDOUT: return "ETIMEDOUT"; + default: + assert(0); + return NULL; + } +} + + /* flags */ enum { UV_CLOSING = 0x00000001, /* uv_close() called but not finished. */ diff --git a/uv.h b/uv.h index 5c766e83..2070309c 100644 --- a/uv.h +++ b/uv.h @@ -165,7 +165,7 @@ struct uv_handle_s { */ uv_err_t uv_last_error(); char* uv_strerror(uv_err_t err); - +const char* uv_err_tostr(uv_err_code code); void uv_init(uv_alloc_cb alloc); int uv_run();