2017-01-03 13:16:48 -08:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-01-11 18:00:53 -08:00
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const net = require('net');
|
|
|
|
const msg = 'test';
|
2017-01-08 13:19:00 +00:00
|
|
|
let stopped = true;
|
|
|
|
let server1Sock;
|
2016-01-11 18:00:53 -08:00
|
|
|
|
|
|
|
|
2017-04-27 17:27:05 -07:00
|
|
|
const server1ConnHandler = (socket) => {
|
2014-10-17 21:45:40 -04:00
|
|
|
socket.on('data', function(data) {
|
|
|
|
if (stopped) {
|
2017-04-09 10:53:30 -07:00
|
|
|
assert.fail('data event should not have happened yet');
|
2014-10-17 21:45:40 -04:00
|
|
|
}
|
|
|
|
|
2018-03-28 17:15:59 +01:00
|
|
|
assert.strictEqual(data.toString(), msg);
|
2014-10-17 21:45:40 -04:00
|
|
|
socket.end();
|
|
|
|
server1.close();
|
|
|
|
});
|
|
|
|
|
2016-01-11 18:00:53 -08:00
|
|
|
server1Sock = socket;
|
|
|
|
};
|
2015-08-18 11:36:20 -07:00
|
|
|
|
2017-07-10 20:55:21 -04:00
|
|
|
const server1 = net.createServer({ pauseOnConnect: true }, server1ConnHandler);
|
2014-10-17 21:45:40 -04:00
|
|
|
|
2017-04-27 17:27:05 -07:00
|
|
|
const server2ConnHandler = (socket) => {
|
2014-10-17 21:45:40 -04:00
|
|
|
socket.on('data', function(data) {
|
2018-03-28 17:15:59 +01:00
|
|
|
assert.strictEqual(data.toString(), msg);
|
2014-10-17 21:45:40 -04:00
|
|
|
socket.end();
|
|
|
|
server2.close();
|
2016-01-11 18:00:53 -08:00
|
|
|
|
2018-03-28 17:15:59 +01:00
|
|
|
assert.strictEqual(server1Sock.bytesRead, 0);
|
2016-01-11 18:00:53 -08:00
|
|
|
server1Sock.resume();
|
|
|
|
stopped = false;
|
2014-10-17 21:45:40 -04:00
|
|
|
});
|
2016-01-11 18:00:53 -08:00
|
|
|
};
|
2014-10-17 21:45:40 -04:00
|
|
|
|
2017-07-10 20:55:21 -04:00
|
|
|
const server2 = net.createServer({ pauseOnConnect: false }, server2ConnHandler);
|
2014-10-17 21:45:40 -04:00
|
|
|
|
2016-05-29 03:06:56 -04:00
|
|
|
server1.listen(0, function() {
|
2016-01-11 18:00:53 -08:00
|
|
|
const clientHandler = common.mustCall(function() {
|
2016-05-29 03:06:56 -04:00
|
|
|
server2.listen(0, function() {
|
2017-07-10 20:55:21 -04:00
|
|
|
net.createConnection({ port: this.address().port }).write(msg);
|
2016-01-11 18:00:53 -08:00
|
|
|
});
|
|
|
|
});
|
2017-07-10 20:55:21 -04:00
|
|
|
net.createConnection({ port: this.address().port }).write(msg, clientHandler);
|
2014-10-17 21:45:40 -04:00
|
|
|
});
|
2015-08-18 11:36:20 -07:00
|
|
|
|
|
|
|
process.on('exit', function() {
|
2017-01-08 15:36:25 +00:00
|
|
|
assert.strictEqual(stopped, false);
|
2015-08-18 11:36:20 -07:00
|
|
|
});
|