-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathbinding.cc
More file actions
37 lines (30 loc) · 901 Bytes
/
binding.cc
File metadata and controls
37 lines (30 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifndef _WIN32
#include <node.h>
#include <v8.h>
#include <uv.h>
#include <assert.h>
#include <unistd.h>
using v8::Boolean;
using v8::FunctionCallbackInfo;
using v8::Int32;
using v8::Value;
void Handler(int signo, siginfo_t* siginfo, void* ucontext) {
char signo_char = signo;
int written;
assert(signo == siginfo->si_signo);
do {
written = write(1, &signo_char, 1); // write() is signal-safe.
} while (written == -1 && errno == EINTR);
assert(written == 1);
}
void RegisterSignalHandler(const FunctionCallbackInfo<Value>& args) {
assert(args[0]->IsInt32());
assert(args[1]->IsBoolean());
int32_t signo = args[0].As<Int32>()->Value();
bool reset_handler = args[1].As<Boolean>()->Value();
node::RegisterSignalHandler(signo, Handler, reset_handler);
}
NODE_MODULE_INIT() {
NODE_SET_METHOD(exports, "registerSignalHandler", RegisterSignalHandler);
}
#endif // _WIN32