-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
[core] make ProcessFD, [Client,Server]Connection non copyable. #41106
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9b1db15
make ProcessFD non copyable.
rynewang c2622f8
also make [Client,Server]Connection non copyable
rynewang e31e761
remove the todo
rynewang 85e7c14
Merge branch 'master' into non-copyable-fd
rynewang 0612fd3
Merge branch 'master' into non-copyable-fd
rynewang d7eafdc
Merge branch 'master' into non-copyable-fd
rynewang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,11 +88,12 @@ class ProcessFD { | |
~ProcessFD(); | ||
ProcessFD(); | ||
ProcessFD(pid_t pid, intptr_t fd = -1); | ||
ProcessFD(const ProcessFD &other); | ||
ProcessFD(ProcessFD &&other); | ||
ProcessFD &operator=(const ProcessFD &other); | ||
ProcessFD &operator=(ProcessFD &&other); | ||
intptr_t CloneFD() const; | ||
|
||
ProcessFD(const ProcessFD &other) = delete; | ||
ProcessFD &operator=(const ProcessFD &other) = delete; | ||
|
||
void CloseFD(); | ||
intptr_t GetFD() const; | ||
pid_t GetId() const; | ||
|
@@ -217,17 +218,7 @@ class ProcessFD { | |
} | ||
}; | ||
|
||
ProcessFD::~ProcessFD() { | ||
if (fd_ != -1) { | ||
bool success; | ||
#ifdef _WIN32 | ||
success = !!CloseHandle(reinterpret_cast<HANDLE>(fd_)); | ||
#else | ||
success = close(static_cast<int>(fd_)) == 0; | ||
#endif | ||
RAY_CHECK(success) << "error " << errno << " closing process " << pid_ << " FD"; | ||
} | ||
} | ||
ProcessFD::~ProcessFD() { CloseFD(); } | ||
|
||
ProcessFD::ProcessFD() : pid_(-1), fd_(-1) {} | ||
|
||
|
@@ -277,18 +268,8 @@ ProcessFD::ProcessFD(pid_t pid, intptr_t fd) : pid_(pid), fd_(fd) { | |
} | ||
} | ||
|
||
ProcessFD::ProcessFD(const ProcessFD &other) : ProcessFD(other.pid_, other.CloneFD()) {} | ||
|
||
ProcessFD::ProcessFD(ProcessFD &&other) : ProcessFD() { *this = std::move(other); } | ||
|
||
ProcessFD &ProcessFD::operator=(const ProcessFD &other) { | ||
if (this != &other) { | ||
// Construct a copy, then call the move constructor | ||
*this = static_cast<ProcessFD>(other); | ||
} | ||
return *this; | ||
} | ||
|
||
ProcessFD &ProcessFD::operator=(ProcessFD &&other) { | ||
if (this != &other) { | ||
// We use swap() to make sure the argument is actually moved from | ||
|
@@ -299,32 +280,19 @@ ProcessFD &ProcessFD::operator=(ProcessFD &&other) { | |
return *this; | ||
} | ||
|
||
intptr_t ProcessFD::CloneFD() const { | ||
intptr_t fd; | ||
void ProcessFD::CloseFD() { | ||
if (fd_ != -1) { | ||
bool success; | ||
#ifdef _WIN32 | ||
HANDLE handle; | ||
BOOL inheritable = FALSE; | ||
fd = DuplicateHandle(GetCurrentProcess(), | ||
reinterpret_cast<HANDLE>(fd_), | ||
GetCurrentProcess(), | ||
&handle, | ||
0, | ||
inheritable, | ||
DUPLICATE_SAME_ACCESS) | ||
? reinterpret_cast<intptr_t>(handle) | ||
: -1; | ||
success = !!CloseHandle(reinterpret_cast<HANDLE>(fd_)); | ||
#else | ||
fd = dup(static_cast<int>(fd_)); | ||
success = close(static_cast<int>(fd_)) == 0; | ||
#endif | ||
RAY_DCHECK(fd != -1); | ||
} else { | ||
fd = -1; | ||
RAY_CHECK(success) << "error " << errno << " closing process " << pid_ << " FD"; | ||
} | ||
return fd; | ||
} | ||
|
||
void ProcessFD::CloseFD() { fd_ = -1; } | ||
fd_ = -1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm interseting... this seems actually never used (existing closeFd) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indeed |
||
} | ||
|
||
intptr_t ProcessFD::GetFD() const { return fd_; } | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
it is not used now btw? (I assume yes given deleting copy constructor just succeeds?)
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.
it's not used anywhere