From 3884b4185a72d63ee0344d16390eea852e8b1f89 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 18 Nov 2010 11:18:07 -0800 Subject: [PATCH] Small clean ups --- lib/net.js | 6 ++++++ src/node_buffer.cc | 4 ++-- src/node_buffer.h | 2 +- src/node_io_watcher.cc | 7 +++---- test/simple/test-pipe.js | 14 +++++++++++--- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/net.js b/lib/net.js index 6d0aef9ca8..38b804eb43 100644 --- a/lib/net.js +++ b/lib/net.js @@ -207,6 +207,11 @@ Stream.prototype._onTimeout = function () { }; +Stream.prototype.writeQueueSize = function () { + return this._writeWatcher.queueSize || 0; +}; + + Stream.prototype.open = function (fd, type) { initStream(this); @@ -532,6 +537,7 @@ Stream.prototype.pause = function () { Stream.prototype.resume = function () { if (this.fd === null) throw new Error('Cannot resume() closed Stream.'); + this._readWatcher.stop(); this._readWatcher.set(this.fd, true, false); this._readWatcher.start(); }; diff --git a/src/node_buffer.cc b/src/node_buffer.cc index d838577a15..d95cf515ee 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -82,8 +82,8 @@ static size_t ByteLength (Handle string, enum encoding enc) { } -Handle Buffer::New(Handle string, - Handle encoding) { +Local Buffer::New(Handle string, + Handle encoding) { HandleScope scope; // get Buffer from global scope. diff --git a/src/node_buffer.h b/src/node_buffer.h index efc982ecf7..34b353d799 100644 --- a/src/node_buffer.h +++ b/src/node_buffer.h @@ -25,7 +25,7 @@ class Buffer : public ObjectWrap { typedef void (*free_callback)(char *data, void *hint); // C++ API for constructing fast buffer - static v8::Handle New( + static v8::Local New( v8::Handle string, v8::Handle encoding = v8::Handle()); diff --git a/src/node_io_watcher.cc b/src/node_io_watcher.cc index 45bc424eea..71a640cb0e 100644 --- a/src/node_io_watcher.cc +++ b/src/node_io_watcher.cc @@ -344,12 +344,11 @@ void IOWatcher::Dump() { // TODO: insert v8::String::Pointers() hack here. Local s = data_v->ToString(); Local e = bucket->Get(encoding_sym); - buf_object = Local::New(Buffer::New(s, e)); + buf_object = Buffer::New(s, e); bucket->Set(data_sym, buf_object); - } else if (Buffer::HasInstance(data_v)) { - buf_object = data_v->ToObject(); } else { - assert(0); + assert(Buffer::HasInstance(data_v)); + buf_object = data_v->ToObject(); } size_t l = Buffer::Length(buf_object); diff --git a/test/simple/test-pipe.js b/test/simple/test-pipe.js index 75db48eabb..3341e875ca 100644 --- a/test/simple/test-pipe.js +++ b/test/simple/test-pipe.js @@ -17,20 +17,22 @@ var bufferSize = 5 * 1024 * 1024; */ var buffer = Buffer(bufferSize); for (var i = 0; i < buffer.length; i++) { - buffer[i] = parseInt(Math.random()*10000) % 256; + buffer[i] = 100; //parseInt(Math.random()*10000) % 256; } var web = http.Server(function (req, res) { web.close(); + console.log("web server connection fd=%d", req.connection.fd); + console.log(req.headers); var socket = net.Stream(); socket.connect(tcpPort); socket.on('connect', function () { - console.log('socket connected'); + console.log('http->tcp connected fd=%d', socket.fd); }); req.pipe(socket); @@ -54,7 +56,7 @@ web.listen(webPort, startClient); var tcp = net.Server(function (s) { tcp.close(); - console.log("tcp server connection"); + console.log("tcp server connection fd=%d", s.fd); var i = 0; @@ -91,6 +93,12 @@ function startClient () { req.write(buffer); req.end(); + + console.log("request fd=%d", req.connection.fd); + + // note the queue includes http headers. + assert.ok(req.connection.writeQueueSize() > buffer.length); + req.on('response', function (res) { console.log('Got response'); res.setEncoding('utf8');