net: fix socket.bytesWritten Buffers support
Buffer.byteLength() works only for string inputs. Thus, when connection has pending Buffer to write, it should just use it's length instead of throwing exception.
This commit is contained in:
parent
eeb4c3216d
commit
c665b8e9ba
@ -667,10 +667,16 @@ Socket.prototype.__defineGetter__('bytesWritten', function() {
|
||||
encoding = this._pendingEncoding;
|
||||
|
||||
state.buffer.forEach(function(el) {
|
||||
if (Buffer.isBuffer(el.chunk))
|
||||
bytes += el.chunk.length;
|
||||
else
|
||||
bytes += Buffer.byteLength(el.chunk, el.encoding);
|
||||
});
|
||||
|
||||
if (data)
|
||||
if (Buffer.isBuffer(data))
|
||||
bytes += data.length;
|
||||
else
|
||||
bytes += Buffer.byteLength(data, encoding);
|
||||
|
||||
return bytes;
|
||||
|
@ -38,8 +38,10 @@ var httpServer = http.createServer(function(req, res) {
|
||||
// Write 1.5mb to cause some requests to buffer
|
||||
// Also, mix up the encodings a bit.
|
||||
var chunk = new Array(1024 + 1).join('7');
|
||||
var bchunk = new Buffer(chunk);
|
||||
for (var i = 0; i < 1024; i++) {
|
||||
res.write(chunk);
|
||||
res.write(bchunk);
|
||||
res.write(chunk, 'hex');
|
||||
}
|
||||
// Get .bytesWritten while buffer is not empty
|
||||
|
Loading…
x
Reference in New Issue
Block a user