11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst net = require('net');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst server = net.createServer(function(socket) {
81cb0ef41Sopenharmony_ci  socket.end();
91cb0ef41Sopenharmony_ci});
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(function() {
121cb0ef41Sopenharmony_ci  const socket = net.connect(server.address().port);
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci  // Cork the socket, then write twice; this should cause a writev, which
151cb0ef41Sopenharmony_ci  // previously caused an err in the bytesWritten count.
161cb0ef41Sopenharmony_ci  socket.cork();
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci  socket.write('one');
191cb0ef41Sopenharmony_ci  socket.write(Buffer.from('twø', 'utf8'));
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci  socket.uncork();
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci  // one = 3 bytes, twø = 4 bytes
241cb0ef41Sopenharmony_ci  assert.strictEqual(socket.bytesWritten, 3 + 4);
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci  socket.on('connect', common.mustCall(function() {
271cb0ef41Sopenharmony_ci    assert.strictEqual(socket.bytesWritten, 3 + 4);
281cb0ef41Sopenharmony_ci  }));
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci  socket.on('end', common.mustCall(function() {
311cb0ef41Sopenharmony_ci    assert.strictEqual(socket.bytesWritten, 3 + 4);
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci    server.close();
341cb0ef41Sopenharmony_ci  }));
351cb0ef41Sopenharmony_ci}));
36