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

Commit

Permalink
windows: basic signal handling support with uv_signal_t
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Aug 15, 2012
1 parent 938a305 commit 2b090b5
Show file tree
Hide file tree
Showing 8 changed files with 335 additions and 29 deletions.
26 changes: 24 additions & 2 deletions include/uv-private/uv-win.h
Expand Up @@ -35,6 +35,7 @@ typedef intptr_t ssize_t;
#include <windows.h>

#include <process.h>
#include <signal.h>
#include <stdint.h>
#include <sys/stat.h>

Expand All @@ -47,6 +48,24 @@ typedef intptr_t ssize_t;
# define S_IFLNK 0xA000
#endif

/* Additional signals supported by uv_signal and or uv_kill. The CRT defines
* the following signals already:
*
* #define SIGINT 2
* #define SIGILL 4
* #define SIGABRT_COMPAT 6
* #define SIGFPE 8
* #define SIGSEGV 11
* #define SIGTERM 15
* #define SIGBREAK 21
* #define SIGABRT 22
*
* The additional signals have values that are common on other Unix
* variants (Linux and Darwin)
*/
#define SIGHUP 1
#define SIGKILL 9

/*
* Guids and typedefs for winsock extension functions
* Mingw32 doesn't have these :-(
Expand Down Expand Up @@ -255,7 +274,8 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);
UV_PROCESS_EXIT, \
UV_READ, \
UV_UDP_RECV, \
UV_WAKEUP,
UV_WAKEUP, \
UV_SIGNAL_REQ,

#define UV_REQ_PRIVATE_FIELDS \
union { \
Expand Down Expand Up @@ -509,7 +529,9 @@ RB_HEAD(uv_timer_tree_s, uv_timer_s);
char* buffer;

#define UV_SIGNAL_PRIVATE_FIELDS \
/* empty */
RB_ENTRY(uv_signal_s) tree_entry; \
struct uv_req_s signal_req; \
unsigned long pending_signum;

int uv_utf16_to_utf8(const WCHAR* utf16Buffer, size_t utf16Size,
char* utf8Buffer, size_t utf8Size);
Expand Down
1 change: 1 addition & 0 deletions include/uv.h
Expand Up @@ -1585,6 +1585,7 @@ struct uv_signal_s {
UV_HANDLE_FIELDS
uv_signal_cb signal_cb;
UV_SIGNAL_PRIVATE_FIELDS
int signum;
};

/* These functions are no-ops on Windows. */
Expand Down
3 changes: 3 additions & 0 deletions src/win/core.c
Expand Up @@ -55,6 +55,9 @@ static void uv_init(void) {
/* Initialize FS */
uv_fs_init();

/* Initialize signal stuff */
uv_signals_init();

/* Initialize console */
uv_console_init();

Expand Down
7 changes: 3 additions & 4 deletions src/win/handle-inl.h
Expand Up @@ -123,6 +123,9 @@ INLINE static void uv_process_endgames(uv_loop_t* loop) {
uv_async_endgame(loop, (uv_async_t*) handle);
break;

case UV_SIGNAL:
uv_signal_endgame(loop, (uv_signal_t*) handle);

case UV_PROCESS:
uv_process_endgame(loop, (uv_process_t*) handle);
break;
Expand All @@ -135,10 +138,6 @@ INLINE static void uv_process_endgames(uv_loop_t* loop) {
uv__fs_poll_endgame(loop, (uv_fs_poll_t*) handle);
break;

case UV_SIGNAL:
uv_signal_endgame(loop, (uv_signal_t*) handle);
break;

default:
assert(0);
break;
Expand Down
8 changes: 4 additions & 4 deletions src/win/handle.c
Expand Up @@ -124,6 +124,10 @@ void uv_close(uv_handle_t* handle, uv_close_cb cb) {
uv_async_close(loop, (uv_async_t*) handle);
return;

case UV_SIGNAL:
uv_signal_close(loop, (uv_signal_t*) handle);
return;

case UV_PROCESS:
uv_process_close(loop, (uv_process_t*) handle);
return;
Expand All @@ -138,10 +142,6 @@ void uv_close(uv_handle_t* handle, uv_close_cb cb) {
uv_want_endgame(loop, handle);
return;

case UV_SIGNAL:
uv_signal_close(loop, (uv_signal_t*) handle);
return;

default:
/* Not supported */
abort();
Expand Down
20 changes: 13 additions & 7 deletions src/win/internal.h
Expand Up @@ -231,6 +231,19 @@ void uv_process_async_wakeup_req(uv_loop_t* loop, uv_async_t* handle,
uv_req_t* req);


/*
* Signal watcher
*/
void uv_signals_init();
int uv__signal_dispatch(int signum);

void uv_signal_close(uv_loop_t* loop, uv_signal_t* handle);
void uv_signal_endgame(uv_loop_t* loop, uv_signal_t* handle);

void uv_process_signal_req(uv_loop_t* loop, uv_signal_t* handle,
uv_req_t* req);


/*
* Spawn
*/
Expand Down Expand Up @@ -273,13 +286,6 @@ void uv_fs_event_endgame(uv_loop_t* loop, uv_fs_event_t* handle);
void uv__fs_poll_endgame(uv_loop_t* loop, uv_fs_poll_t* handle);


/*
* Signals.
*/
void uv_signal_close(uv_loop_t* loop, uv_signal_t* handle);
void uv_signal_endgame(uv_loop_t* loop, uv_signal_t* handle);


/*
* Utilities.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/win/req-inl.h
Expand Up @@ -187,6 +187,10 @@ INLINE static void uv_process_reqs(uv_loop_t* loop) {
uv_process_async_wakeup_req(loop, (uv_async_t*) req->data, req);
break;

case UV_SIGNAL_REQ:
uv_process_signal_req(loop, (uv_signal_t*) req->data, req);
break;

case UV_POLL_REQ:
uv_process_poll_req(loop, (uv_poll_t*) req->data, req);
break;
Expand Down

0 comments on commit 2b090b5

Please sign in to comment.