mirror of https://github.com/nodejs/node.git
Add process.kill(sig = SIGTERM)
parent
2fd4958698
commit
e39923a3d7
|
@ -29,6 +29,7 @@ Process::Initialize (Handle<Object> target)
|
|||
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor_template, "write", Process::Write);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor_template, "close", Process::Close);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor_template, "kill", Process::Kill);
|
||||
|
||||
constructor_template->PrototypeTemplate()->SetAccessor(PID_SYMBOL,
|
||||
PIDGetter);
|
||||
|
@ -101,13 +102,6 @@ Process::Write (const Arguments& args)
|
|||
Process *process = NODE_UNWRAP(Process, args.Holder());
|
||||
assert(process);
|
||||
|
||||
#if 0
|
||||
if ( connection->ReadyState() != OPEN
|
||||
&& connection->ReadyState() != WRITE_ONLY
|
||||
)
|
||||
return ThrowException(String::New("Socket is not open for writing"));
|
||||
#endif
|
||||
|
||||
// XXX
|
||||
// A lot of improvement can be made here. First of all we're allocating
|
||||
// oi_bufs for every send which is clearly inefficent - it should use a
|
||||
|
@ -156,6 +150,23 @@ Process::Write (const Arguments& args)
|
|||
return Undefined();
|
||||
}
|
||||
|
||||
Handle<Value>
|
||||
Process::Kill (const Arguments& args)
|
||||
{
|
||||
HandleScope scope;
|
||||
Process *process = NODE_UNWRAP(Process, args.Holder());
|
||||
assert(process);
|
||||
|
||||
int sig = SIGTERM;
|
||||
if (args[0]->IsInt32()) sig = args[0]->Int32Value();
|
||||
|
||||
if (process->Kill(sig) != 0) {
|
||||
return ThrowException(String::New("Process already dead"));
|
||||
}
|
||||
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
Handle<Value>
|
||||
Process::Close (const Arguments& args)
|
||||
{
|
||||
|
@ -451,8 +462,7 @@ Process::OnExit (EV_P_ ev_child *watcher, int revents)
|
|||
int
|
||||
Process::Write (oi_buf *buf)
|
||||
{
|
||||
if (stdin_pipe_[1] < 0 || got_close_)
|
||||
return -1;
|
||||
if (stdin_pipe_[1] < 0 || got_close_) return -1;
|
||||
oi_queue_insert_head(&out_stream_, &buf->queue);
|
||||
buf->written = 0;
|
||||
ev_io_start(EV_DEFAULT_UC_ &stdin_watcher_);
|
||||
|
@ -462,10 +472,15 @@ Process::Write (oi_buf *buf)
|
|||
int
|
||||
Process::Close ()
|
||||
{
|
||||
if (stdin_pipe_[1] < 0 || got_close_)
|
||||
return -1;
|
||||
if (stdin_pipe_[1] < 0 || got_close_) return -1;
|
||||
got_close_ = true;
|
||||
ev_io_start(EV_DEFAULT_UC_ &stdin_watcher_);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
Process::Kill (int sig)
|
||||
{
|
||||
if (pid_ == 0) return -1;
|
||||
return kill(pid_, sig);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ class Process : ObjectWrap {
|
|||
static v8::Handle<v8::Value> New (const v8::Arguments& args);
|
||||
static v8::Handle<v8::Value> Write (const v8::Arguments& args);
|
||||
static v8::Handle<v8::Value> Close (const v8::Arguments& args);
|
||||
static v8::Handle<v8::Value> Kill (const v8::Arguments& args);
|
||||
static v8::Handle<v8::Value> PIDGetter (v8::Local<v8::String> _, const v8::AccessorInfo& info);
|
||||
|
||||
Process(v8::Handle<v8::Object> handle);
|
||||
|
@ -27,6 +28,7 @@ class Process : ObjectWrap {
|
|||
int Spawn (const char *command);
|
||||
int Write (oi_buf *buf);
|
||||
int Close ();
|
||||
int Kill (int sig);
|
||||
|
||||
private:
|
||||
static void OnOutput (EV_P_ ev_io *watcher, int revents);
|
||||
|
|
Loading…
Reference in New Issue