Permalink
Browse files

lint

  • Loading branch information...
1 parent 723c7d9 commit 116f4dea052c9d59f6666345ccde4af5774b1bc2 @ry ry committed Aug 26, 2009
View
2 src/dns.cc
@@ -35,7 +35,7 @@ set_timeout ()
}
static inline void
-maybe_start ()
+maybe_start ()
{
ev_io_start(EV_DEFAULT_UC_ &io_watcher);
set_timeout();
View
14 src/events.cc
@@ -22,7 +22,7 @@ using namespace node;
Persistent<FunctionTemplate> EventEmitter::constructor_template;
-void
+void
EventEmitter::Initialize (Local<FunctionTemplate> ctemplate)
{
HandleScope scope;
@@ -38,7 +38,7 @@ EventEmitter::Initialize (Local<FunctionTemplate> ctemplate)
static bool
ReallyEmit (Handle<Object> self, Handle<String> event, int argc, Handle<Value> argv[])
{
- HandleScope scope;
+ HandleScope scope;
Local<Value> events_v = self->Get(String::NewSymbol("_events"));
if (!events_v->IsObject()) return false;
@@ -49,7 +49,7 @@ ReallyEmit (Handle<Object> self, Handle<String> event, int argc, Handle<Value> a
Local<Array> listeners = Local<Array>::Cast(listeners_v);
for (unsigned int i = 0; i < listeners->Length(); i++) {
- HandleScope scope;
+ HandleScope scope;
Local<Value> listener_v = listeners->Get(Integer::New(i));
if (!listener_v->IsFunction()) continue;
@@ -71,7 +71,7 @@ ReallyEmit (Handle<Object> self, Handle<String> event, int argc, Handle<Value> a
Handle<Value>
EventEmitter::Emit (const Arguments& args)
{
- HandleScope scope;
+ HandleScope scope;
Local<String> event = args[0]->ToString();
int argc = 0;
Local<Array> emit_args;
@@ -85,22 +85,22 @@ EventEmitter::Emit (const Arguments& args)
argv[i] = emit_args->Get(Integer::New(i));
}
- bool r = ReallyEmit(args.Holder(), event, argc, argv);
+ bool r = ReallyEmit(args.Holder(), event, argc, argv);
return scope.Close(r ? True() : False());
}
bool
EventEmitter::Emit (const char *event_s, int argc, Handle<Value> argv[])
{
- HandleScope scope;
+ HandleScope scope;
Local<String> event = String::NewSymbol(event_s);
return ReallyEmit(handle_, event, argc, argv);
}
Persistent<FunctionTemplate> Promise::constructor_template;
-void
+void
Promise::Initialize (v8::Handle<v8::Object> target)
{
HandleScope scope;
View
2 src/events.h
@@ -25,7 +25,7 @@ class Promise : public EventEmitter {
static v8::Persistent<v8::FunctionTemplate> constructor_template;
static Promise* Create (bool ref = false);
-
+
bool EmitSuccess (int argc, v8::Handle<v8::Value> argv[]);
bool EmitError (int argc, v8::Handle<v8::Value> argv[]);
void Block ();
View
2 src/events.js
@@ -50,7 +50,7 @@ node.Promise.prototype.wait = function () {
ret = arg;
})
.block();
-
+
if (had_error) throw ret;
return ret;
};
View
26 src/file.cc
@@ -145,9 +145,9 @@ AfterOpen (eio_req *req)
static Handle<Value>
Open (const Arguments& args)
{
- if ( args.Length() < 3
- || !args[0]->IsString()
- || !args[1]->IsInt32()
+ if ( args.Length() < 3
+ || !args[0]->IsString()
+ || !args[1]->IsInt32()
|| !args[2]->IsInt32()
) return ThrowException(BAD_ARGUMENTS);
@@ -186,7 +186,7 @@ AfterWrite (eio_req *req)
/* node.fs.write(fd, data, position, callback)
- * Wrapper for write(2).
+ * Wrapper for write(2).
*
* 0 fd integer. file descriptor
* 1 data the data to write (string = utf8, array = raw)
@@ -198,16 +198,16 @@ AfterWrite (eio_req *req)
static Handle<Value>
Write (const Arguments& args)
{
- if ( args.Length() < 3
- || !args[0]->IsInt32()
+ if ( args.Length() < 3
+ || !args[0]->IsInt32()
) return ThrowException(BAD_ARGUMENTS);
HandleScope scope;
int fd = args[0]->Int32Value();
off_t pos = args[2]->IsNumber() ? args[2]->IntegerValue() : -1;
- char *buf = NULL;
+ char *buf = NULL;
size_t len = 0;
if (args[1]->IsString()) {
@@ -216,7 +216,7 @@ Write (const Arguments& args)
len = string->Utf8Length();
buf = reinterpret_cast<char*>(malloc(len));
string->WriteUtf8(buf, len);
-
+
} else if (args[1]->IsArray()) {
// raw encoding
Local<Array> array = Local<Array>::Cast(args[1]);
@@ -250,8 +250,8 @@ AfterUtf8Read (eio_req *req)
Local<Value> argv[2];
- if (req->result == 0) {
- // eof
+ if (req->result == 0) {
+ // eof
argv[0] = Local<Value>::New(Null());
argv[1] = Integer::New(0);
} else {
@@ -297,7 +297,7 @@ AfterRawRead(eio_req *req)
}
/* node.fs.read(fd, length, position, encoding, callback)
- * Wrapper for read(2).
+ * Wrapper for read(2).
*
* 0 fd integer. file descriptor
* 1 length integer. length to read
@@ -310,7 +310,7 @@ AfterRawRead(eio_req *req)
static Handle<Value>
Read (const Arguments& args)
{
- if ( args.Length() < 2
+ if ( args.Length() < 2
|| !args[0]->IsInt32() // fd
|| !args[1]->IsNumber() // len
) return ThrowException(BAD_ARGUMENTS);
@@ -329,7 +329,7 @@ Read (const Arguments& args)
Promise *promise = Promise::Create(true);
// NOTE: 2nd param: NULL pointer tells eio to allocate it itself
- eio_read(fd, NULL, len, pos, EIO_PRI_DEFAULT,
+ eio_read(fd, NULL, len, pos, EIO_PRI_DEFAULT,
encoding == UTF8 ? AfterUtf8Read : AfterRawRead, promise);
return scope.Close(promise->Handle());
View
2 src/file.js
@@ -2,7 +2,7 @@ node.fs.exists = function (path, callback) {
var p = node.fs.stat(path);
p.addCallback(function () { callback(true); });
p.addErrback(function () { callback(false); });
-}
+};
node.fs.cat = function (path, encoding) {
var open_promise = node.fs.open(path, node.O_RDONLY, 0666);
View
12 src/http.cc
@@ -149,13 +149,13 @@ HTTPConnection::on_headers_complete (http_parser *parser)
Local<Object> message_info = Object::New();
- // METHOD
+ // METHOD
if (connection->parser_.type == HTTP_REQUEST)
message_info->Set(METHOD_SYMBOL, GetMethod(connection->parser_.method));
- // STATUS
+ // STATUS
if (connection->parser_.type == HTTP_RESPONSE)
- message_info->Set(STATUS_CODE_SYMBOL,
+ message_info->Set(STATUS_CODE_SYMBOL,
Integer::New(connection->parser_.status_code));
// VERSION
@@ -165,10 +165,10 @@ HTTPConnection::on_headers_complete (http_parser *parser)
, "%d.%d"
, connection->parser_.version_major
, connection->parser_.version_minor
- );
+ );
message_info->Set(HTTP_VERSION_SYMBOL, String::New(version));
- message_info->Set(SHOULD_KEEP_ALIVE_SYMBOL,
+ message_info->Set(SHOULD_KEEP_ALIVE_SYMBOL,
http_parser_should_keep_alive(&connection->parser_) ? True() : False());
Local<Value> argv[1] = { message_info };
@@ -189,7 +189,7 @@ HTTPConnection::on_body (http_parser *parser, const char *buf, size_t len)
Handle<Value> argv[1];
- // TODO each message should have their encoding.
+ // TODO each message should have their encoding.
// don't look at the conneciton for encoding
if (connection->encoding_ == RAW) {
View
2 src/http.h
@@ -19,7 +19,7 @@ class HTTPConnection : public Connection {
static v8::Handle<v8::Value> NewServer (const v8::Arguments& args);
HTTPConnection (enum http_parser_type type)
- : Connection()
+ : Connection()
{
http_parser_init (&parser_, type);
parser_.on_message_begin = on_message_begin;
View
26 src/http.js
@@ -67,17 +67,17 @@ node.http.parseUri = function (str) {
}
});
uri.toString = function () { return str; };
-
+
for (i = o.key.length - 1; i >= 0; i--){
if (uri[o.key[i]] == "") delete uri[o.key[i]];
}
-
+
return uri;
};
node.http.parseUri.options = {
strictMode: false,
- key: [
+ key: [
"source",
"protocol",
"authority",
@@ -119,7 +119,7 @@ function IncomingMessage (connection) {
this.httpVersion = null;
this.headers = {};
- // request (server) only
+ // request (server) only
this.uri = "";
this.method = null;
@@ -130,7 +130,7 @@ function IncomingMessage (connection) {
node.inherits(IncomingMessage, node.EventEmitter);
IncomingMessage.prototype.setBodyEncoding = function (enc) {
- // TODO: Find a cleaner way of doing this.
+ // TODO: Find a cleaner way of doing this.
this.connection.setEncoding(enc);
};
@@ -144,7 +144,7 @@ IncomingMessage.prototype.resume = function () {
IncomingMessage.prototype._addHeaderLine = function (field, value) {
if (field in this.headers) {
- // TODO Certain headers like 'Content-Type' should not be concatinated.
+ // TODO Certain headers like 'Content-Type' should not be concatinated.
// See https://www.google.com/reader/view/?tab=my#overview-page
this.headers[field] += ", " + value;
} else {
@@ -191,7 +191,7 @@ OutgoingMessage.prototype.sendHeaderLines = function (first_line, headers) {
}
message_header += field + ": " + value + CRLF;
-
+
if (connection_expression.exec(field)) {
sent_connection_header = true;
if (close_expression.exec(value)) this.closeOnFinish = true;
@@ -206,7 +206,7 @@ OutgoingMessage.prototype.sendHeaderLines = function (first_line, headers) {
}
}
- // keep-alive logic
+ // keep-alive logic
if (sent_connection_header == false) {
if (this.should_keep_alive) {
message_header += "Connection: keep-alive\r\n";
@@ -336,11 +336,11 @@ function createIncomingMessageStream (connection, incoming_listener) {
if (info.method) {
// server only
- incoming.method = info.method;
+ incoming.method = info.method;
incoming.uri = node.http.parseUri(incoming.uri); // TODO parse the URI lazily?
} else {
// client only
- incoming.statusCode = info.statusCode;
+ incoming.statusCode = info.statusCode;
}
stream.emit("incoming", [incoming, info.should_keep_alive]);
@@ -370,7 +370,7 @@ function flushMessageQueue (connection, queue) {
var out = message.output.shift();
connection.send(out, out.encoding);
}
-
+
if (!message.finished) break;
message.emit("sent");
@@ -416,7 +416,7 @@ function connectionListener (connection) {
}
});
responses.push(res);
-
+
connection.server.emit("request", [req, res]);
});
}
@@ -454,7 +454,7 @@ node.http.createClient = function (port, host) {
client.emit("error");
return;
}
-
+
//node.debug("HTTP CLIENT onClose. readyState = " + client.readyState);
// If there are more requests to handle, reconnect.
View
46 src/net.cc
@@ -32,14 +32,14 @@ using namespace node;
#define CLOSING_SYMBOL String::NewSymbol("closing")
#define CLOSED_SYMBOL String::NewSymbol("closed")
-static const struct addrinfo server_tcp_hints =
-/* ai_flags */ { AI_PASSIVE
+static const struct addrinfo server_tcp_hints =
+/* ai_flags */ { AI_PASSIVE
/* ai_family */ , AF_UNSPEC
/* ai_socktype */ , SOCK_STREAM
, 0
};
-static const struct addrinfo client_tcp_hints =
+static const struct addrinfo client_tcp_hints =
/* ai_flags */ { 0
/* ai_family */ , AF_UNSPEC
/* ai_socktype */ , SOCK_STREAM
@@ -48,7 +48,7 @@ static const struct addrinfo client_tcp_hints =
Persistent<FunctionTemplate> Connection::constructor_template;
-void
+void
Connection::Initialize (v8::Handle<v8::Object> target)
{
HandleScope scope;
@@ -115,8 +115,8 @@ Connection::Init (void)
Connection::~Connection ()
{
- assert(stream_.recvfd < 0 && "garbage collecting open Connection");
- assert(stream_.sendfd < 0 && "garbage collecting open Connection");
+ assert(stream_.recvfd < 0 && "garbage collecting open Connection");
+ assert(stream_.sendfd < 0 && "garbage collecting open Connection");
}
Handle<Value>
@@ -146,7 +146,7 @@ Connection::Connect (const Arguments& args)
if (connection->ReadyState() != EVCOM_INITIALIZED) {
return ThrowException(String::New("Socket is not in CLOSED state."));
- }
+ }
assert(connection->stream_.recvfd < 0);
assert(connection->stream_.sendfd < 0);
@@ -169,19 +169,19 @@ Connection::Connect (const Arguments& args)
ev_ref(EV_DEFAULT_UC);
connection->Attach();
-
+
#ifdef __APPLE__
/* HACK: Bypass the thread pool and do it sync on Macintosh.
- * Experiecing strange error where execution halts on
+ * Experiecing strange error where execution halts on
* getaddrinfo() and CPU goes to 100%. FIXME.
*/
eio_req *req = static_cast<eio_req*>(malloc(sizeof(eio_req)));
req->data = connection;
Connection::Resolve(req);
#else
/* For the moment I will do DNS lookups in the eio thread pool. This is
- * sub-optimal and cannot handle massive numbers of requests.
- * In the future I will move to a system using adns or udns:
+ * sub-optimal and cannot handle massive numbers of requests.
+ * In the future I will move to a system using adns or udns:
* http://lists.schmorp.de/pipermail/libev/2009q1/000632.html
*/
eio_custom( Connection::Resolve
@@ -202,7 +202,7 @@ Connection::Resolve (eio_req *req)
assert(connection->attached_);
assert(connection->resolving_);
- req->result = getaddrinfo(connection->host_, connection->port_,
+ req->result = getaddrinfo(connection->host_, connection->port_,
&client_tcp_hints, &address);
req->ptr2 = address;
@@ -251,7 +251,7 @@ Connection::AfterResolve (eio_req *req)
int r = 0;
if (req->result == 0) r = connection->Connect(address->ai_addr);
- if (address_list) freeaddrinfo(address_list);
+ if (address_list) freeaddrinfo(address_list);
// no error. return.
if (req->result == 0) {
@@ -262,7 +262,7 @@ Connection::AfterResolve (eio_req *req)
/* RESOLVE ERROR */
/* TODO: the whole resolve process should be moved into evcom_stream.
- * The fact that I'm modifying a read-only variable here should be
+ * The fact that I'm modifying a read-only variable here should be
* good evidence of this.
*/
connection->stream_.errorno = req->result;
@@ -364,10 +364,10 @@ Connection::Send (const Arguments& args)
Connection *connection = ObjectWrap::Unwrap<Connection>(args.Holder());
assert(connection);
- if ( connection->ReadyState() != EVCOM_CONNECTED_RW
+ if ( connection->ReadyState() != EVCOM_CONNECTED_RW
&& connection->ReadyState() != EVCOM_CONNECTED_WO
)
- {
+ {
return ThrowException(String::New("Socket is not open for writing"));
}
@@ -377,7 +377,7 @@ Connection::Send (const Arguments& args)
// memory pool or ring buffer. Of course, expressing binary data as an
// array of integers is extremely inefficent. This can improved when v8
// bug 270 (http://code.google.com/p/v8/issues/detail?id=270) has been
- // addressed.
+ // addressed.
if (args[0]->IsString()) {
enum encoding enc = ParseEncoding(args[1]);
@@ -411,10 +411,10 @@ Connection::Send (const Arguments& args)
} else return ThrowException(String::New("Bad argument"));
- return Undefined();
+ return Undefined();
}
-void
+void
Connection::OnReceive (const void *buf, size_t len)
{
HandleScope scope;
@@ -438,13 +438,13 @@ Connection::OnReceive (const void *buf, size_t len)
argv[0] = chunk;
}
} else {
- argv[0] = Local<Value>::New(Null());
+ argv[0] = Local<Value>::New(Null());
}
Emit("receive", argc, argv);
}
-void
+void
Connection::OnClose ()
{
HandleScope scope;
@@ -529,7 +529,7 @@ Server::OnConnection (struct sockaddr *addr)
Local<Object> js_connection =
GetConnectionTemplate()->GetFunction()->NewInstance(0, NULL);
-
+
if (js_connection.IsEmpty()) {
FatalException(try_catch);
return NULL;
@@ -623,7 +623,7 @@ Server::Listen (const Arguments& args)
server->Listen(address->ai_addr, backlog);
- if (address_list) freeaddrinfo(address_list);
+ if (address_list) freeaddrinfo(address_list);
return Undefined();
}
View
12 src/net.h
@@ -32,7 +32,7 @@ class Connection : public EventEmitter {
static v8::Handle<v8::Value> ReadyStateGetter (v8::Local<v8::String> _,
const v8::AccessorInfo& info);
- Connection (void) : EventEmitter()
+ Connection (void) : EventEmitter()
{
encoding_ = RAW;
@@ -126,7 +126,7 @@ class Server : public EventEmitter {
static v8::Handle<v8::Value> Listen (const v8::Arguments& args);
static v8::Handle<v8::Value> Close (const v8::Arguments& args);
- Server (void) : EventEmitter()
+ Server (void) : EventEmitter()
{
evcom_server_init(&server_);
server_.on_connection = Server::on_connection;
@@ -138,16 +138,16 @@ class Server : public EventEmitter {
assert(server_.fd >= 0);
}
- int Listen (struct sockaddr *address, int backlog) {
- int r = evcom_server_listen (&server_, address, backlog);
+ int Listen (struct sockaddr *address, int backlog) {
+ int r = evcom_server_listen (&server_, address, backlog);
if(r != 0) return r;
- evcom_server_attach (EV_DEFAULT_ &server_);
+ evcom_server_attach (EV_DEFAULT_ &server_);
Attach();
return 0;
}
void Close ( ) {
- evcom_server_close (&server_);
+ evcom_server_close (&server_);
}
virtual v8::Handle<v8::FunctionTemplate> GetConnectionTemplate (void);
View
22 src/node.cc
@@ -10,7 +10,7 @@
#include "constants.h"
#include "node_stdio.h"
-#include "natives.h"
+#include "natives.h"
#include <stdio.h>
#include <stdlib.h>
@@ -94,16 +94,16 @@ v8::Handle<v8::Value>
node_exit (const v8::Arguments& args)
{
int r = 0;
- if (args.Length() > 0)
+ if (args.Length() > 0)
r = args[0]->IntegerValue();
exit(r);
- return Undefined();
+ return Undefined();
}
v8::Handle<v8::Value>
compile (const v8::Arguments& args)
{
- if (args.Length() < 2)
+ if (args.Length() < 2)
return Undefined();
HandleScope scope;
@@ -112,7 +112,7 @@ compile (const v8::Arguments& args)
Local<String> filename = args[1]->ToString();
Handle<Value> result = ExecuteString(source, filename);
-
+
return scope.Close(result);
}
@@ -123,7 +123,7 @@ OnFatalError (const char* location, const char* message)
#define FATAL_ERROR "\033[1;31mV8 FATAL ERROR.\033[m"
if (location)
fprintf(stderr, FATAL_ERROR " %s %s\n", location, message);
- else
+ else
fprintf(stderr, FATAL_ERROR " %s\n", message);
exit(1);
@@ -138,7 +138,7 @@ node::FatalException (TryCatch &try_catch)
static ev_async eio_watcher;
-static void
+static void
node_eio_cb (EV_P_ ev_async *watcher, int revents)
{
assert(watcher == &eio_watcher);
@@ -149,7 +149,7 @@ node_eio_cb (EV_P_ ev_async *watcher, int revents)
static void
eio_want_poll (void)
{
- ev_async_send(EV_DEFAULT_UC_ &eio_watcher);
+ ev_async_send(EV_DEFAULT_UC_ &eio_watcher);
}
enum encoding
@@ -266,7 +266,7 @@ PrintHelp ( )
}
static void
-ParseArgs (int *argc, char **argv)
+ParseArgs (int *argc, char **argv)
{
for (int i = 1; i < *argc; i++) {
const char *arg = argv[i];
@@ -283,7 +283,7 @@ ParseArgs (int *argc, char **argv)
}
int
-main (int argc, char *argv[])
+main (int argc, char *argv[])
{
evcom_ignore_sigpipe();
ev_default_loop(EVFLAG_AUTO); // initialize the default ev loop.
@@ -311,7 +311,7 @@ main (int argc, char *argv[])
// The global object / "process" is an instance of EventEmitter. For
// strange reasons we must initialize EventEmitter now! it will be assign
- // to it's namespace node.EventEmitter in Load() bellow.
+ // to it's namespace node.EventEmitter in Load() bellow.
EventEmitter::Initialize(process_template);
Persistent<Context> context = Context::New(NULL,
View
2 src/node.h
@@ -31,7 +31,7 @@ do { \
enum encoding {ASCII, UTF8, RAW};
enum encoding ParseEncoding (v8::Handle<v8::Value> encoding_v);
-void FatalException (v8::TryCatch &try_catch);
+void FatalException (v8::TryCatch &try_catch);
} // namespace node
#endif // node_h
View
4 src/object_wrap.h
@@ -17,7 +17,7 @@ class ObjectWrap {
assert(handle_.IsNearDeath());
handle_->SetInternalField(0, v8::Undefined());
handle_.Dispose();
- handle_.Clear();
+ handle_.Clear();
}
}
@@ -55,7 +55,7 @@ class ObjectWrap {
assert(handle_.IsWeak());
attached_++;
}
-
+
/* Detach() marks an object as detached from the event loop. This is its
* default state. When an object with a "weak" reference changes from
* attached to detached state it will be freed. Be careful not to access
View
2 src/process.h
@@ -58,5 +58,5 @@ class Process : EventEmitter {
int exit_code_;
};
-} // namespace node
+} // namespace node
#endif // node_process_h
View
2 src/timer.cc
@@ -42,7 +42,7 @@ Timer::RepeatGetter (Local<String> property, const AccessorInfo& info)
return scope.Close(v);
}
-void
+void
Timer::RepeatSetter (Local<String> property, Local<Value> value, const AccessorInfo& info)
{
HandleScope scope;
View
2 src/timer.h
@@ -29,5 +29,5 @@ class Timer : EventEmitter {
ev_timer watcher_;
};
-} // namespace node
+} // namespace node
#endif // node_timer_h
View
2 test/mjsunit/mjsunit.js
@@ -133,7 +133,7 @@ exports.assertThrows = function (code) {
} catch (e) {
// Do nothing.
}
- if (!threwException) {
+ if (!threwException) {
exports.assertTrue(false, "did not throw exception");
}
};
View
2 test/mjsunit/test-http-proxy.js
@@ -18,7 +18,7 @@ var proxy = node.http.createServer(function (req, res) {
var proxy_req = proxy_client.get(req.uri.path);
proxy_req.finish(function(proxy_res) {
res.sendHeader(proxy_res.statusCode, proxy_res.headers);
- proxy_res.addListener("body", function(chunk) {
+ proxy_res.addListener("body", function(chunk) {
res.sendBody(chunk);
});
proxy_res.addListener("complete", function() {
View
2 test/mjsunit/test-process-buffering.js
@@ -19,7 +19,7 @@ function pwd (callback) {
pwd(function (result) {
- p(result);
+ p(result);
assertTrue(result.length > 1);
assertEquals("\n", result[result.length-1]);
});
View
6 test/mjsunit/test-process-spawn-loop.js
@@ -4,12 +4,12 @@ var N = 40;
var finished = false;
function spawn (i) {
- var p = node.createProcess('python -c "print 500 * 1024 * \'C\'"');
+ var p = node.createProcess('python -c "print 500 * 1024 * \'C\'"');
var output = "";
- p.addListener("output", function(chunk) {
+ p.addListener("output", function(chunk) {
if (chunk) output += chunk;
- });
+ });
p.addListener("exit", function () {
//puts(output);
View
2 test/mjsunit/test-tcp-many-clients.js
@@ -49,7 +49,7 @@ function runClient (callback) {
if (this.connections < connections_per_client) {
this.connect(port);
} else {
- callback();
+ callback();
}
});
}
View
2 test/mjsunit/test-tcp-pingpong.js
@@ -51,7 +51,7 @@ function pingPongTest (port, host, on_complete) {
client.addListener("receive", function (data) {
assertEquals("PONG", data);
- count += 1;
+ count += 1;
if (sent_final_ping) {
assertEquals("readOnly", client.readyState);
View
2 test/mjsunit/test-tcp-reconnect.js
@@ -40,7 +40,7 @@ client.addListener("receive", function (chunk) {
client.addListener("close", function (had_error) {
puts("disconnect");
assertFalse(had_error);
- if (disconnect_count++ < N)
+ if (disconnect_count++ < N)
client.connect(port); // reconnect
else
server.close();
View
6 test/mjsunit/test-tcp-throttle.js
@@ -4,7 +4,7 @@ N = 200;
server = node.tcp.createServer(function (connection) {
function send (j) {
- if (j >= N) {
+ if (j >= N) {
connection.close();
return;
}
@@ -29,7 +29,7 @@ client.addListener("receive", function (d) {
});
setTimeout(function () {
- chars_recved = recv.length;
+ chars_recved = recv.length;
puts("pause at: " + chars_recved);
assertTrue(chars_recved > 1);
client.readPause();
@@ -39,7 +39,7 @@ setTimeout(function () {
client.readResume();
setTimeout(function () {
- chars_recved = recv.length;
+ chars_recved = recv.length;
puts("pause at: " + chars_recved);
client.readPause();
View
2 test/mjsunit/test-timers.js
@@ -29,7 +29,7 @@ setInterval(function () {
var t = interval_count * 1000;
assertTrue(t - WINDOW < diff && diff < t + WINDOW);
-
+
assertTrue(interval_count <= 3);
if (interval_count == 3)
clearInterval(this);
View
2 test/mjsunit/test-utf8-scripts.js
@@ -4,5 +4,5 @@ include("mjsunit.js");
puts("Σὲ γνωρίζω ἀπὸ τὴν κόψη");
-assertTrue( /Hellö Wörld/.test("Hellö Wörld") );
+assertTrue( /Hellö Wörld/.test("Hellö Wörld") );
View
121 website/api.txt
@@ -90,13 +90,16 @@ An array containing the command line arguments.
+__filename+ ::
The filename of the script being executed.
++process+ ::
+A special global object. The +process+ object is like the +window+ object of
+browser-side javascript.
=== Events
Many objects in Node emit events: a TCP server emits an event each time
there is a connection, a child process emits an event when it exits. All
-objects which emit events are are instances of +node.EventEmitter+.
+objects which emit events are are instances of +node.EventEmitter+.
Events are represented by a snakecased string. Here are some examples:
+"connection"+, +"receive"+, +"message_begin"+.
@@ -117,7 +120,7 @@ added.
|=========================================================
| Event | Parameters | Notes
-| +"newListener"+ | +event, listener+| This event is made
+| +"newListener"+ | +event, listener+| This event is made
any time someone adds
a new listener.
|=========================================================
@@ -132,7 +135,7 @@ server.addListener("connection", function (socket) {
----------------------------------------
-+emitter.listeners(event)+ ::
++emitter.listeners(event)+ ::
Returns an array of listeners for the specified event. This array can be
manipulated, e.g. to remove listeners.
@@ -148,8 +151,8 @@ emit anymore events.
[cols="1,2,10",options="header"]
|=========================================================
| Event | Parameters | Notes
-| +"success"+ | (depends) |
-| +"error"+ | (depends) |
+| +"success"+ | (depends) |
+| +"error"+ | (depends) |
|=========================================================
+promise.addCallback(listener)+ ::
@@ -174,14 +177,14 @@ If +"error"+ was emitted instead, +wait()+ throws an error.
Standard I/O is handled through a special object +node.stdio+. stdout and
stdin are fully non-blocking (even when piping to files). stderr is
-synchronous.
+synchronous.
[cols="1,2,10",options="header"]
|=========================================================
| Event | Parameters | Notes
| +"data"+ | +data+ | Made when stdin has received a chunk of data.
- Depending on the encoding that stdin was opened
+ Depending on the encoding that stdin was opened
with, +data+ will be either an array of integers
(raw encoding) or a string (ascii or utf8
encoding). This event will only be emited after
@@ -191,7 +194,7 @@ synchronous.
+node.stdio.open(encoding="utf8")+::
Open stdin. The program will not exit until +node.stdio.close()+ has been
-called or the +"close"+ event has been emitted.
+called or the +"close"+ event has been emitted.
+node.stdio.write(data)+::
Write data to stdout.
@@ -282,7 +285,7 @@ process.addListener("exit", function () {
----------------------------------------
Just to reiterate: the +"exit"+ event, is not the place to close files or
-shutdown servers. The process will exit before they get performed.
+shutdown servers. The process will exit before they get performed.
@@ -372,7 +375,7 @@ the +node+ namespace (+node.SIGINT+, +node.SIGUSR1+, ...).
=== File I/O
File I/O is provided by simple wrappers around standard POSIX functions.
-All POSIX wrappers have a similar form.
+All POSIX wrappers have a similar form.
They return a promise (+node.Promise+). Example:
------------------------------------------------------------------------------
@@ -413,7 +416,7 @@ node.fs.stat("/tmp/world").addCallback(function (stats) {
------------------------------------------------------------------------------
+node.fs.rename(path1, path2)+ ::
- See rename(2).
+ See rename(2).
- on success: no parameters.
- on error: no parameters.
@@ -524,20 +527,20 @@ multi-part bodies. _This is left to the user._
|=========================================================
|Event | Parameters | Notes
-|+"request"+ | +request, response+ |
+|+"request"+ | +request, response+ |
+request+ is an instance of +node.http.ServerRequest+
+
+response+ is an instance of +node.http.ServerResponse+
-|+"connection"+ | +connection+ |
-When a new TCP connection is established.
+|+"connection"+ | +connection+ |
+When a new TCP connection is established.
+connection+ is an object of type +node.http.Connection+. Usually users will not
want to access this event. The +connection+ can also be accessed at
+request.connection+.
|+"close"+ | +errorno+ | Emitted when the server closes. +errorno+
is an integer which indicates what, if any,
- error caused the server to close. If no
+ error caused the server to close. If no
error occured +errorno+ will be 0.
|=========================================================
@@ -571,14 +574,14 @@ the user--and passed as the first argument to a +"request"+ listener.
|=========================================================
|Event | Parameters | Notes
-|+"body"+ | +chunk+ |
+|+"body"+ | +chunk+ |
Emitted when a piece of the message body is received. Example: A chunk of
the body is given as the single argument. The transfer-encoding has been
decoded. The body chunk is either a String in the case of UTF-8 encoding or
an array of numbers in the case of raw encoding. The body encoding is set
with +request.setBodyEncoding()+.
-|+"complete"+ | |
+|+"complete"+ | |
Emitted exactly once for each message. No arguments.
After emitted no other events will be emitted on the request.
@@ -599,21 +602,21 @@ Accept: */*\r\n
\r\n
----------------------------------------
+
-Then +request.uri+ will be
+Then +request.uri+ will be
+
----------------------------------------
-{ path: "/status",
- file: "status",
- directory: "/",
- params: { "name" : "ryan" }
+{ path: "/status",
+ file: "status",
+ directory: "/",
+ params: { "name" : "ryan" }
}
----------------------------------------
+
In particular, note that +request.uri.protocol+ is
+undefined+. This is because there was no URI protocol given
-in the actual HTTP Request.
+in the actual HTTP Request.
+
-+request.uri.anchor+, +request.uri.query+, +request.uri.file+, +request.uri.directory+, +request.uri.path+, +request.uri.relative+, +request.uri.port+, +request.uri.host+, +request.uri.password+, +request.uri.user+, +request.uri.authority+, +request.uri.protocol+, +request.uri.params+, +request.uri.toString()+, +request.uri.source+
++request.uri.anchor+, +request.uri.query+, +request.uri.file+, +request.uri.directory+, +request.uri.path+, +request.uri.relative+, +request.uri.port+, +request.uri.host+, +request.uri.password+, +request.uri.user+, +request.uri.authority+, +request.uri.protocol+, +request.uri.params+, +request.uri.toString()+, +request.uri.source+
+request.headers+ ::
@@ -650,7 +653,7 @@ passed as the second parameter to the +"request"+ event.
+response.sendHeader(statusCode, headers)+ ::
Sends a response header to the request. The status code is a 3-digit HTTP
-status code, like +404+. The second argument, +headers+ are the response headers.
+status code, like +404+. The second argument, +headers+ are the response headers.
+
Example:
+
@@ -675,13 +678,13 @@ If +chunk+ is a string, the second parameter
specifies how to encode it into a byte stream. By default the
+encoding+ is +"ascii"+.
+
-Note: This is the raw HTTP body and has nothing to do with
-higher-level multi-part body encodings that may be used.
+Note: This is the raw HTTP body and has nothing to do with
+higher-level multi-part body encodings that may be used.
+response.finish()+ ::
This method signals to the server that all of the response headers and body
-has been sent; that server should consider this message complete.
+has been sent; that server should consider this message complete.
The method, +response.finish()+, MUST be called on each
response.
@@ -733,7 +736,7 @@ the header of the request. One needs to call
+request.finish()+ to finalize the request and retrieve
the response. (This sounds convoluted but it provides a chance
for the user to stream a body to the server with
-+request.sendBody()+.)
++request.sendBody()+.)
==== +node.http.ClientRequest+
@@ -761,7 +764,7 @@ Sends a sucessive peice of the body. By calling this method
many times, the user can stream a request body to a
server&mdash;in that case it is suggested to use the
+["Transfer-Encoding", "chunked"]+ header line when
-creating the request.
+creating the request.
+
The +chunk+ argument should be an array of integers
or a string.
@@ -779,7 +782,7 @@ Finishes sending the request. If any parts of the body are
unsent, it will flush them to the socket. If the request is
chunked, this will send the terminating +"0\r\n\r\n"+.
+
-The parameter +response_listener+ is a callback which
+The parameter +response_listener+ is a callback which
will be executed when the response headers have been received.
The +response_listener+ callback is executed with one
argument which is an instance of +node.http.ClientResponse+.
@@ -794,14 +797,14 @@ This object is created internally and passed to the +"response"+ event.
|=========================================================
|Event | Parameters | Notes
-|+"body"+ | +chunk+ |
+|+"body"+ | +chunk+ |
Emitted when a piece of the message body is received. Example: A chunk of
the body is given as the single argument. The transfer-encoding has been
decoded. The body chunk is either a String in the case of UTF-8 encoding or
an array of numbers in the case of raw encoding. The body encoding is set
with +response.setBodyEncoding()+.
-|+"complete"+ | |
+|+"complete"+ | |
Emitted exactly once for each message. No arguments.
After emitted no other events will be emitted on the response.
@@ -811,13 +814,13 @@ After emitted no other events will be emitted on the response.
The 3-digit HTTP response status code. E.G. +404+.
+response.httpVersion+ ::
- The HTTP version of the connected-to server. Probably either
+ The HTTP version of the connected-to server. Probably either
+"1.1"+ or +"1.0"+.
-+response.headers+ ::
++response.headers+ ::
The response headers.
-+response.setBodyEncoding(encoding)+ ::
++response.setBodyEncoding(encoding)+ ::
Set the encoding for the response body. Either +"utf8"+ or +"raw"+.
Defaults to raw.
@@ -865,7 +868,7 @@ server.listen(7000, "localhost");
+connection+ is an instance of +node.tcp.Connection+.
|+"close"+ | +errorno+ | Emitted when the server closes. +errorno+
is an integer which indicates what, if any,
- error caused the server to close. If no
+ error caused the server to close. If no
error occured +errorno+ will be 0.
|=========================================================
@@ -877,16 +880,16 @@ the +"connection"+ event.
+server.listen(port, host=null, backlog=1024)+ ::
-Tells the server to listen for TCP connections to +port+ and +host+.
+Tells the server to listen for TCP connections to +port+ and +host+.
+
+host+ is optional. If +host+ is not specified the server will accept client
connections on any network address.
+
The third argument, +backlog+, is also optional and defaults to 1024. The
+backlog+ argument defines the maximum length to which the queue of pending
-connections for the server may grow.
+connections for the server may grow.
+
-This function is synchronous.
+This function is synchronous.
+server.close()+::
@@ -904,46 +907,46 @@ socket for +node.tcp.Server+.
|=========================================================
|Event | Parameters | Notes
|+"connect"+ | | Call once the connection is established
- after a call to +createConnection()+ or
+ after a call to +createConnection()+ or
+connect()+.
-|+"receive"+ | +data+ | Called when data is received on the
- connection. Encoding of data is set
- by +connection.setEncoding()+. +data+
- will either be a string, in the case of
- utf8, or an array of integer in the case
+|+"receive"+ | +data+ | Called when data is received on the
+ connection. Encoding of data is set
+ by +connection.setEncoding()+. +data+
+ will either be a string, in the case of
+ utf8, or an array of integer in the case
of raw encoding.
-|+"eof"+ | | Called when the other end of the
+|+"eof"+ | | Called when the other end of the
connection sends a FIN packet.
- After this is emitted the +readyState+
- will be +"writeOnly"+. One should probably
+ After this is emitted the +readyState+
+ will be +"writeOnly"+. One should probably
just call +connection.close()+ when this
event is emitted.
|+"close"+ | +had_error+ | Emitted once the connection is fully
- closed. The argument +had_error+
+ closed. The argument +had_error+
is a boolean which says if the connection
was closed due to a transmission error.
(TODO: access error codes.)
|=========================================================
+node.tcp.createConnection(port, host="127.0.0.1")+::
Creates a new connection object and opens a connection to the specified
-+port+ and +host+. If the second parameter is omitted, localhost is assumed.
++port+ and +host+. If the second parameter is omitted, localhost is assumed.
+
When the connection is established the +"connect"+ event will be emitted.
+connection.connect(port, host="127.0.0.1")+::
Opens a connection to the specified +port+ and +host+. +createConnection()+
also opens a connection; normally this method is not needed. Use this only
if a connection is closed and you want to reuse the object to connect to
-another server.
+another server.
+
This function is asynchronous. When the +"connect"+ event is emitted the
connection is established. If there is a problem connecting, the +"connect"+
event will not be emitted, the +"close"+ event will be emitted with
+had_error == true+.
+connection.remoteAddress+::
-The string representation of the remote IP address. For example,
+The string representation of the remote IP address. For example,
+"74.125.127.100"+ or +"2001:4860:a005::68"+.
+
This member is only present in server-side connections.
@@ -954,7 +957,7 @@ Either +"closed"+, +"open"+, +"opening"+, +"readOnly"+, or +"writeOnly"+.
+connection.setEncoding(encoding)+::
-Sets the encoding (either +"utf8"+ or +"raw"+) for data that is received.
+Sets the encoding (either +"utf8"+ or +"raw"+) for data that is received.
+connection.send(data, encoding="ascii")+::
Sends data on the connection. The data should be eithre an array
@@ -986,7 +989,7 @@ Resumes reading if reading was paused by +readPause()+.
=== DNS
Here is an example of which resolves +"www.google.com"+ then reverse
-resolves the IP addresses which are returned.
+resolves the IP addresses which are returned.
-------------------------------------------------------------------------
var resolution = node.dns.resolve4("www.google.com");
@@ -1018,26 +1021,26 @@ resolution.addErrback(function (code, msg) {
Resolves a domain (e.g. +"google.com"+) into an array of IPv4 addresses (e.g.
+["74.125.79.104", "74.125.79.105", "74.125.79.106"]+).
-This function returns a promise.
+This function returns a promise.
- on success: returns +addresses, ttl, cname+. +ttl+ (time-to-live) is an integer
specifying the number of seconds this result is valid for. +cname+ is the
canonical name for the query.
- on error: returns +code, msg+. +code+ is one of the error codes listed
- below and +msg+ is a string describing the error in English.
+ below and +msg+ is a string describing the error in English.
+node.dns.resolve6(domain)+::
The same as +node.dns.resolve4()+ except for IPv6 queries (an +AAAA+ query).
+node.dns.reverse(ip)+::
-Reverse resolves an ip address to an array of domain names.
+Reverse resolves an ip address to an array of domain names.
- on success: returns +domains, ttl, cname+. +ttl+ (time-to-live) is an integer
specifying the number of seconds this result is valid for. +cname+ is the
canonical name for the query. +domains+ is an array of domains.
- on error: returns +code, msg+. +code+ is one of the error codes listed
- below and +msg+ is a string describing the error in English.
+ below and +msg+ is a string describing the error in English.
Each DNS query can return an error code.
View
26 website/index.html
@@ -6,7 +6,7 @@
padding: 0;
margin: 0;
}
- </style>
+ </style>
<script type="text/javascript" src="sh_main.js"></script>
<script type="text/javascript" src="sh_javascript.min.js"></script>
<link type="text/css" rel="stylesheet" href="pipe.css" />
@@ -39,7 +39,7 @@
An example of a web server written with Node which responds with
"Hello World" after waiting two seconds:
</p>
-
+
<pre>
node.http.createServer(function (req, res) {
setTimeout(function () {
@@ -49,7 +49,7 @@
}, 2000);
}).listen(8000);
puts("Server running at http://127.0.0.1:8000/");</pre>
-
+
<p>
To run the server, put the code into a file
<code>example.js</code> and execute it with the <code>node</code>
@@ -58,7 +58,7 @@
<pre class="sh_none">
% /usr/local/bin/node example.js
Server running at http://127.0.0.1:8000/</pre>
-
+
<p>
See the <a href="api.html">API documentation</a> for more
examples.
@@ -80,24 +80,24 @@ <h2 id="about">About</h2>
programs. In the above example, the two second delay does not
prevent the server from handling new requests. Node tells the
operating system (through <code>epoll</code>, <code>kqueue</code>,
- <code class="sh_none">/dev/poll</code>, or <code>select</code>)
+ <code class="sh_none">/dev/poll</code>, or <code>select</code>)
that it should be notified when the 2 seconds are up or if a new
connection is made&mdash;then it goes to sleep. If someone new
connects, then it executes the callback, if the timeout expires,
it executes the inner callback. Each connection is only a small
heap allocation.
</p>
-
+
<p>
This is in contrast to today's more common model where OS threads
- are employed for concurrency. Thread-based networking
+ are employed for concurrency. Thread-based networking
<a href="http://www.sics.se/~joe/apachevsyaws.html">is</a>
<a href="http://www.kegel.com/c10k.html">relatively</a>
<a href="http://bulk.fefe.de/scalable-networking.pdf">inefficient</a>
<!-- TODO needs links -->
- and very difficult to use.
+ and very difficult to use.
- Node will show much better memory efficiency under high-loads
+ Node will show much better memory efficiency under high-loads
<!-- TODO benchmark -->
than systems which allocate 2mb thread stacks for each connection.
@@ -122,7 +122,7 @@ <h2 id="about">About</h2>
no more callbacks to perform. This behavior is like browser
javascript&mdash;the event loop is hidden from the user.
</p>
-
+
<p>
Node's HTTP library has grown out of my difficulties developing and
working with web servers. For example, streaming data through most
@@ -131,7 +131,7 @@ <h2 id="about">About</h2>
infrastructure, it makes a good foundation for web libraries or
frameworks.
</p>
-
+
<p>
<i>
But what about multiple-processor concurrency? Threads are
@@ -168,7 +168,7 @@ <h2 id="build">Build</h2>
built, supports only IA-32 and ARM processors. V8 is included in the
Node distribution. There are no dependencies.
</p>
-
+
<pre class="sh_none">
./configure
make
@@ -181,7 +181,7 @@ <h2 id="build">Build</h2>
<p>To run the tests</p>
<pre class="sh_none">make test</pre>
-
+
<h2 id="demo">Demo</h2>
<p>
A chat room demo is running at <a

0 comments on commit 116f4de

Please sign in to comment.