summaryrefslogtreecommitdiff
path: root/test/parallel/test-net-connect-options.js
blob: ac8bbcefc03e4ced030b537f0c9494bc31273581 (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
34
35
36
37
38
39
40
41
42
'use strict';
var common = require('../common');
var assert = require('assert');
var net = require('net');

var serverGotEnd = false;
var clientGotEnd = false;

var server = net.createServer({allowHalfOpen: true}, function(socket) {
  socket.resume();
  socket.on('end', function() {
    serverGotEnd = true;
  });
  socket.end();
});

server.listen(common.PORT, function() {
  var client = net.connect({
    host: '127.0.0.1',
    port: common.PORT,
    allowHalfOpen: true
  }, function() {
    console.error('client connect cb');
    client.resume();
    client.on('end', function() {
      clientGotEnd = true;
      setTimeout(function() {
        assert(client.writable);
        client.end();
      }, 10);
    });
    client.on('close', function() {
      server.close();
    });
  });
});

process.on('exit', function() {
  console.error('exit', serverGotEnd, clientGotEnd);
  assert(serverGotEnd);
  assert(clientGotEnd);
});