mirror of
https://github.com/nodejs/node.git
synced 2025-04-29 22:40:57 +00:00

For tests / benchmarks that are creating Buffer instances for any reason other than to test Buffer constructor, use the new Buffer.alloc/Buffer.from API instead of the deprecated API. PR-URL: https://github.com/nodejs/node/pull/18980 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
36 lines
856 B
JavaScript
36 lines
856 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const net = require('net');
|
|
|
|
const server = net.createServer(function(socket) {
|
|
socket.end();
|
|
});
|
|
|
|
server.listen(0, common.mustCall(function() {
|
|
const socket = net.connect(server.address().port);
|
|
|
|
// Cork the socket, then write twice; this should cause a writev, which
|
|
// previously caused an err in the bytesWritten count.
|
|
socket.cork();
|
|
|
|
socket.write('one');
|
|
socket.write(Buffer.from('twø', 'utf8'));
|
|
|
|
socket.uncork();
|
|
|
|
// one = 3 bytes, twø = 4 bytes
|
|
assert.strictEqual(socket.bytesWritten, 3 + 4);
|
|
|
|
socket.on('connect', common.mustCall(function() {
|
|
assert.strictEqual(socket.bytesWritten, 3 + 4);
|
|
}));
|
|
|
|
socket.on('end', common.mustCall(function() {
|
|
assert.strictEqual(socket.bytesWritten, 3 + 4);
|
|
|
|
server.close();
|
|
}));
|
|
}));
|