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(handle);
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst N = 100;
101cb0ef41Sopenharmony_ciconst buf = Buffer.alloc(2, 'a');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciserver.listen(0, function() {
131cb0ef41Sopenharmony_ci  const conn = net.connect(this.address().port);
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci  conn.on('connect', () => {
161cb0ef41Sopenharmony_ci    let res = true;
171cb0ef41Sopenharmony_ci    let i = 0;
181cb0ef41Sopenharmony_ci    for (; i < N && res; i++) {
191cb0ef41Sopenharmony_ci      conn.cork();
201cb0ef41Sopenharmony_ci      conn.write(buf);
211cb0ef41Sopenharmony_ci      res = conn.write(buf);
221cb0ef41Sopenharmony_ci      conn.uncork();
231cb0ef41Sopenharmony_ci    }
241cb0ef41Sopenharmony_ci    assert.strictEqual(i, N);
251cb0ef41Sopenharmony_ci    conn.end();
261cb0ef41Sopenharmony_ci  });
271cb0ef41Sopenharmony_ci});
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_cifunction handle(socket) {
301cb0ef41Sopenharmony_ci  socket.resume();
311cb0ef41Sopenharmony_ci  socket.on('error', common.mustNotCall())
321cb0ef41Sopenharmony_ci        .on('close', common.mustCall(() => server.close()));
331cb0ef41Sopenharmony_ci}
34