1'use strict'; 2 3const common = require('../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 29function handle(socket) { 30 socket.resume(); 31 socket.on('error', common.mustNotCall()) 32 .on('close', common.mustCall(() => server.close())); 33} 34