• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5const net = require('net');
6
7const server = net.createServer(function(socket) {
8  socket.end();
9});
10
11server.listen(0, common.mustCall(function() {
12  const socket = net.connect(server.address().port);
13
14  // Cork the socket, then write twice; this should cause a writev, which
15  // previously caused an err in the bytesWritten count.
16  socket.cork();
17
18  socket.write('one');
19  socket.write(Buffer.from('twø', 'utf8'));
20
21  socket.uncork();
22
23  // one = 3 bytes, twø = 4 bytes
24  assert.strictEqual(socket.bytesWritten, 3 + 4);
25
26  socket.on('connect', common.mustCall(function() {
27    assert.strictEqual(socket.bytesWritten, 3 + 4);
28  }));
29
30  socket.on('end', common.mustCall(function() {
31    assert.strictEqual(socket.bytesWritten, 3 + 4);
32
33    server.close();
34  }));
35}));
36