2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2014-07-02 15:24:17 +02:00
|
|
|
var common = require('../common');
|
|
|
|
|
|
|
|
var dgram = require('dgram');
|
|
|
|
var callbacks = 0;
|
|
|
|
var client;
|
|
|
|
var timer;
|
|
|
|
|
2014-08-02 15:06:25 +04:00
|
|
|
if (process.platform === 'darwin') {
|
2015-07-06 03:24:12 +00:00
|
|
|
console.log('1..0 # Skipped: because of 17894467 Apple bug');
|
2014-08-02 15:06:25 +04:00
|
|
|
return;
|
|
|
|
}
|
2014-07-02 15:24:17 +02:00
|
|
|
|
|
|
|
client = dgram.createSocket('udp4');
|
|
|
|
|
|
|
|
client.bind(common.PORT);
|
|
|
|
|
|
|
|
function callback() {
|
|
|
|
callbacks++;
|
|
|
|
if (callbacks == 2) {
|
|
|
|
clearTimeout(timer);
|
|
|
|
client.close();
|
|
|
|
} else if (callbacks > 2) {
|
2015-05-19 13:00:06 +02:00
|
|
|
throw new Error('the callbacks should be called only two times');
|
2014-07-02 15:24:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
client.on('message', function(buffer, bytes) {
|
2014-07-02 15:24:17 +02:00
|
|
|
callback();
|
|
|
|
});
|
|
|
|
|
2016-01-25 15:00:06 -08:00
|
|
|
client.send(
|
|
|
|
Buffer.allocUnsafe(1), 0, 0, common.PORT, '127.0.0.1', (err, len) => {
|
|
|
|
callback();
|
|
|
|
});
|
2014-07-02 15:24:17 +02:00
|
|
|
|
|
|
|
timer = setTimeout(function() {
|
|
|
|
throw new Error('Timeout');
|
|
|
|
}, 200);
|