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 big = Buffer.alloc(1024 * 1024);
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst handler = common.mustCall((socket) => {
101cb0ef41Sopenharmony_ci  socket.end(big);
111cb0ef41Sopenharmony_ci  server.close();
121cb0ef41Sopenharmony_ci});
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ciconst onListen = common.mustCall(() => {
151cb0ef41Sopenharmony_ci  let prev = 0;
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci  function checkRaise(value) {
181cb0ef41Sopenharmony_ci    assert(value > prev);
191cb0ef41Sopenharmony_ci    prev = value;
201cb0ef41Sopenharmony_ci  }
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci  const onData = common.mustCallAtLeast((chunk) => {
231cb0ef41Sopenharmony_ci    checkRaise(socket.bytesRead);
241cb0ef41Sopenharmony_ci  });
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ci  const onEnd = common.mustCall(() => {
271cb0ef41Sopenharmony_ci    assert.strictEqual(socket.bytesRead, prev);
281cb0ef41Sopenharmony_ci    assert.strictEqual(big.length, prev);
291cb0ef41Sopenharmony_ci  });
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci  const onClose = common.mustCall(() => {
321cb0ef41Sopenharmony_ci    assert(!socket._handle);
331cb0ef41Sopenharmony_ci    assert.strictEqual(socket.bytesRead, prev);
341cb0ef41Sopenharmony_ci    assert.strictEqual(big.length, prev);
351cb0ef41Sopenharmony_ci  });
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci  const onConnect = common.mustCall(() => {
381cb0ef41Sopenharmony_ci    socket.on('data', onData);
391cb0ef41Sopenharmony_ci    socket.on('end', onEnd);
401cb0ef41Sopenharmony_ci    socket.on('close', onClose);
411cb0ef41Sopenharmony_ci    socket.end();
421cb0ef41Sopenharmony_ci  });
431cb0ef41Sopenharmony_ci
441cb0ef41Sopenharmony_ci  const socket = net.connect(server.address().port, onConnect);
451cb0ef41Sopenharmony_ci});
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ciconst server = net.createServer(handler).listen(0, onListen);
48