Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Small clean ups
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Nov 19, 2010
1 parent 02039c9 commit 3884b41
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
6 changes: 6 additions & 0 deletions lib/net.js
Expand Up @@ -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);

Expand Down Expand Up @@ -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();
};
Expand Down
4 changes: 2 additions & 2 deletions src/node_buffer.cc
Expand Up @@ -82,8 +82,8 @@ static size_t ByteLength (Handle<String> string, enum encoding enc) {
}


Handle<Object> Buffer::New(Handle<String> string,
Handle<Value> encoding) {
Local<Object> Buffer::New(Handle<String> string,
Handle<Value> encoding) {
HandleScope scope;

// get Buffer from global scope.
Expand Down
2 changes: 1 addition & 1 deletion src/node_buffer.h
Expand Up @@ -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<v8::Object> New(
static v8::Local<v8::Object> New(
v8::Handle<v8::String> string,
v8::Handle<v8::Value> encoding = v8::Handle<v8::Value>());

Expand Down
7 changes: 3 additions & 4 deletions src/node_io_watcher.cc
Expand Up @@ -344,12 +344,11 @@ void IOWatcher::Dump() {
// TODO: insert v8::String::Pointers() hack here.
Local<String> s = data_v->ToString();
Local<Value> e = bucket->Get(encoding_sym);
buf_object = Local<Object>::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);
Expand Down
14 changes: 11 additions & 3 deletions test/simple/test-pipe.js
Expand Up @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 3884b41

Please sign in to comment.