Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test-net-can-reset-timeout.js « parallel « test - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: faa460e847aa08cf09eccb71aa45e21a01a5fdc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
const common = require('../common');
const net = require('net');

const server = net.createServer(common.mustCall(function(stream) {
  stream.setTimeout(100);

  stream.resume();

  stream.on('timeout', common.mustCall(function() {
    console.log('timeout');
    // try to reset the timeout.
    stream.write('WHAT.');
  }));

  stream.on('end', function() {
    console.log('server side end');
    stream.end();
  });
}));

server.listen(0, function() {
  const c = net.createConnection(this.address().port);

  c.on('data', function() {
    c.end();
  });

  c.on('end', function() {
    console.log('client side end');
    server.close();
  });
});