GeezerVison is showing github.com — dgram: make _createSocketHandle() internal only · nodejs/node@98ef8cf
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/dgram.js +5-60Lines changed: 5 additions & 60 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 21 | 21 |
| 22 | 22 | 'use strict'; | 23 | 23 |
| 24 | | -const assert = require('assert'); | 25 | 24 | const errors = require('internal/errors'); | 26 | | -const { kStateSymbol } = require('internal/dgram'); | | 25 | +const { | | 26 | + kStateSymbol, | | 27 | + _createSocketHandle, | | 28 | + newHandle | | 29 | +} = require('internal/dgram'); | 27 | 30 | const { | 28 | 31 | ERR_INVALID_ARG_TYPE, | 29 | 32 | ERR_MISSING_ARGS, | 30 | 33 | ERR_SOCKET_ALREADY_BOUND, | 31 | 34 | ERR_SOCKET_BAD_BUFFER_SIZE, | 32 | 35 | ERR_SOCKET_BAD_PORT, | 33 | | - ERR_SOCKET_BAD_TYPE, | 34 | 36 | ERR_SOCKET_BUFFER_SIZE, | 35 | 37 | ERR_SOCKET_CANNOT_SEND, | 36 | 38 | ERR_SOCKET_DGRAM_NOT_RUNNING | @@ -47,9 +49,6 @@ const { UV_UDP_REUSEADDR } = process.binding('constants').os; | 47 | 49 |
| 48 | 50 | const { UDP, SendWrap } = process.binding('udp_wrap'); | 49 | 51 |
| 50 | | -// Lazy load for startup performance. | 51 | | -let dns; | 52 | | - | 53 | 52 | const BIND_STATE_UNBOUND = 0; | 54 | 53 | const BIND_STATE_BINDING = 1; | 55 | 54 | const BIND_STATE_BOUND = 2; | @@ -64,59 +63,6 @@ const errnoException = errors.errnoException; | 64 | 63 | const exceptionWithHostPort = errors.exceptionWithHostPort; | 65 | 64 |
| 66 | 65 |
| 67 | | -function lookup4(lookup, address, callback) { | 68 | | - return lookup(address || '127.0.0.1', 4, callback); | 69 | | -} | 70 | | - | 71 | | - | 72 | | -function lookup6(lookup, address, callback) { | 73 | | - return lookup(address || '::1', 6, callback); | 74 | | -} | 75 | | - | 76 | | - | 77 | | -function newHandle(type, lookup) { | 78 | | - if (lookup === undefined) { | 79 | | - if (dns === undefined) dns = require('dns'); | 80 | | - lookup = dns.lookup; | 81 | | - } else if (typeof lookup !== 'function') | 82 | | - throw new ERR_INVALID_ARG_TYPE('lookup', 'Function', lookup); | 83 | | - | 84 | | - if (type === 'udp4') { | 85 | | - const handle = new UDP(); | 86 | | - handle.lookup = lookup4.bind(handle, lookup); | 87 | | - return handle; | 88 | | - } | 89 | | - | 90 | | - if (type === 'udp6') { | 91 | | - const handle = new UDP(); | 92 | | - handle.lookup = lookup6.bind(handle, lookup); | 93 | | - handle.bind = handle.bind6; | 94 | | - handle.send = handle.send6; | 95 | | - return handle; | 96 | | - } | 97 | | - | 98 | | - throw new ERR_SOCKET_BAD_TYPE(); | 99 | | -} | 100 | | - | 101 | | - | 102 | | -function _createSocketHandle(address, port, addressType, fd, flags) { | 103 | | - // Opening an existing fd is not supported for UDP handles. | 104 | | - assert(typeof fd !== 'number' || fd < 0); | 105 | | - | 106 | | - var handle = newHandle(addressType); | 107 | | - | 108 | | - if (port || address) { | 109 | | - var err = handle.bind(address, port || 0, flags); | 110 | | - if (err) { | 111 | | - handle.close(); | 112 | | - return err; | 113 | | - } | 114 | | - } | 115 | | - | 116 | | - return handle; | 117 | | -} | 118 | | - | 119 | | - | 120 | 66 | function Socket(type, listener) { | 121 | 67 | EventEmitter.call(this); | 122 | 68 | var lookup; | @@ -739,7 +685,6 @@ Socket.prototype.getSendBufferSize = function() { | 739 | 685 |
| 740 | 686 |
| 741 | 687 | module.exports = { | 742 | | - _createSocketHandle, | 743 | 688 | createSocket, | 744 | 689 | Socket | 745 | 690 | }; |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/cluster/shared_handle.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 'use strict'; | 2 | 2 | const assert = require('assert'); | 3 | | -const dgram = require('dgram'); | | 3 | +const dgram = require('internal/dgram'); | 4 | 4 | const net = require('net'); | 5 | 5 |
| 6 | 6 | module.exports = SharedHandle; | |
Collapse file Copy file name to clipboard +67-1Lines changed: 67 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 'use strict'; | | 2 | +const assert = require('assert'); | | 3 | +const { codes } = require('internal/errors'); | | 4 | +const { UDP } = process.binding('udp_wrap'); | | 5 | +const { ERR_INVALID_ARG_TYPE, ERR_SOCKET_BAD_TYPE } = codes; | 2 | 6 | const kStateSymbol = Symbol('state symbol'); | | 7 | +let dns; // Lazy load for startup performance. | 3 | 8 |
| 4 | | -module.exports = { kStateSymbol }; | | 9 | + | | 10 | +function lookup4(lookup, address, callback) { | | 11 | + return lookup(address || '127.0.0.1', 4, callback); | | 12 | +} | | 13 | + | | 14 | + | | 15 | +function lookup6(lookup, address, callback) { | | 16 | + return lookup(address || '::1', 6, callback); | | 17 | +} | | 18 | + | | 19 | + | | 20 | +function newHandle(type, lookup) { | | 21 | + if (lookup === undefined) { | | 22 | + if (dns === undefined) { | | 23 | + dns = require('dns'); | | 24 | + } | | 25 | + | | 26 | + lookup = dns.lookup; | | 27 | + } else if (typeof lookup !== 'function') { | | 28 | + throw new ERR_INVALID_ARG_TYPE('lookup', 'Function', lookup); | | 29 | + } | | 30 | + | | 31 | + if (type === 'udp4') { | | 32 | + const handle = new UDP(); | | 33 | + | | 34 | + handle.lookup = lookup4.bind(handle, lookup); | | 35 | + return handle; | | 36 | + } | | 37 | + | | 38 | + if (type === 'udp6') { | | 39 | + const handle = new UDP(); | | 40 | + | | 41 | + handle.lookup = lookup6.bind(handle, lookup); | | 42 | + handle.bind = handle.bind6; | | 43 | + handle.send = handle.send6; | | 44 | + return handle; | | 45 | + } | | 46 | + | | 47 | + throw new ERR_SOCKET_BAD_TYPE(); | | 48 | +} | | 49 | + | | 50 | + | | 51 | +function _createSocketHandle(address, port, addressType, fd, flags) { | | 52 | + // Opening an existing fd is not supported for UDP handles. | | 53 | + assert(typeof fd !== 'number' || fd < 0); | | 54 | + | | 55 | + const handle = newHandle(addressType); | | 56 | + | | 57 | + if (port || address) { | | 58 | + const err = handle.bind(address, port || 0, flags); | | 59 | + | | 60 | + if (err) { | | 61 | + handle.close(); | | 62 | + return err; | | 63 | + } | | 64 | + } | | 65 | + | | 66 | + return handle; | | 67 | +} | | 68 | + | | 69 | + | | 70 | +module.exports = { kStateSymbol, _createSocketHandle, newHandle }; |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-dgram-create-socket-handle.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// Flags: --expose-internals | 1 | 2 | 'use strict'; | 2 | 3 | const common = require('../common'); | 3 | 4 | const assert = require('assert'); | 4 | | -const dgram = require('dgram'); | | 5 | +const { _createSocketHandle } = require('internal/dgram'); | 5 | 6 | const UDP = process.binding('udp_wrap').UDP; | 6 | | -const _createSocketHandle = dgram._createSocketHandle; | 7 | 7 |
| 8 | 8 | // Throws if an "existing fd" is passed in. | 9 | 9 | common.expectsError(() => { | |
|