Browse Source

Small clean ups

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
3884b4185a
  1. 6
      lib/net.js
  2. 2
      src/node_buffer.cc
  3. 2
      src/node_buffer.h
  4. 7
      src/node_io_watcher.cc
  5. 14
      test/simple/test-pipe.js

6
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();
};

2
src/node_buffer.cc

@ -82,7 +82,7 @@ static size_t ByteLength (Handle<String> string, enum encoding enc) {
}
Handle<Object> Buffer::New(Handle<String> string,
Local<Object> Buffer::New(Handle<String> string,
Handle<Value> encoding) {
HandleScope scope;

2
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<v8::Object> New(
static v8::Local<v8::Object> New(
v8::Handle<v8::String> string,
v8::Handle<v8::Value> encoding = v8::Handle<v8::Value>());

7
src/node_io_watcher.cc

@ -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);

14
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');

Loading…
Cancel
Save