• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2// Ensure that if a dgram socket is closed before the sendQueue is drained
3// will not crash
4
5const common = require('../common');
6const dgram = require('dgram');
7
8const buf = Buffer.alloc(1024, 42);
9
10const socket = dgram.createSocket('udp4');
11
12socket.on('listening', function() {
13  socket.close();
14});
15
16// Get a random port for send
17const portGetter = dgram.createSocket('udp4')
18  .bind(0, 'localhost', common.mustCall(() => {
19    // Adds a listener to 'listening' to send the data when
20    // the socket is available
21    socket.send(buf, 0, buf.length,
22                portGetter.address().port,
23                portGetter.address().address);
24
25    portGetter.close();
26  }));
27