Created
November 10, 2011 01:32
-
-
Save ry/1353813 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 8a27de2989bf55d6cf19c108fbf308376aa7e4e3 Mon Sep 17 00:00:00 2001 | |
From: Ryan Dahl <ry@tinyclouds.org> | |
Date: Wed, 9 Nov 2011 17:31:53 -0800 | |
Subject: [PATCH] Alternative ERRNO strategy | |
--- | |
include/uv.h | 106 +++++++++++++++++++++++++++++-------------------------- | |
src/uv-common.c | 53 ++-------------------------- | |
2 files changed, 59 insertions(+), 100 deletions(-) | |
diff --git a/include/uv.h b/include/uv.h | |
index 175840c..7e51613 100644 | |
--- a/include/uv.h | |
+++ b/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, | |
diff --git a/src/uv-common.c b/src/uv-common.c | |
index cd8c206..20f8bca 100644 | |
--- a/src/uv-common.c | |
+++ b/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) { | |
-- | |
1.7.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
+1 this is what I always do (stole it from v8), a lot easier to manage