Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created February 11, 2013 22:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/4758403 to your computer and use it in GitHub Desktop.
Save isaacs/4758403 to your computer and use it in GitHub Desktop.
var tls = require('tls');
var path = require('path');
var fs = require('fs');
var cert_dir = 'test/fixtures/'
var PORT = 12346;
var options = { key: fs.readFileSync(cert_dir + '/test_key.pem'),
cert: fs.readFileSync(cert_dir + '/test_cert.pem'),
ca: [ fs.readFileSync(cert_dir + '/test_ca.pem') ] };
var server = tls.createServer(options, function(conn) {
conn.on('data', function(chunk) {
console.error('got chunk', chunk.length);
});
}).listen(PORT, function() {
var chunk = new Buffer(10);
chunk.fill('x');
var opt = {port:PORT, rejectUnauthorized: false };
var conn = tls.connect(opt, function() {
conn.on('drain', write);
write();
});
function write() {
console.error('start writing');
var i = 0;
while (false !== conn.write(chunk)) {
if (!(++i % 10000)) console.error(process.memoryUsage());
}
console.error('wait for drain');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment