Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Alternative errno strategy

  • Loading branch information...
commit fd2b04d784d6cc10ca985a5548835310622bda50 1 parent f17d483
@ry ry authored
Showing with 74 additions and 123 deletions.
  1. +56 −50 include/uv.h
  2. +9 −10 src/unix/error.c
  3. +3 −50 src/uv-common.c
  4. +6 −13 src/win/error.c
View
106 include/uv.h
@@ -67,58 +67,64 @@ typedef intptr_t ssize_t;
#endif
/* Expand this list if necessary. */
+#define UV_ERRNO_MAP(XX) \
+ XX( -1, UNKNOWN, "unknown error") \
+ XX( 0, OK, "success") \
+ XX( 1, EOF, "end of file") \
+ XX( 2, EADDRINFO, "getaddrinfo error") \
+ XX( 3, EACCES, "permission denied") \
+ XX( 4, EAGAIN, "no more processes") \
+ XX( 5, EADDRINUSE, "address already in use") \
+ XX( 6, EADDRNOTAVAIL, "") \
+ XX( 7, EAFNOSUPPORT, "") \
+ XX( 8, EALREADY, "") \
+ XX( 9, EBADF, "bad file descriptor") \
+ XX( 10, EBUSY, "mount device busy") \
+ XX( 11, ECONNABORTED, "software caused connection abort") \
+ XX( 12, ECONNREFUSED, "connection refused") \
+ XX( 13, ECONNRESET, "connection reset by peer") \
+ XX( 14, EDESTADDRREQ, "destination address required") \
+ XX( 15, EFAULT, "bad address in system call argument") \
+ XX( 16, EHOSTUNREACH, "host is unreachable") \
+ XX( 17, EINTR, "interrupted system call") \
+ XX( 18, EINVAL, "invalid argument") \
+ XX( 19, EISCONN, "socket is already connected") \
+ XX( 20, EMFILE, "too many open files") \
+ XX( 21, EMSGSIZE, "message too long") \
+ XX( 22, ENETDOWN, "network is down") \
+ XX( 23, ENETUNREACH, "network is unreachable") \
+ XX( 24, ENFILE, "file table overflow") \
+ XX( 25, ENOBUFS, "no buffer space available") \
+ XX( 26, ENOMEM, "not enough memory") \
+ XX( 27, ENOTDIR, "not a directory") \
+ XX( 28, EISDIR, "illegal operation on a directory") \
+ XX( 29, ENONET, "machine is not on the network") \
+ XX( 30, ENOPROTOOPT, "bad proocol option") \
+ XX( 31, ENOTCONN, "socket is not connected") \
+ XX( 32, ENOTSOCK, "socket operation on non-socket") \
+ XX( 33, ENOTSUP, "operation not supported on socket") \
+ XX( 34, ENOENT, "no such file or directory") \
+ XX( 35, ENOSYS, "function not implemented") \
+ XX( 36, EPIPE, "broken pipe") \
+ XX( 37, EPROTO, "protocol error") \
+ XX( 38, EPROTONOSUPPORT, "protocol not suppored") \
+ XX( 39, EPROTOTYPE, "protocol wrong type for socket") \
+ XX( 40, ETIMEDOUT, "connection timed out") \
+ XX( 41, ECHARSET, "") \
+ XX( 42, EAIFAMNOSUPPORT, "") \
+ XX( 43, EAINONAME, "") \
+ XX( 44, EAISERVICE, "") \
+ XX( 45, EAISOCKTYPE, "") \
+ XX( 46, ESHUTDOWN, "") \
+ XX( 47, EEXIST, "file already exists") \
+ XX( 48, ESRCH, "no such process")
+
+
+#define UV_ERRNO_GEN(val, name, s) UV_##name = val,
typedef enum {
- UV_UNKNOWN = -1,
- UV_OK = 0,
- UV_EOF,
- UV_EADDRINFO,
- UV_EACCES,
- UV_EAGAIN,
- UV_EADDRINUSE,
- UV_EADDRNOTAVAIL,
- UV_EAFNOSUPPORT,
- UV_EALREADY,
- UV_EBADF,
- UV_EBUSY,
- UV_ECONNABORTED,
- UV_ECONNREFUSED,
- UV_ECONNRESET,
- UV_EDESTADDRREQ,
- UV_EFAULT,
- UV_EHOSTUNREACH,
- UV_EINTR,
- UV_EINVAL,
- UV_EISCONN,
- UV_EMFILE,
- UV_EMSGSIZE,
- UV_ENETDOWN,
- UV_ENETUNREACH,
- UV_ENFILE,
- UV_ENOBUFS,
- UV_ENOMEM,
- UV_ENOTDIR,
- UV_EISDIR,
- UV_ENONET,
- UV_ENOPROTOOPT,
- UV_ENOTCONN,
- UV_ENOTSOCK,
- UV_ENOTSUP,
- UV_ENOENT,
- UV_ENOSYS,
- UV_EPIPE,
- UV_EPROTO,
- UV_EPROTONOSUPPORT,
- UV_EPROTOTYPE,
- UV_ETIMEDOUT,
- UV_ECHARSET,
- UV_EAIFAMNOSUPPORT,
- UV_EAINONAME,
- UV_EAISERVICE,
- UV_EAISOCKTYPE,
- UV_ESHUTDOWN,
- UV_EEXIST,
- UV_ESRCH
+ UV_ERRNO_MAP(UV_ERRNO_GEN)
} uv_err_code;
+#undef UV_ERRNO_GEN
typedef enum {
UV_UNKNOWN_HANDLE = 0,
View
19 src/unix/error.c
@@ -126,19 +126,18 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
* a) rely on what the system provides us
* b) reverse-map the error codes
*/
+#define UV_STRERROR_GEN(val, name, s) case UV_##name : return s;
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)
+ if (err.code == UV_EADDRINFO) {
return gai_strerror(errorno);
+ }
- if (errorno == -1)
- return "Unknown error";
- else
- return strerror(errorno);
+ switch (err.code) {
+ UV_ERRNO_MAP(UV_STRERROR_GEN)
+ default:
+ return strerror(err.sys_errno_);
+ }
}
+#undef UV_STRERROR_GEN
View
53 src/uv-common.c
@@ -50,63 +50,16 @@ uv_buf_t uv_buf_init(char* base, size_t len) {
const uv_err_t uv_ok_ = { UV_OK, 0 };
-
+#define UV_ERR_NAME_GEN(val, name, s) case UV_##name : return #name;
const char* uv_err_name(uv_err_t err) {
switch (err.code) {
- case UV_UNKNOWN: return "UNKNOWN";
- case UV_OK: return "OK";
- case UV_EOF: return "EOF";
- case UV_EADDRINFO: return "EADDRINFO";
- case UV_EACCES: return "EACCES";
- 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_EMSGSIZE: return "EMSGSIZE";
- 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_ENOTDIR: return "ENOTDIR";
- 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_ENOENT: return "ENOENT";
- case UV_ENOSYS: return "ENOSYS";
- case UV_EPIPE: return "EPIPE";
- case UV_EPROTO: return "EPROTO";
- case UV_EPROTONOSUPPORT: return "EPROTONOSUPPORT";
- case UV_EPROTOTYPE: return "EPROTOTYPE";
- case UV_ETIMEDOUT: return "ETIMEDOUT";
- case UV_ECHARSET: return "ECHARSET";
- case UV_EAIFAMNOSUPPORT: return "EAIFAMNOSUPPORT";
- case UV_EAINONAME: return "EAINONAME";
- case UV_EAISERVICE: return "EAISERVICE";
- case UV_EAISOCKTYPE: return "EAISOCKTYPE";
- case UV_ESHUTDOWN: return "ESHUTDOWN";
- case UV_EEXIST: return "EEXIST";
- case UV_ESRCH: return "ESRCH";
+ UV_ERRNO_MAP(UV_ERR_NAME_GEN)
default:
assert(0);
return NULL;
}
}
+#undef UV_ERR_NAME_GEN
void uv__set_error(uv_loop_t* loop, uv_err_code code, int sys_error) {
View
19 src/win/error.c
@@ -67,22 +67,15 @@ void uv_fatal_error(const int errorno, const char* syscall) {
/* TODO: thread safety */
static char* last_err_str_ = NULL;
+#define UV_STRERROR_GEN(val, name, s) case UV_##name : return s;
const char* uv_strerror(uv_err_t err) {
- if (last_err_str_ != NULL) {
- LocalFree(last_err_str_);
- }
-
- FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err.sys_errno_,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR) &last_err_str_, 0,
- NULL);
-
- if (last_err_str_) {
- return last_err_str_;
- } else {
- return "Unknown error";
+ switch (err.code) {
+ UV_ERRNO_MAP(UV_STRERROR_GEN)
+ default:
+ return "Unknown system error";
}
}
+#undef UV_STRERROR_GEN
uv_err_code uv_translate_sys_error(int sys_errno) {
Please sign in to comment.
Something went wrong with that request. Please try again.