11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst net = require('net');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci{
81cb0ef41Sopenharmony_ci  const server = net.createServer(common.mustCall((socket) => {
91cb0ef41Sopenharmony_ci    socket.end(Buffer.alloc(1024));
101cb0ef41Sopenharmony_ci  })).listen(0, common.mustCall(() => {
111cb0ef41Sopenharmony_ci    const socket = net.connect(server.address().port);
121cb0ef41Sopenharmony_ci    assert.strictEqual(socket.allowHalfOpen, false);
131cb0ef41Sopenharmony_ci    socket.resume();
141cb0ef41Sopenharmony_ci    socket.on('end', common.mustCall(() => {
151cb0ef41Sopenharmony_ci      process.nextTick(() => {
161cb0ef41Sopenharmony_ci        // Ensure socket is not destroyed straight away
171cb0ef41Sopenharmony_ci        // without proper shutdown.
181cb0ef41Sopenharmony_ci        assert(!socket.destroyed);
191cb0ef41Sopenharmony_ci        server.close();
201cb0ef41Sopenharmony_ci      });
211cb0ef41Sopenharmony_ci    }));
221cb0ef41Sopenharmony_ci    socket.on('finish', common.mustCall(() => {
231cb0ef41Sopenharmony_ci      assert(!socket.destroyed);
241cb0ef41Sopenharmony_ci    }));
251cb0ef41Sopenharmony_ci    socket.on('close', common.mustCall());
261cb0ef41Sopenharmony_ci  }));
271cb0ef41Sopenharmony_ci}
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci{
301cb0ef41Sopenharmony_ci  const server = net.createServer(common.mustCall((socket) => {
311cb0ef41Sopenharmony_ci    socket.end(Buffer.alloc(1024));
321cb0ef41Sopenharmony_ci  })).listen(0, common.mustCall(() => {
331cb0ef41Sopenharmony_ci    const socket = net.connect(server.address().port);
341cb0ef41Sopenharmony_ci    assert.strictEqual(socket.allowHalfOpen, false);
351cb0ef41Sopenharmony_ci    socket.resume();
361cb0ef41Sopenharmony_ci    socket.on('end', common.mustCall(() => {
371cb0ef41Sopenharmony_ci      assert(!socket.destroyed);
381cb0ef41Sopenharmony_ci    }));
391cb0ef41Sopenharmony_ci    socket.end('asd');
401cb0ef41Sopenharmony_ci    socket.on('finish', common.mustCall(() => {
411cb0ef41Sopenharmony_ci      assert(!socket.destroyed);
421cb0ef41Sopenharmony_ci    }));
431cb0ef41Sopenharmony_ci    socket.on('close', common.mustCall(() => {
441cb0ef41Sopenharmony_ci      server.close();
451cb0ef41Sopenharmony_ci    }));
461cb0ef41Sopenharmony_ci  }));
471cb0ef41Sopenharmony_ci}
48