mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
lib: add UV_UDP_REUSEPORT for udp
PR-URL: https://github.com/nodejs/node/pull/55403 Refs: https://github.com/libuv/libuv/pull/4419 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
ee46d2297c
commit
6a02c2701e
7 files changed
+141
-3
No files matched your search
@@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
const dgram = require('dgram');
|
||||
|
||||
const options = { type: 'udp4', reusePort: true };
|
||||
|
||||
function checkSupportReusePort() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const socket = dgram.createSocket(options);
|
||||
socket.bind(0);
|
||||
socket.on('listening', () => {
|
||||
socket.close(resolve);
|
||||
});
|
||||
socket.on('error', (err) => {
|
||||
console.log('The `reusePort` option is not supported:', err.message);
|
||||
socket.close();
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
checkSupportReusePort,
|
||||
options,
|
||||
};
|
||||
Reference in new issue
Block a user