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 truthyValues = [true, 1, 'true', {}, []];
81cb0ef41Sopenharmony_ciconst falseyValues = [false, 0, ''];
91cb0ef41Sopenharmony_ciconst genSetNoDelay = (desiredArg) => (enable) => {
101cb0ef41Sopenharmony_ci  assert.strictEqual(enable, desiredArg);
111cb0ef41Sopenharmony_ci};
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci// setNoDelay should default to true
141cb0ef41Sopenharmony_cilet socket = new net.Socket({
151cb0ef41Sopenharmony_ci  handle: {
161cb0ef41Sopenharmony_ci    setNoDelay: common.mustCall(genSetNoDelay(true)),
171cb0ef41Sopenharmony_ci    readStart() {}
181cb0ef41Sopenharmony_ci  }
191cb0ef41Sopenharmony_ci});
201cb0ef41Sopenharmony_cisocket.setNoDelay();
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_cisocket = new net.Socket({
231cb0ef41Sopenharmony_ci  handle: {
241cb0ef41Sopenharmony_ci    setNoDelay: common.mustCall(genSetNoDelay(true), 1),
251cb0ef41Sopenharmony_ci    readStart() {}
261cb0ef41Sopenharmony_ci  }
271cb0ef41Sopenharmony_ci});
281cb0ef41Sopenharmony_citruthyValues.forEach((testVal) => socket.setNoDelay(testVal));
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_cisocket = new net.Socket({
311cb0ef41Sopenharmony_ci  handle: {
321cb0ef41Sopenharmony_ci    setNoDelay: common.mustNotCall(),
331cb0ef41Sopenharmony_ci    readStart() {}
341cb0ef41Sopenharmony_ci  }
351cb0ef41Sopenharmony_ci});
361cb0ef41Sopenharmony_cifalseyValues.forEach((testVal) => socket.setNoDelay(testVal));
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_cisocket = new net.Socket({
391cb0ef41Sopenharmony_ci  handle: {
401cb0ef41Sopenharmony_ci    setNoDelay: common.mustCall(3),
411cb0ef41Sopenharmony_ci    readStart() {}
421cb0ef41Sopenharmony_ci  }
431cb0ef41Sopenharmony_ci});
441cb0ef41Sopenharmony_citruthyValues.concat(falseyValues).concat(truthyValues)
451cb0ef41Sopenharmony_ci  .forEach((testVal) => socket.setNoDelay(testVal));
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci// If a handler doesn't have a setNoDelay function it shouldn't be called.
481cb0ef41Sopenharmony_ci// In the case below, if it is called an exception will be thrown
491cb0ef41Sopenharmony_cisocket = new net.Socket({
501cb0ef41Sopenharmony_ci  handle: {
511cb0ef41Sopenharmony_ci    setNoDelay: null,
521cb0ef41Sopenharmony_ci    readStart() {}
531cb0ef41Sopenharmony_ci  }
541cb0ef41Sopenharmony_ci});
551cb0ef41Sopenharmony_ciconst returned = socket.setNoDelay(true);
561cb0ef41Sopenharmony_ciassert.ok(returned instanceof net.Socket);
57