mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
75930bb38c
* Destroy `SSL*` and friends on a next tick to make sure that we are not doing it in one of the OpenSSL callbacks * Add more checks to the C++ methods that might be invoked during destructor's pending queue cleanup Fix: https://github.com/joyent/node/issues/8780 Fix: https://github.com/iojs/io.js/issues/1696 PR-URL: https://github.com/nodejs/io.js/pull/1702 Reviewed-By: Trevor Norris <trev.norris@gmail.com>
77 lines
1.5 KiB
JavaScript
77 lines
1.5 KiB
JavaScript
'use strict';
|
|
var common = require('../common');
|
|
var assert = require('assert');
|
|
|
|
if (!common.hasCrypto) {
|
|
console.log('1..0 # Skipped: missing crypto');
|
|
process.exit();
|
|
}
|
|
var tls = require('tls');
|
|
|
|
var stream = require('stream');
|
|
var fs = require('fs');
|
|
var net = require('net');
|
|
|
|
var connected = {
|
|
client: 0,
|
|
server: 0
|
|
};
|
|
|
|
var server = tls.createServer({
|
|
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
|
|
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
|
|
}, function(c) {
|
|
console.log('new client');
|
|
connected.server++;
|
|
c.end('ohai');
|
|
}).listen(common.PORT, function() {
|
|
var raw = net.connect(common.PORT);
|
|
|
|
var pending = false;
|
|
raw.on('readable', function() {
|
|
if (pending)
|
|
p._read();
|
|
});
|
|
|
|
var p = new stream.Duplex({
|
|
read: function read() {
|
|
pending = false;
|
|
|
|
var chunk = raw.read();
|
|
if (chunk) {
|
|
console.log('read', chunk);
|
|
this.push(chunk);
|
|
} else {
|
|
pending = true;
|
|
}
|
|
},
|
|
write: function write(data, enc, cb) {
|
|
console.log('write', data, enc);
|
|
raw.write(data, enc, cb);
|
|
}
|
|
});
|
|
|
|
var socket = tls.connect({
|
|
socket: p,
|
|
rejectUnauthorized: false
|
|
}, function() {
|
|
console.log('client secure');
|
|
|
|
connected.client++;
|
|
|
|
socket.end('hello');
|
|
socket.resume();
|
|
socket.destroy();
|
|
});
|
|
|
|
socket.once('close', function() {
|
|
console.log('client close');
|
|
server.close();
|
|
});
|
|
});
|
|
|
|
process.once('exit', function() {
|
|
assert.equal(connected.client, 1);
|
|
assert.equal(connected.server, 1);
|
|
});
|