|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +const assert = require('assert'); |
| 5 | +const net = require('net'); |
| 6 | + |
| 7 | +// Verifies that setKeepAlive() forwards the keepalive probe interval |
| 8 | +// (TCP_KEEPINTVL) and probe count (TCP_KEEPCNT) to the handle. The interval is |
| 9 | +// converted from milliseconds to whole seconds, mirroring the initialDelay |
| 10 | +// handling and uv_tcp_keepalive_ex(). |
| 11 | + |
| 12 | +// Explicit setKeepAlive(enable, initialDelay, interval, count) forwards all |
| 13 | +// four values, converting milliseconds to seconds for the delays. |
| 14 | +{ |
| 15 | + const server = net.createServer(); |
| 16 | + server.listen(0, common.mustCall(() => { |
| 17 | + const client = net.connect( |
| 18 | + { port: server.address().port }, |
| 19 | + common.mustCall(() => { |
| 20 | + client._handle.setKeepAlive = common.mustCall( |
| 21 | + (enable, delay, interval, count) => { |
| 22 | + assert.strictEqual(enable, true); |
| 23 | + assert.strictEqual(delay, 5); |
| 24 | + assert.strictEqual(interval, 10); |
| 25 | + assert.strictEqual(count, 9); |
| 26 | + }); |
| 27 | + client.setKeepAlive(true, 5000, 10000, 9); |
| 28 | + client.end(); |
| 29 | + })); |
| 30 | + |
| 31 | + client.on('end', common.mustCall(() => server.close())); |
| 32 | + })); |
| 33 | +} |
| 34 | + |
| 35 | +// Omitting interval/count passes undefined through; the handle applies the |
| 36 | +// libuv defaults (1s interval, 10 probes). |
| 37 | +{ |
| 38 | + const server = net.createServer(); |
| 39 | + server.listen(0, common.mustCall(() => { |
| 40 | + const client = net.connect( |
| 41 | + { port: server.address().port }, |
| 42 | + common.mustCall(() => { |
| 43 | + client._handle.setKeepAlive = common.mustCall( |
| 44 | + (enable, delay, interval, count) => { |
| 45 | + assert.strictEqual(enable, true); |
| 46 | + assert.strictEqual(delay, 5); |
| 47 | + assert.strictEqual(interval, undefined); |
| 48 | + assert.strictEqual(count, undefined); |
| 49 | + }); |
| 50 | + client.setKeepAlive(true, 5000); |
| 51 | + client.end(); |
| 52 | + })); |
| 53 | + |
| 54 | + client.on('end', common.mustCall(() => server.close())); |
| 55 | + })); |
| 56 | +} |
0 commit comments