-
-
Notifications
You must be signed in to change notification settings - Fork 32k
os: expose guessFileDescriptorType
#58060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
os: expose guessFileDescriptorType
#58060
Conversation
I'll rebase to fix the first commit message after the CI passes! Should I also squash the PR or leave the rest as is? |
As you prefer, in any case it will get squashed upon merging. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #58060 +/- ##
==========================================
- Coverage 90.21% 90.21% -0.01%
==========================================
Files 630 630
Lines 186391 186392 +1
Branches 36608 36619 +11
==========================================
- Hits 168161 168156 -5
- Misses 11052 11060 +8
+ Partials 7178 7176 -2
🚀 New features to boost your workflow:
|
b88d406
to
f3d0b71
Compare
doc/api/os.md
Outdated
added: REPLACEME | ||
--> | ||
|
||
* `handle` {integer} The handle number to try and guess the type of. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should really specify that "handle" means "file descriptor". In fact, given that the fs docs almost exclusively use "file descriptor" and "fd", I would also adopt that terminology here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I could also rename the function to guessFileDescriptorType
? Or should I leave it as is?
And will apply the changes to fd/file descriptor in a few
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'd probably do that. In the context of libuv, guessHandleType
makes more sense, because it returns a value that actually corresponds to the types of libuv handles, which wrap around fds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Let me know if I've also done the rebase correctly 🤞
guessHandleType
guessFileDescriptorType
f3d0b71
to
0c33ea7
Compare
0c33ea7
to
93dc673
Compare
src/node_util.cc
Outdated
proxy->GetTarget(), | ||
proxy->GetHandler() | ||
}; | ||
Local<Value> ret[] = {proxy->GetTarget(), proxy->GetHandler()}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a large number of unrelated changes in here. Were these manually edited or did the format tool do these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the formatting changes were done by saving the file (after configuring vscode with the settings example provided by the contributing guide). Not sure exactly why so many changes happened, but running the cpp formatter through make also didn't revert it. I can manually revert it if desired
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do, making PRs easier to review gives them the best chance to actually land, and it avoids polluting git blame
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I did revert these changes, and staged them, but after running make format-cpp
, the file was reformatted to how it is on this PR. I'll push the non-formatted change but not sure if I should open a PR after formatting the file or just leave it be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yet running CLANG_FORMAT_START=main make format-cpp
changes nothing, confusing.. I'll leave that be for now
d803730
to
15f0bda
Compare
Exposes the internal `guessHandleType` function as `guessFileDescriptorType`, which can be used to see if a handle has a specific type, regardless of the OS it is on. This helps out with detecting, for example, if standard input is piped into the process, instead of relying on file system calls. Refs: nodejs#57603
Co-authored-by: James M Snell <[email protected]>
15f0bda
to
a65ced5
Compare
Co-authored-by: Antoine du Hamel <[email protected]>
* Returns: {string|null} | ||
|
||
Returns the type of the file descriptor passed in, or `null` if the provided file descriptor | ||
is invalid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: some expanded explanation about why this is useful would probably be helpful. It's rather obscure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to improve the documentation, but I'm not sure if this is good 😅
// For an unhandled handle type, we want to return `UNKNOWN` instead of | ||
// `null` since the type is "known" by UV, just not exposed further to | ||
// JS land | ||
return 5; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit... for later... not something to do in this PR... these really ought to be defined in an enum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would do it if I knew how 😅, and there is a TODO for that already in the function
Tested with `require('internal/test/binding').internalBinding('util').guessHandleType(2**31)` (not sure if there was a better way, but it works so)
Exposes the internal
guessHandleType
function, which can be used to see if a handle has a specific type, regardless of the OS it is on.This helps out with detecting, for example, if standard input is piped into the process, instead of relying on file system calls.
Refs: #57603