1'use strict'; 2 3require('../common'); 4const assert = require('assert'); 5const net = require('net'); 6 7const server = net.createServer(handle); 8 9const N = 100; 10const buf = Buffer.alloc(2, 'a'); 11 12server.listen(0, function() { 13 const conn = net.connect(this.address().port); 14 15 conn.on('connect', () => { 16 let res = true; 17 let i = 0; 18 for (; i < N && res; i++) { 19 conn.cork(); 20 conn.write(buf); 21 res = conn.write(buf); 22 conn.uncork(); 23 } 24 assert.strictEqual(i, N); 25 conn.end(); 26 }); 27}); 28 29process.on('exit', function() { 30 assert.strictEqual(server.connections, 0); 31}); 32 33function handle(socket) { 34 socket.resume(); 35 36 socket.on('error', function(err) { 37 socket.destroy(); 38 }).on('close', function() { 39 server.close(); 40 }); 41} 42