GeezerVison is showing github.com — src: return uint32 for `guessHandleType` · nodejs/node@954e46e
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 +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -38,7 +38,6 @@ const { | 38 | 38 | _createSocketHandle, | 39 | 39 | newHandle, | 40 | 40 | } = require('internal/dgram'); | 41 | | -const { guessHandleType } = internalBinding('util'); | 42 | 41 | const { | 43 | 42 | ERR_BUFFER_OUT_OF_BOUNDS, | 44 | 43 | ERR_INVALID_ARG_TYPE, | @@ -59,7 +58,7 @@ const { | 59 | 58 | validatePort, | 60 | 59 | } = require('internal/validators'); | 61 | 60 | const { Buffer } = require('buffer'); | 62 | | -const { deprecate } = require('internal/util'); | | 61 | +const { deprecate, guessHandleType } = require('internal/util'); | 63 | 62 | const { isArrayBufferView } = require('internal/util/types'); | 64 | 63 | const EventEmitter = require('events'); | 65 | 64 | const { | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/bootstrap/switches/is_main_thread.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -42,7 +42,7 @@ process.on('removeListener', stopListeningIfSignal); | 42 | 42 | // ---- keep the attachment of the wrappers above so that it's easier to ---- | 43 | 43 | // ---- compare the setups side-by-side ----- | 44 | 44 |
| 45 | | -const { guessHandleType } = internalBinding('util'); | | 45 | +const { guessHandleType } = require('internal/util'); | 46 | 46 |
| 47 | 47 | function createWritableStdioStream(fd) { | 48 | 48 | let stream; | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/dgram.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 |
| 8 | 8 | const { codes } = require('internal/errors'); | 9 | 9 | const { UDP } = internalBinding('udp_wrap'); | 10 | | -const { guessHandleType } = internalBinding('util'); | | 10 | +const { guessHandleType } = require('internal/util'); | 11 | 11 | const { | 12 | 12 | isInt32, | 13 | 13 | validateFunction, | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/util.js +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -54,6 +54,7 @@ const { | 54 | 54 | const { signals } = internalBinding('constants').os; | 55 | 55 | const { | 56 | 56 | isArrayBufferDetached: _isArrayBufferDetached, | | 57 | + guessHandleType: _guessHandleType, | 57 | 58 | privateSymbols: { | 58 | 59 | arrow_message_private_symbol, | 59 | 60 | decorated_private_symbol, | @@ -789,6 +790,13 @@ function setupCoverageHooks(dir) { | 789 | 790 | return coverageDirectory; | 790 | 791 | } | 791 | 792 |
| | 793 | + | | 794 | +const handleTypes = ['TCP', 'TTY', 'UDP', 'FILE', 'PIPE', 'UNKNOWN']; | | 795 | +function guessHandleType(fd) { | | 796 | + const type = _guessHandleType(fd); | | 797 | + return handleTypes[type]; | | 798 | +} | | 799 | + | 792 | 800 | module.exports = { | 793 | 801 | getLazy, | 794 | 802 | assertCrypto, | @@ -812,6 +820,7 @@ module.exports = { | 812 | 820 | getInternalGlobal, | 813 | 821 | getSystemErrorMap, | 814 | 822 | getSystemErrorName, | | 823 | + guessHandleType, | 815 | 824 | isArrayBufferDetached, | 816 | 825 | isError, | 817 | 826 | isInsideNodeModules, | |
Collapse file Copy file name to clipboardExpand all lines: lib/net.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -59,7 +59,6 @@ const { | 59 | 59 | } = internalBinding('uv'); | 60 | 60 |
| 61 | 61 | const { Buffer } = require('buffer'); | 62 | | -const { guessHandleType } = internalBinding('util'); | 63 | 62 | const { ShutdownWrap } = internalBinding('stream_wrap'); | 64 | 63 | const { | 65 | 64 | TCP, | @@ -111,7 +110,7 @@ const { | 111 | 110 | } = require('internal/errors'); | 112 | 111 | const { isUint8Array } = require('internal/util/types'); | 113 | 112 | const { queueMicrotask } = require('internal/process/task_queues'); | 114 | | -const { kEmptyObject } = require('internal/util'); | | 113 | +const { kEmptyObject, guessHandleType } = require('internal/util'); | 115 | 114 | const { | 116 | 115 | validateAbortSignal, | 117 | 116 | validateBoolean, | |
Collapse file Copy file name to clipboardExpand all lines: src/node_util.cc +13-8Lines changed: 13 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -289,32 +289,37 @@ static void GuessHandleType(const FunctionCallbackInfo<Value>& args) { | 289 | 289 | CHECK_GE(fd, 0); | 290 | 290 |
| 291 | 291 | uv_handle_type t = uv_guess_handle(fd); | 292 | | - const char* type = nullptr; | | 292 | + // TODO(anonrig): We can use an enum here and then create the array in the | | 293 | + // binding, which will remove the hard-coding in C++ and JS land. | | 294 | + uint32_t type{0}; | 293 | 295 |
| | 296 | + // Currently, the return type of this function corresponds to the index of the | | 297 | + // array defined in the JS land. This is done as an optimization to reduce the | | 298 | + // string serialization overhead. | 294 | 299 | switch (t) { | 295 | 300 | case UV_TCP: | 296 | | - type = "TCP"; | | 301 | + type = 0; | 297 | 302 | break; | 298 | 303 | case UV_TTY: | 299 | | - type = "TTY"; | | 304 | + type = 1; | 300 | 305 | break; | 301 | 306 | case UV_UDP: | 302 | | - type = "UDP"; | | 307 | + type = 2; | 303 | 308 | break; | 304 | 309 | case UV_FILE: | 305 | | - type = "FILE"; | | 310 | + type = 3; | 306 | 311 | break; | 307 | 312 | case UV_NAMED_PIPE: | 308 | | - type = "PIPE"; | | 313 | + type = 4; | 309 | 314 | break; | 310 | 315 | case UV_UNKNOWN_HANDLE: | 311 | | - type = "UNKNOWN"; | | 316 | + type = 5; | 312 | 317 | break; | 313 | 318 | default: | 314 | 319 | ABORT(); | 315 | 320 | } | 316 | 321 |
| 317 | | - args.GetReturnValue().Set(OneByteString(env->isolate(), type)); | | 322 | + args.GetReturnValue().Set(type); | 318 | 323 | } | 319 | 324 |
| 320 | 325 | static void ToUSVString(const FunctionCallbackInfo<Value>& args) { | |
|