{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.
This commit is contained in:
Родитель
fa10b757f5
Коммит
278183a902
|
@ -239,12 +239,12 @@ function socketOnEnd() {
|
|||
socket.destroy();
|
||||
}
|
||||
|
||||
function socketOnData(d, start, end) {
|
||||
function socketOnData(d) {
|
||||
var socket = this;
|
||||
var req = this._httpMessage;
|
||||
var parser = this.parser;
|
||||
|
||||
var ret = parser.execute(d, start, end - start);
|
||||
var ret = parser.execute(d);
|
||||
if (ret instanceof Error) {
|
||||
debug('parse error');
|
||||
freeParser(parser, req);
|
||||
|
@ -261,8 +261,7 @@ function socketOnData(d, start, end) {
|
|||
socket.onend = null;
|
||||
parser.finish();
|
||||
|
||||
// This is start + byteParsed
|
||||
var bodyHead = d.slice(start + bytesParsed, end);
|
||||
var bodyHead = d.slice(bytesParsed, d.length);
|
||||
|
||||
var eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade';
|
||||
if (EventEmitter.listenerCount(req, eventName) > 0) {
|
||||
|
|
|
@ -336,8 +336,8 @@ function connectionListener(socket) {
|
|||
self.emit('clientError', e, this);
|
||||
});
|
||||
|
||||
socket.ondata = function(d, start, end) {
|
||||
var ret = parser.execute(d, start, end - start);
|
||||
socket.ondata = function(d) {
|
||||
var ret = parser.execute(d);
|
||||
if (ret instanceof Error) {
|
||||
debug('parse error');
|
||||
socket.destroy(ret);
|
||||
|
@ -354,8 +354,7 @@ function connectionListener(socket) {
|
|||
|
||||
var eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade';
|
||||
if (EventEmitter.listenerCount(self, eventName) > 0) {
|
||||
// This is start + byteParsed
|
||||
var bodyHead = d.slice(start + bytesParsed, end);
|
||||
var bodyHead = d.slice(bytesParsed, d.length);
|
||||
|
||||
self.emit(eventName, req, req.socket, bodyHead);
|
||||
} else {
|
||||
|
|
|
@ -325,9 +325,9 @@ function setupChannel(target, channel) {
|
|||
var decoder = new StringDecoder('utf8');
|
||||
var jsonBuffer = '';
|
||||
channel.buffering = false;
|
||||
channel.onread = function(pool, offset, length, recvHandle) {
|
||||
channel.onread = function(pool, recvHandle) {
|
||||
if (pool) {
|
||||
jsonBuffer += decoder.write(pool.slice(offset, offset + length));
|
||||
jsonBuffer += decoder.write(pool);
|
||||
|
||||
var i, start = 0;
|
||||
|
||||
|
|
|
@ -414,13 +414,13 @@ Socket.prototype._stopReceiving = function() {
|
|||
};
|
||||
|
||||
|
||||
function onMessage(handle, slab, start, len, rinfo) {
|
||||
function onMessage(handle, buf, rinfo) {
|
||||
var self = handle.owner;
|
||||
if (!slab) {
|
||||
if (!buf) {
|
||||
return self.emit('error', errnoException(process._errno, 'recvmsg'));
|
||||
}
|
||||
rinfo.size = len; // compatibility
|
||||
self.emit('message', slab.slice(start, start + len), rinfo);
|
||||
rinfo.size = buf.length; // compatibility
|
||||
self.emit('message', buf, rinfo);
|
||||
}
|
||||
|
||||
|
||||
|
|
12
lib/net.js
12
lib/net.js
|
@ -483,15 +483,15 @@ Socket.prototype.destroy = function(exception) {
|
|||
|
||||
// This function is called whenever the handle gets a
|
||||
// buffer, or when there's an error reading.
|
||||
function onread(buffer, offset, length) {
|
||||
function onread(buffer) {
|
||||
var handle = this;
|
||||
var self = handle.owner;
|
||||
var length = !!buffer ? buffer.length : 0;
|
||||
assert(handle === self._handle, 'handle != self._handle');
|
||||
|
||||
timers._unrefActive(self);
|
||||
|
||||
var end = offset + length;
|
||||
debug('onread', process._errno, offset, length, end);
|
||||
debug('onread', process._errno, length);
|
||||
|
||||
if (buffer) {
|
||||
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.
|
||||
// wait for the next one.
|
||||
if (offset === end) {
|
||||
if (length === 0) {
|
||||
debug('not any data, keep waiting');
|
||||
return;
|
||||
}
|
||||
|
@ -514,8 +514,8 @@ function onread(buffer, offset, length) {
|
|||
|
||||
// Optimization: emit the original buffer with end points
|
||||
var ret = true;
|
||||
if (self.ondata) self.ondata(buffer, offset, end);
|
||||
else ret = self.push(buffer.slice(offset, end));
|
||||
if (self.ondata) self.ondata(buffer);
|
||||
else ret = self.push(buffer);
|
||||
|
||||
if (handle.reading && !ret) {
|
||||
handle.reading = false;
|
||||
|
|
|
@ -378,7 +378,7 @@ public:
|
|||
}
|
||||
|
||||
|
||||
// var bytesParsed = parser->execute(buffer, off, len);
|
||||
// var bytesParsed = parser->execute(buffer);
|
||||
static Handle<Value> Execute(const Arguments& args) {
|
||||
HandleScope scope(node_isolate);
|
||||
|
||||
|
@ -403,18 +403,6 @@ public:
|
|||
char *buffer_data = Buffer::Data(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.
|
||||
current_buffer = &buffer_v;
|
||||
current_buffer_data = buffer_data;
|
||||
|
@ -422,7 +410,7 @@ public:
|
|||
parser->got_exception_ = false;
|
||||
|
||||
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();
|
||||
|
||||
|
@ -437,7 +425,7 @@ public:
|
|||
Local<Integer> nparsed_obj = Integer::New(nparsed, node_isolate);
|
||||
// If there was a parse error in one of the callbacks
|
||||
// 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_);
|
||||
|
||||
Local<Value> e = Exception::Error(String::NewSymbol("Parse Error"));
|
||||
|
|
|
@ -613,11 +613,9 @@ void StreamWrapCallbacks::DoRead(uv_stream_t* handle,
|
|||
|
||||
assert(static_cast<size_t>(nread) <= buf.len);
|
||||
|
||||
int argc = 3;
|
||||
Local<Value> argv[4] = {
|
||||
Buffer::Use(buf.base, nread),
|
||||
Uint32::New(0, node_isolate),
|
||||
Uint32::New(nread, node_isolate)
|
||||
int argc = 1;
|
||||
Local<Value> argv[2] = {
|
||||
Buffer::Use(buf.base, nread)
|
||||
};
|
||||
|
||||
Local<Object> pending_obj;
|
||||
|
@ -632,7 +630,7 @@ void StreamWrapCallbacks::DoRead(uv_stream_t* handle,
|
|||
}
|
||||
|
||||
if (!pending_obj.IsEmpty()) {
|
||||
argv[3] = pending_obj;
|
||||
argv[1] = pending_obj;
|
||||
argc++;
|
||||
}
|
||||
|
||||
|
|
|
@ -478,13 +478,8 @@ void TLSCallbacks::ClearOut() {
|
|||
do {
|
||||
read = SSL_read(ssl_, out, sizeof(out));
|
||||
if (read > 0) {
|
||||
Local<Value> buff = Buffer::New(out, read);
|
||||
Handle<Value> argv[3] = {
|
||||
buff,
|
||||
Integer::New(0, node_isolate),
|
||||
Integer::New(read, node_isolate)
|
||||
};
|
||||
MakeCallback(Self(), onread_sym, ARRAY_SIZE(argv), argv);
|
||||
Handle<Value> buf = Buffer::New(out, read);
|
||||
MakeCallback(Self(), onread_sym, 1, &buf);
|
||||
}
|
||||
} while (read > 0);
|
||||
|
||||
|
|
|
@ -409,8 +409,6 @@ void UDPWrap::OnRecv(uv_udp_t* handle,
|
|||
Local<Value> argv[] = {
|
||||
Local<Object>::New(node_isolate, wrap->object_),
|
||||
Buffer::Use(buf.base, nread),
|
||||
Uint32::New(0, node_isolate),
|
||||
Uint32::New(nread, node_isolate),
|
||||
AddressToJS(addr)
|
||||
};
|
||||
MakeCallback(wrap->object_, onmessage_sym, ARRAY_SIZE(argv), argv);
|
||||
|
|
|
@ -49,13 +49,13 @@ server.onconnection = function(client) {
|
|||
|
||||
client.readStart();
|
||||
client.pendingWrites = [];
|
||||
client.onread = function(buffer, offset, length) {
|
||||
client.onread = function(buffer) {
|
||||
if (buffer) {
|
||||
assert.ok(length > 0);
|
||||
assert.ok(buffer.length > 0);
|
||||
|
||||
assert.equal(0, client.writeQueueSize);
|
||||
|
||||
var req = client.writeBuffer(buffer.slice(offset, offset + length));
|
||||
var req = client.writeBuffer(buffer);
|
||||
client.pendingWrites.push(req);
|
||||
|
||||
console.log('client.writeQueueSize: ' + client.writeQueueSize);
|
||||
|
|
Загрузка…
Ссылка в новой задаче