Skip to content

Commit ad9d683

Browse files
committed
API: rename node.Process to node.ChildProcess
This is to avoid confusion with the global "process" object, especially for the instances of node.Process.
1 parent 116f4de commit ad9d683

13 files changed

+106
-104
lines changed

benchmark/process_loop.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
function next (i) {
22
if (i <= 0) return;
33

4-
var process = node.createProcess("echo hello");
4+
var child = node.createChildProcess("echo hello");
55

6-
process.addListener("output", function (chunk) {
6+
child.addListener("output", function (chunk) {
77
if (chunk) print(chunk);
88
});
99

10-
process.addListener("exit", function (code) {
10+
child.addListener("exit", function (code) {
1111
if (code != 0) node.exit(-1);
1212
next(i - 1);
1313
});

benchmark/run.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ var benchmark_dir = node.path.dirname(__filename);
88
function exec (script, callback) {
99
var command = ARGV[0] + " " + node.path.join(benchmark_dir, script);
1010
var start = new Date();
11-
var process = node.createProcess(command);
12-
process.addListener("exit", function (code) {
11+
var child = node.createChildProcess(command);
12+
child.addListener("exit", function (code) {
1313
var elapsed = new Date() - start;
1414
callback(elapsed, code);
1515
});

benchmark/static_http_server.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ function responseListener (res) {
3434
});
3535
}
3636

37-
function onLoad () {
38-
for (var i = 0; i < concurrency; i++) {
39-
var client = node.http.createClient(port);
40-
client.id = i;
41-
client.get("/").finish(responseListener);
42-
requests++;
43-
}
37+
for (var i = 0; i < concurrency; i++) {
38+
var client = node.http.createClient(port);
39+
client.id = i;
40+
client.get("/").finish(responseListener);
41+
requests++;
4442
}

src/process.cc renamed to src/child_process.cc

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "node.h"
2-
#include "process.h"
2+
#include "child_process.h"
33

44
#include <assert.h>
55
#include <stdlib.h>
@@ -13,65 +13,65 @@ using namespace node;
1313

1414
#define PID_SYMBOL String::NewSymbol("pid")
1515

16-
Persistent<FunctionTemplate> Process::constructor_template;
16+
Persistent<FunctionTemplate> ChildProcess::constructor_template;
1717

1818
void
19-
Process::Initialize (Handle<Object> target)
19+
ChildProcess::Initialize (Handle<Object> target)
2020
{
2121
HandleScope scope;
2222

23-
Local<FunctionTemplate> t = FunctionTemplate::New(Process::New);
23+
Local<FunctionTemplate> t = FunctionTemplate::New(ChildProcess::New);
2424
constructor_template = Persistent<FunctionTemplate>::New(t);
2525
constructor_template->Inherit(EventEmitter::constructor_template);
2626
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
2727

28-
NODE_SET_PROTOTYPE_METHOD(constructor_template, "spawn", Process::Spawn);
29-
NODE_SET_PROTOTYPE_METHOD(constructor_template, "write", Process::Write);
30-
NODE_SET_PROTOTYPE_METHOD(constructor_template, "close", Process::Close);
31-
NODE_SET_PROTOTYPE_METHOD(constructor_template, "kill", Process::Kill);
28+
NODE_SET_PROTOTYPE_METHOD(constructor_template, "spawn", ChildProcess::Spawn);
29+
NODE_SET_PROTOTYPE_METHOD(constructor_template, "write", ChildProcess::Write);
30+
NODE_SET_PROTOTYPE_METHOD(constructor_template, "close", ChildProcess::Close);
31+
NODE_SET_PROTOTYPE_METHOD(constructor_template, "kill", ChildProcess::Kill);
3232

33-
target->Set(String::NewSymbol("Process"), constructor_template->GetFunction());
33+
target->Set(String::NewSymbol("ChildProcess"), constructor_template->GetFunction());
3434
}
3535

3636
Handle<Value>
37-
Process::New (const Arguments& args)
37+
ChildProcess::New (const Arguments& args)
3838
{
3939
HandleScope scope;
4040

41-
Process *p = new Process();
41+
ChildProcess *p = new ChildProcess();
4242
p->Wrap(args.Holder());
4343

4444
return args.This();
4545
}
4646

4747
Handle<Value>
48-
Process::Spawn (const Arguments& args)
48+
ChildProcess::Spawn (const Arguments& args)
4949
{
5050
if (args.Length() == 0 || !args[0]->IsString()) {
5151
return ThrowException(String::New("Bad argument."));
5252
}
5353

5454
HandleScope scope;
55-
Process *process = ObjectWrap::Unwrap<Process>(args.Holder());
55+
ChildProcess *child = ObjectWrap::Unwrap<ChildProcess>(args.Holder());
5656

5757
String::Utf8Value command(args[0]->ToString());
5858

59-
int r = process->Spawn(*command);
59+
int r = child->Spawn(*command);
6060
if (r != 0) {
6161
return ThrowException(String::New("Error spawning"));
6262
}
6363

64-
process->handle_->Set(PID_SYMBOL, Integer::New(process->pid_));
64+
child->handle_->Set(PID_SYMBOL, Integer::New(child->pid_));
6565

6666
return Undefined();
6767
}
6868

6969
Handle<Value>
70-
Process::Write (const Arguments& args)
70+
ChildProcess::Write (const Arguments& args)
7171
{
7272
HandleScope scope;
73-
Process *process = ObjectWrap::Unwrap<Process>(args.Holder());
74-
assert(process);
73+
ChildProcess *child = ObjectWrap::Unwrap<ChildProcess>(args.Holder());
74+
assert(child);
7575

7676
ssize_t len;
7777

@@ -109,69 +109,69 @@ Process::Write (const Arguments& args)
109109
}
110110
}
111111

112-
return process->Write(buf, len) == 0 ? True() : False();
112+
return child->Write(buf, len) == 0 ? True() : False();
113113
}
114114

115115
Handle<Value>
116-
Process::Kill (const Arguments& args)
116+
ChildProcess::Kill (const Arguments& args)
117117
{
118118
HandleScope scope;
119-
Process *process = ObjectWrap::Unwrap<Process>(args.Holder());
120-
assert(process);
119+
ChildProcess *child = ObjectWrap::Unwrap<ChildProcess>(args.Holder());
120+
assert(child);
121121

122122
int sig = SIGTERM;
123123
if (args[0]->IsInt32()) sig = args[0]->Int32Value();
124124

125-
if (process->Kill(sig) != 0) {
126-
return ThrowException(String::New("Process already dead"));
125+
if (child->Kill(sig) != 0) {
126+
return ThrowException(String::New("ChildProcess already dead"));
127127
}
128128

129129
return Undefined();
130130
}
131131

132132
Handle<Value>
133-
Process::Close (const Arguments& args)
133+
ChildProcess::Close (const Arguments& args)
134134
{
135135
HandleScope scope;
136-
Process *process = ObjectWrap::Unwrap<Process>(args.Holder());
137-
assert(process);
138-
return process->Close() == 0 ? True() : False();
136+
ChildProcess *child = ObjectWrap::Unwrap<ChildProcess>(args.Holder());
137+
assert(child);
138+
return child->Close() == 0 ? True() : False();
139139
}
140140

141141
void
142-
Process::reader_closed (evcom_reader *r)
142+
ChildProcess::reader_closed (evcom_reader *r)
143143
{
144-
Process *process = static_cast<Process*> (r->data);
145-
if (r == &process->stdout_reader_) {
146-
process->stdout_fd_ = -1;
144+
ChildProcess *child = static_cast<ChildProcess*> (r->data);
145+
if (r == &child->stdout_reader_) {
146+
child->stdout_fd_ = -1;
147147
} else {
148-
assert(r == &process->stderr_reader_);
149-
process->stderr_fd_ = -1;
148+
assert(r == &child->stderr_reader_);
149+
child->stderr_fd_ = -1;
150150
}
151151
evcom_reader_detach(r);
152-
process->MaybeShutdown();
152+
child->MaybeShutdown();
153153
}
154154

155155
void
156-
Process::stdin_closed (evcom_writer *w)
156+
ChildProcess::stdin_closed (evcom_writer *w)
157157
{
158-
Process *process = static_cast<Process*> (w->data);
159-
assert(w == &process->stdin_writer_);
160-
process->stdin_fd_ = -1;
158+
ChildProcess *child = static_cast<ChildProcess*> (w->data);
159+
assert(w == &child->stdin_writer_);
160+
child->stdin_fd_ = -1;
161161
evcom_writer_detach(w);
162-
process->MaybeShutdown();
162+
child->MaybeShutdown();
163163
}
164164

165165
void
166-
Process::on_read (evcom_reader *r, const void *buf, size_t len)
166+
ChildProcess::on_read (evcom_reader *r, const void *buf, size_t len)
167167
{
168-
Process *process = static_cast<Process*> (r->data);
168+
ChildProcess *child = static_cast<ChildProcess*> (r->data);
169169
HandleScope scope;
170170

171-
bool isSTDOUT = (r == &process->stdout_reader_);
171+
bool isSTDOUT = (r == &child->stdout_reader_);
172172
Local<Value> argv[1];
173173

174-
enum encoding encoding = isSTDOUT ? process->stdout_encoding_ : process->stderr_encoding_;
174+
enum encoding encoding = isSTDOUT ? child->stdout_encoding_ : child->stderr_encoding_;
175175

176176
if (len == 0) {
177177
argv[0] = Local<Value>::New(Null());
@@ -190,11 +190,11 @@ Process::on_read (evcom_reader *r, const void *buf, size_t len)
190190
argv[0] = String::New((const char*)buf, len);
191191
}
192192

193-
process->Emit(isSTDOUT ? "output" : "error", 1, argv);
194-
process->MaybeShutdown();
193+
child->Emit(isSTDOUT ? "output" : "error", 1, argv);
194+
child->MaybeShutdown();
195195
}
196196

197-
Process::Process ()
197+
ChildProcess::ChildProcess ()
198198
: EventEmitter()
199199
{
200200
evcom_reader_init(&stdout_reader_);
@@ -211,7 +211,7 @@ Process::Process ()
211211
stdin_writer_.data = this;
212212
stdin_writer_.on_close = stdin_closed;
213213

214-
ev_init(&child_watcher_, Process::OnCHLD);
214+
ev_init(&child_watcher_, ChildProcess::OnCHLD);
215215
child_watcher_.data = this;
216216

217217
stdout_fd_ = -1;
@@ -227,13 +227,13 @@ Process::Process ()
227227
pid_ = 0;
228228
}
229229

230-
Process::~Process ()
230+
ChildProcess::~ChildProcess ()
231231
{
232232
Shutdown();
233233
}
234234

235235
void
236-
Process::Shutdown ()
236+
ChildProcess::Shutdown ()
237237
{
238238
if (stdin_fd_ >= 0) {
239239
evcom_writer_close(&stdin_writer_);
@@ -269,7 +269,7 @@ SetNonBlocking (int fd)
269269
}
270270

271271
int
272-
Process::Spawn (const char *command)
272+
ChildProcess::Spawn (const char *command)
273273
{
274274
assert(pid_ == 0);
275275
assert(stdout_fd_ == -1);
@@ -345,48 +345,48 @@ Process::Spawn (const char *command)
345345
}
346346

347347
void
348-
Process::OnCHLD (EV_P_ ev_child *watcher, int revents)
348+
ChildProcess::OnCHLD (EV_P_ ev_child *watcher, int revents)
349349
{
350350
ev_child_stop(EV_A_ watcher);
351-
Process *process = static_cast<Process*>(watcher->data);
351+
ChildProcess *child = static_cast<ChildProcess*>(watcher->data);
352352

353353
assert(revents == EV_CHILD);
354-
assert(process->pid_ == watcher->rpid);
355-
assert(&process->child_watcher_ == watcher);
354+
assert(child->pid_ == watcher->rpid);
355+
assert(&child->child_watcher_ == watcher);
356356

357-
process->got_chld_ = true;
358-
process->exit_code_ = watcher->rstatus;
357+
child->got_chld_ = true;
358+
child->exit_code_ = watcher->rstatus;
359359

360-
if (process->stdin_fd_ >= 0) evcom_writer_close(&process->stdin_writer_);
360+
if (child->stdin_fd_ >= 0) evcom_writer_close(&child->stdin_writer_);
361361

362-
process->MaybeShutdown();
362+
child->MaybeShutdown();
363363
}
364364

365365
int
366-
Process::Write (const char *str, size_t len)
366+
ChildProcess::Write (const char *str, size_t len)
367367
{
368368
if (stdin_fd_ < 0 || got_chld_) return -1;
369369
evcom_writer_write(&stdin_writer_, str, len);
370370
return 0;
371371
}
372372

373373
int
374-
Process::Close (void)
374+
ChildProcess::Close (void)
375375
{
376376
if (stdin_fd_ < 0 || got_chld_) return -1;
377377
evcom_writer_close(EV_DEFAULT_UC_ &stdin_writer_);
378378
return 0;
379379
}
380380

381381
int
382-
Process::Kill (int sig)
382+
ChildProcess::Kill (int sig)
383383
{
384384
if (got_chld_ || pid_ == 0) return -1;
385385
return kill(pid_, sig);
386386
}
387387

388388
void
389-
Process::MaybeShutdown (void)
389+
ChildProcess::MaybeShutdown (void)
390390
{
391391
if (stdout_fd_ < 0 && stderr_fd_ < 0 && got_chld_) {
392392
HandleScope scope;

src/process.h renamed to src/child_process.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef node_process_h
2-
#define node_process_h
1+
#ifndef node_child_process_h
2+
#define node_child_process_h
33

44
#include "node.h"
55
#include "events.h"
@@ -9,7 +9,7 @@
99

1010
namespace node {
1111

12-
class Process : EventEmitter {
12+
class ChildProcess : EventEmitter {
1313
public:
1414
static void Initialize (v8::Handle<v8::Object> target);
1515

@@ -22,8 +22,8 @@ class Process : EventEmitter {
2222
static v8::Handle<v8::Value> Kill (const v8::Arguments& args);
2323
static v8::Handle<v8::Value> PIDGetter (v8::Local<v8::String> _, const v8::AccessorInfo& info);
2424

25-
Process();
26-
~Process();
25+
ChildProcess();
26+
~ChildProcess();
2727

2828
int Spawn (const char *command);
2929
int Write (const char *str, size_t len);
@@ -59,4 +59,4 @@ class Process : EventEmitter {
5959
};
6060

6161
} // namespace node
62-
#endif // node_process_h
62+
#endif // node_child_process_h

src/node.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "file.h"
77
#include "http.h"
88
#include "timer.h"
9-
#include "process.h"
9+
#include "child_process.h"
1010
#include "constants.h"
1111
#include "node_stdio.h"
1212

@@ -213,7 +213,7 @@ Load (int argc, char *argv[])
213213

214214
Stdio::Initialize(node_obj);
215215
Timer::Initialize(node_obj);
216-
Process::Initialize(node_obj);
216+
ChildProcess::Initialize(node_obj);
217217

218218
DefineConstants(node_obj);
219219

0 commit comments

Comments
 (0)