Skip to content
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

Refactor of RpcapdServerInitializer #1410

Merged
merged 16 commits into from
May 30, 2024

Conversation

Dimi1010
Copy link
Collaborator

This PR refactors the RpcapdServerInitializer object and contains the following changes:

  • Fixed leak of sub-process thread handle by the initializer.
  • Fixed sub-process not terminating if the main process is killed without calling object destructors.
  • getHandle method marked as const.
  • Explicitly deleted copy constructor and copy assignment operator for RpcapdServerInitializer.
    NB: Move constructor can be added at a later date if needed.
  • Removed the usages of ostringstream in favor of straight string allocation with reserve + append.
  • Added assert to remote device test that the device pointer is not null.

@Dimi1010 Dimi1010 requested a review from seladb as a code owner May 26, 2024 10:54
}
public:
RpcapdServerInitializer(bool activateRemoteDevice, const std::string& ip, uint16_t port)
: m_ProcessHandle(nullptr), m_JobHandle(nullptr)
{
if (!activateRemoteDevice)
return;

std::string cmd = "rpcapd\\rpcapd.exe";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can move this line to around L163 (new)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, tho IMO I prefer the variables being initialized in the sequence they are used in the CreateProcess call.

@tigercosmos
Copy link
Collaborator

@seladb I think this is ready for review.

Comment on lines +190 to +205
RpcapdServerInitializer(RpcapdServerInitializer&& other) noexcept
: m_ProcessHandle(other.m_ProcessHandle), m_JobHandle(other.m_JobHandle)
{
other.m_ProcessHandle = nullptr;
other.m_JobHandle = nullptr;
}
RpcapdServerInitializer& operator=(const RpcapdServerInitializer&) = delete;
RpcapdServerInitializer& operator=(RpcapdServerInitializer&& other) noexcept
{
killProcessAndCloseHandles();
m_ProcessHandle = other.m_ProcessHandle;
m_JobHandle = other.m_JobHandle;
other.m_ProcessHandle = nullptr;
other.m_JobHandle = nullptr;
return *this;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need all of these methods? We don't the copy c'tor or the assignment operator anywhere

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the class is not safe to copy, but since it only holds POD members, a copy ctor will be implicitly declared by the compiler if not explicitly deleted. As for the move ctor, @tigercosmos wanted them added as deleted too, but since the class is technically movable, I decided to write them out instead of declaring them deleted.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I have no specific objection. It's a helper class in our test suite so it doesn't have to be perfect 🙂

}
public:
RpcapdServerInitializer(bool activateRemoteDevice, const std::string& ip, uint16_t port)
: m_ProcessHandle(nullptr), m_JobHandle(nullptr)
{
if (!activateRemoteDevice)
return;

std::string cmd = "rpcapd\\rpcapd.exe";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I don't remember why I defined this string twice (here and in line 127). Maybe we can use cmd when we write args?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added 519b35a

@Dimi1010 Dimi1010 merged commit cc2507e into seladb:dev May 30, 2024
39 checks passed
@Dimi1010 Dimi1010 deleted the refactor/rpcapd-refactor branch May 30, 2024 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants