0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-28 22:46:31 +01:00
nodejs/test/parallel/test-dgram-close.js
isaacs 3e1b1dd4a9 Remove excessive copyright/license boilerplate
The copyright and license notice is already in the LICENSE file.  There
is no justifiable reason to also require that it be included in every
file, since the individual files are not individually distributed except
as part of the entire package.
2015-01-12 15:30:28 -08:00

36 lines
867 B
JavaScript

// Ensure that if a dgram socket is closed before the DNS lookup completes, it
// won't crash.
var assert = require('assert'),
common = require('../common'),
dgram = require('dgram');
var buf = new Buffer(1024);
buf.fill(42);
var socket = dgram.createSocket('udp4');
var handle = socket._handle;
var closeEvents = 0;
var closeCallbacks = 0;
socket.send(buf, 0, buf.length, common.PORT, 'localhost');
assert.strictEqual(socket.close(function() {
++closeCallbacks;
}), socket);
socket.on('close', function() {
assert.equal(closeCallbacks, 1);
++closeEvents;
});
socket = null;
// Verify that accessing handle after closure doesn't throw
setImmediate(function() {
setImmediate(function() {
console.log('Handle fd is: ', handle.fd);
});
});
process.on('exit', function() {
assert.equal(closeEvents, 1);
assert.equal(closeCallbacks, 1);
});