Created
November 8, 2011 23:12
-
-
Save ry/28507b5ce35fcc9372dc 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 3cea65b9e2b269a2145613056cae635b1923392d Mon Sep 17 00:00:00 2001 | |
From: Ryan Dahl <ry@tinyclouds.org> | |
Date: Tue, 8 Nov 2011 15:05:50 -0800 | |
Subject: [PATCH 1/2] Add uv__new_artificial_error() | |
--- | |
src/uv-common.c | 11 +++++++++-- | |
src/uv-common.h | 1 + | |
2 files changed, 10 insertions(+), 2 deletions(-) | |
diff --git a/src/uv-common.c b/src/uv-common.c | |
index 599d625..2f16c7a 100644 | |
--- a/src/uv-common.c | |
+++ b/src/uv-common.c | |
@@ -121,8 +121,7 @@ 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) { | |
- loop->last_err.code = code; | |
- loop->last_err.sys_errno_ = 0; | |
+ loop->last_err = uv__new_artificial_error(code); | |
} | |
@@ -134,6 +133,14 @@ uv_err_t uv__new_sys_error(int sys_error) { | |
} | |
+uv_err_t uv__new_artificial_error(uv_err_code code) { | |
+ uv_err_t error; | |
+ error.code = code; | |
+ error.sys_errno_ = 0; | |
+ return error; | |
+} | |
+ | |
+ | |
uv_err_t uv_last_error(uv_loop_t* loop) { | |
return loop->last_err; | |
} | |
diff --git a/src/uv-common.h b/src/uv-common.h | |
index eecb130..5d99036 100644 | |
--- a/src/uv-common.h | |
+++ b/src/uv-common.h | |
@@ -55,6 +55,7 @@ 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); | |
uv_err_t uv__new_sys_error(int sys_error); | |
+uv_err_t uv__new_artificial_error(uv_err_code code); | |
int uv__tcp_bind(uv_tcp_t* handle, struct sockaddr_in addr); | |
int uv__tcp_bind6(uv_tcp_t* handle, struct sockaddr_in6 addr); | |
-- | |
1.7.6.msysgit.0 |
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 1177a0141b0e68b2c717f7583670b4c8690f446a Mon Sep 17 00:00:00 2001 | |
From: Tj Holowaychuk <tj@vision-media.ca> | |
Date: Mon, 7 Nov 2011 12:30:02 -0800 | |
Subject: [PATCH 2/2] Add UV_ESRCH | |
Fixes #239. | |
--- | |
include/uv.h | 3 ++- | |
src/unix/error.c | 2 ++ | |
src/win/process.c | 2 +- | |
test/test-spawn.c | 6 ++++-- | |
4 files changed, 9 insertions(+), 4 deletions(-) | |
diff --git a/include/uv.h b/include/uv.h | |
index 88afed4..175840c 100644 | |
--- a/include/uv.h | |
+++ b/include/uv.h | |
@@ -116,7 +116,8 @@ typedef enum { | |
UV_EAISERVICE, | |
UV_EAISOCKTYPE, | |
UV_ESHUTDOWN, | |
- UV_EEXIST | |
+ UV_EEXIST, | |
+ UV_ESRCH | |
} uv_err_code; | |
typedef enum { | |
diff --git a/src/unix/error.c b/src/unix/error.c | |
index ac8bdd7..f79d2db 100644 | |
--- a/src/unix/error.c | |
+++ b/src/unix/error.c | |
@@ -79,6 +79,7 @@ static int uv__translate_lib_error(int code) { | |
case UV_ENOTCONN: return ENOTCONN; | |
case UV_EEXIST: return EEXIST; | |
case UV_EHOSTUNREACH: return EHOSTUNREACH; | |
+ case UV_ESRCH: return ESRCH; | |
default: return -1; | |
} | |
@@ -112,6 +113,7 @@ uv_err_code uv_translate_sys_error(int sys_errno) { | |
case EEXIST: return UV_EEXIST; | |
case EHOSTUNREACH: return UV_EHOSTUNREACH; | |
case EAI_NONAME: return UV_ENOENT; | |
+ case ESRCH: return UV_ESRCH; | |
default: return UV_UNKNOWN; | |
} | |
diff --git a/src/win/process.c b/src/win/process.c | |
index fd8018f..9d6973c 100644 | |
--- a/src/win/process.c | |
+++ b/src/win/process.c | |
@@ -1086,7 +1086,7 @@ static uv_err_t uv__kill(HANDLE process_handle, int signum) { | |
status == STILL_ACTIVE) { | |
err = uv_ok_; | |
} else { | |
- err = uv__new_sys_error(GetLastError()); | |
+ err = uv__new_artificial_error(UV_ESRCH); | |
} | |
} else { | |
err.code = UV_ENOSYS; | |
diff --git a/test/test-spawn.c b/test/test-spawn.c | |
index 192644b..6872011 100644 | |
--- a/test/test-spawn.c | |
+++ b/test/test-spawn.c | |
@@ -68,11 +68,13 @@ static void kill_cb(uv_process_t* process, int exit_status, int term_signal) { | |
ASSERT(no_term_signal || term_signal == 15); | |
uv_close((uv_handle_t*)process, close_cb); | |
- /* Sending signum == 0 should check if the | |
+ /* | |
+ * Sending signum == 0 should check if the | |
* child process is still alive, not kill it. | |
+ * This process should be dead. | |
*/ | |
err = uv_kill(process->pid, 0); | |
- ASSERT(err.code != UV_OK); | |
+ ASSERT(err.code == UV_ESRCH); | |
} | |
-- | |
1.7.6.msysgit.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment