Browse Source

{stream,udp,tls}_wrap: remove unused offset/length

The function arguments offset and length are now no longer used since
all I/O requests now use discretely allocated memory.
v0.11.4-release
Trevor Norris 12 years ago
parent
commit
278183a902
  1. 7
      lib/_http_client.js
  2. 7
      lib/_http_server.js
  3. 4
      lib/child_process.js
  4. 8
      lib/dgram.js
  5. 12
      lib/net.js
  6. 18
      src/node_http_parser.cc
  7. 10
      src/stream_wrap.cc
  8. 9
      src/tls_wrap.cc
  9. 2
      src/udp_wrap.cc
  10. 6
      test/simple/test-tcp-wrap-listen.js

7
lib/_http_client.js

@ -239,12 +239,12 @@ function socketOnEnd() {
socket.destroy(); socket.destroy();
} }
function socketOnData(d, start, end) { function socketOnData(d) {
var socket = this; var socket = this;
var req = this._httpMessage; var req = this._httpMessage;
var parser = this.parser; var parser = this.parser;
var ret = parser.execute(d, start, end - start); var ret = parser.execute(d);
if (ret instanceof Error) { if (ret instanceof Error) {
debug('parse error'); debug('parse error');
freeParser(parser, req); freeParser(parser, req);
@ -261,8 +261,7 @@ function socketOnData(d, start, end) {
socket.onend = null; socket.onend = null;
parser.finish(); parser.finish();
// This is start + byteParsed var bodyHead = d.slice(bytesParsed, d.length);
var bodyHead = d.slice(start + bytesParsed, end);
var eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade'; var eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade';
if (EventEmitter.listenerCount(req, eventName) > 0) { if (EventEmitter.listenerCount(req, eventName) > 0) {

7
lib/_http_server.js

@ -336,8 +336,8 @@ function connectionListener(socket) {
self.emit('clientError', e, this); self.emit('clientError', e, this);
}); });
socket.ondata = function(d, start, end) { socket.ondata = function(d) {
var ret = parser.execute(d, start, end - start); var ret = parser.execute(d);
if (ret instanceof Error) { if (ret instanceof Error) {
debug('parse error'); debug('parse error');
socket.destroy(ret); socket.destroy(ret);
@ -354,8 +354,7 @@ function connectionListener(socket) {
var eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade'; var eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade';
if (EventEmitter.listenerCount(self, eventName) > 0) { if (EventEmitter.listenerCount(self, eventName) > 0) {
// This is start + byteParsed var bodyHead = d.slice(bytesParsed, d.length);
var bodyHead = d.slice(start + bytesParsed, end);
self.emit(eventName, req, req.socket, bodyHead); self.emit(eventName, req, req.socket, bodyHead);
} else { } else {

4
lib/child_process.js

@ -325,9 +325,9 @@ function setupChannel(target, channel) {
var decoder = new StringDecoder('utf8'); var decoder = new StringDecoder('utf8');
var jsonBuffer = ''; var jsonBuffer = '';
channel.buffering = false; channel.buffering = false;
channel.onread = function(pool, offset, length, recvHandle) { channel.onread = function(pool, recvHandle) {
if (pool) { if (pool) {
jsonBuffer += decoder.write(pool.slice(offset, offset + length)); jsonBuffer += decoder.write(pool);
var i, start = 0; var i, start = 0;

8
lib/dgram.js

@ -414,13 +414,13 @@ Socket.prototype._stopReceiving = function() {
}; };
function onMessage(handle, slab, start, len, rinfo) { function onMessage(handle, buf, rinfo) {
var self = handle.owner; var self = handle.owner;
if (!slab) { if (!buf) {
return self.emit('error', errnoException(process._errno, 'recvmsg')); return self.emit('error', errnoException(process._errno, 'recvmsg'));
} }
rinfo.size = len; // compatibility rinfo.size = buf.length; // compatibility
self.emit('message', slab.slice(start, start + len), rinfo); self.emit('message', buf, rinfo);
} }

12
lib/net.js

@ -483,15 +483,15 @@ Socket.prototype.destroy = function(exception) {
// This function is called whenever the handle gets a // This function is called whenever the handle gets a
// buffer, or when there's an error reading. // buffer, or when there's an error reading.
function onread(buffer, offset, length) { function onread(buffer) {
var handle = this; var handle = this;
var self = handle.owner; var self = handle.owner;
var length = !!buffer ? buffer.length : 0;
assert(handle === self._handle, 'handle != self._handle'); assert(handle === self._handle, 'handle != self._handle');
timers._unrefActive(self); timers._unrefActive(self);
var end = offset + length; debug('onread', process._errno, length);
debug('onread', process._errno, offset, length, end);
if (buffer) { if (buffer) {
debug('got data'); debug('got data');
@ -503,7 +503,7 @@ function onread(buffer, offset, length) {
// if we didn't get any bytes, that doesn't necessarily mean EOF. // if we didn't get any bytes, that doesn't necessarily mean EOF.
// wait for the next one. // wait for the next one.
if (offset === end) { if (length === 0) {
debug('not any data, keep waiting'); debug('not any data, keep waiting');
return; return;
} }
@ -514,8 +514,8 @@ function onread(buffer, offset, length) {
// Optimization: emit the original buffer with end points // Optimization: emit the original buffer with end points
var ret = true; var ret = true;
if (self.ondata) self.ondata(buffer, offset, end); if (self.ondata) self.ondata(buffer);
else ret = self.push(buffer.slice(offset, end)); else ret = self.push(buffer);
if (handle.reading && !ret) { if (handle.reading && !ret) {
handle.reading = false; handle.reading = false;

18
src/node_http_parser.cc

@ -378,7 +378,7 @@ public:
} }
// var bytesParsed = parser->execute(buffer, off, len); // var bytesParsed = parser->execute(buffer);
static Handle<Value> Execute(const Arguments& args) { static Handle<Value> Execute(const Arguments& args) {
HandleScope scope(node_isolate); HandleScope scope(node_isolate);
@ -403,18 +403,6 @@ public:
char *buffer_data = Buffer::Data(buffer_obj); char *buffer_data = Buffer::Data(buffer_obj);
size_t buffer_len = Buffer::Length(buffer_obj); size_t buffer_len = Buffer::Length(buffer_obj);
size_t off = args[1]->Int32Value();
if (off >= buffer_len) {
return ThrowException(Exception::Error(
String::New("Offset is out of bounds")));
}
size_t len = args[2]->Int32Value();
if (off+len > buffer_len) {
return ThrowException(Exception::Error(
String::New("off + len > buffer.length")));
}
// Assign 'buffer_' while we parse. The callbacks will access that varible. // Assign 'buffer_' while we parse. The callbacks will access that varible.
current_buffer = &buffer_v; current_buffer = &buffer_v;
current_buffer_data = buffer_data; current_buffer_data = buffer_data;
@ -422,7 +410,7 @@ public:
parser->got_exception_ = false; parser->got_exception_ = false;
size_t nparsed = size_t nparsed =
http_parser_execute(&parser->parser_, &settings, buffer_data + off, len); http_parser_execute(&parser->parser_, &settings, buffer_data, buffer_len);
parser->Save(); parser->Save();
@ -437,7 +425,7 @@ public:
Local<Integer> nparsed_obj = Integer::New(nparsed, node_isolate); Local<Integer> nparsed_obj = Integer::New(nparsed, node_isolate);
// If there was a parse error in one of the callbacks // If there was a parse error in one of the callbacks
// TODO What if there is an error on EOF? // TODO What if there is an error on EOF?
if (!parser->parser_.upgrade && nparsed != len) { if (!parser->parser_.upgrade && nparsed != buffer_len) {
enum http_errno err = HTTP_PARSER_ERRNO(&parser->parser_); enum http_errno err = HTTP_PARSER_ERRNO(&parser->parser_);
Local<Value> e = Exception::Error(String::NewSymbol("Parse Error")); Local<Value> e = Exception::Error(String::NewSymbol("Parse Error"));

10
src/stream_wrap.cc

@ -613,11 +613,9 @@ void StreamWrapCallbacks::DoRead(uv_stream_t* handle,
assert(static_cast<size_t>(nread) <= buf.len); assert(static_cast<size_t>(nread) <= buf.len);
int argc = 3; int argc = 1;
Local<Value> argv[4] = { Local<Value> argv[2] = {
Buffer::Use(buf.base, nread), Buffer::Use(buf.base, nread)
Uint32::New(0, node_isolate),
Uint32::New(nread, node_isolate)
}; };
Local<Object> pending_obj; Local<Object> pending_obj;
@ -632,7 +630,7 @@ void StreamWrapCallbacks::DoRead(uv_stream_t* handle,
} }
if (!pending_obj.IsEmpty()) { if (!pending_obj.IsEmpty()) {
argv[3] = pending_obj; argv[1] = pending_obj;
argc++; argc++;
} }

9
src/tls_wrap.cc

@ -478,13 +478,8 @@ void TLSCallbacks::ClearOut() {
do { do {
read = SSL_read(ssl_, out, sizeof(out)); read = SSL_read(ssl_, out, sizeof(out));
if (read > 0) { if (read > 0) {
Local<Value> buff = Buffer::New(out, read); Handle<Value> buf = Buffer::New(out, read);
Handle<Value> argv[3] = { MakeCallback(Self(), onread_sym, 1, &buf);
buff,
Integer::New(0, node_isolate),
Integer::New(read, node_isolate)
};
MakeCallback(Self(), onread_sym, ARRAY_SIZE(argv), argv);
} }
} while (read > 0); } while (read > 0);

2
src/udp_wrap.cc

@ -409,8 +409,6 @@ void UDPWrap::OnRecv(uv_udp_t* handle,
Local<Value> argv[] = { Local<Value> argv[] = {
Local<Object>::New(node_isolate, wrap->object_), Local<Object>::New(node_isolate, wrap->object_),
Buffer::Use(buf.base, nread), Buffer::Use(buf.base, nread),
Uint32::New(0, node_isolate),
Uint32::New(nread, node_isolate),
AddressToJS(addr) AddressToJS(addr)
}; };
MakeCallback(wrap->object_, onmessage_sym, ARRAY_SIZE(argv), argv); MakeCallback(wrap->object_, onmessage_sym, ARRAY_SIZE(argv), argv);

6
test/simple/test-tcp-wrap-listen.js

@ -49,13 +49,13 @@ server.onconnection = function(client) {
client.readStart(); client.readStart();
client.pendingWrites = []; client.pendingWrites = [];
client.onread = function(buffer, offset, length) { client.onread = function(buffer) {
if (buffer) { if (buffer) {
assert.ok(length > 0); assert.ok(buffer.length > 0);
assert.equal(0, client.writeQueueSize); assert.equal(0, client.writeQueueSize);
var req = client.writeBuffer(buffer.slice(offset, offset + length)); var req = client.writeBuffer(buffer);
client.pendingWrites.push(req); client.pendingWrites.push(req);
console.log('client.writeQueueSize: ' + client.writeQueueSize); console.log('client.writeQueueSize: ' + client.writeQueueSize);

Loading…
Cancel
Save