FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
node/src/node_signal_handler.cc at debugger · bionicpill/node · GitHub
bionicpill
node
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
node
/
src
/
node_signal_handler.cc
Copy path
More file actions
More file actions
Latest commit
History
History
History
74 lines (53 loc) · 1.99 KB
Breadcrumbs
node
/
src
/
node_signal_handler.cc
Copy path
File metadata and controls
74 lines (53 loc) · 1.99 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
Copyright 2009 Ryan Dahl <ry@tinyclouds.org>
#
include
<
node_signal_handler.h
>
#
include
<
assert.h
>
namespace
node
{
using
namespace
v8
;
Persistent<FunctionTemplate> SignalHandler::constructor_template;
void
SignalHandler::Initialize
(Handle<Object> target) {
HandleScope scope;
Local<FunctionTemplate> t =
FunctionTemplate::New
(SignalHandler::New);
constructor_template = Persistent<FunctionTemplate>::
New
(t);
constructor_template->
Inherit
(EventEmitter::constructor_template);
constructor_template->
InstanceTemplate
()->
SetInternalFieldCount
(
1
);
constructor_template->
SetClassName
(
String::NewSymbol
(
"
SignalHandler
"
));
NODE_SET_PROTOTYPE_METHOD
(constructor_template,
"
stop
"
, SignalHandler::Stop);
target->
Set
(
String::NewSymbol
(
"
SignalHandler
"
),
constructor_template->
GetFunction
());
}
void
SignalHandler::OnSignal
(
EV_P_
ev_signal *watcher,
int
revents) {
SignalHandler *handler =
static_cast
<SignalHandler*>(watcher->
data
);
HandleScope scope;
assert
(revents ==
EV_SIGNAL
);
handler->
Emit
(
"
signal
"
,
0
,
NULL
);
}
SignalHandler::~SignalHandler
() {
if
(watcher_.
active
) {
ev_ref
(
EV_DEFAULT_UC
);
ev_signal_stop
(
EV_DEFAULT_UC_
&watcher_);
}
}
Handle<Value>
SignalHandler::New
(
const
Arguments& args) {
HandleScope scope;
if
(args.
Length
() !=
1
|| !args[
0
]->
IsInt32
()) {
return
ThrowException
(
String::New
(
"
Bad arguments
"
));
}
int
sig = args[
0
]->
Int32Value
();
SignalHandler *handler =
new
SignalHandler
();
handler->
Wrap
(args.
Holder
());
ev_signal_init
(&handler->
watcher_
, SignalHandler::OnSignal, sig);
handler->
watcher_
.
data
= handler;
ev_signal_start
(
EV_DEFAULT_UC_
&handler->
watcher_
);
ev_unref
(
EV_DEFAULT_UC
);
handler->
Attach
();
return
args.
This
();
}
Handle<Value>
SignalHandler::Stop
(
const
Arguments& args) {
HandleScope scope;
SignalHandler *handler = ObjectWrap::Unwrap<SignalHandler>(args.
Holder
());
ev_ref
(
EV_DEFAULT_UC
);
ev_signal_stop
(
EV_DEFAULT_UC_
&handler->
watcher_
);
handler->
Detach
();
return
Undefined
();
}
}
//
namespace node
Back
|
FazBrowse Home
|
New Git URL