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: extract _send_windows_request to the named_pipe_helper.py #32

Merged
merged 1 commit into from
Dec 6, 2023

Conversation

Honglichenn
Copy link
Contributor

@Honglichenn Honglichenn commented Dec 5, 2023

What was the problem/requirement? (What/Why)

Need to send request in the Adaptor Server client and the Background client. There are some common code could be reused.

What was the solution? (How)

  • Move named_pipe_helper.py to the _named_pipe folder
  • Move _send_windows_request to the named_pipe_helper and rename it to send_named_pipe_request
  • Add some doc strings.
  • Add win32file.FlushFileBuffers(self.pipe_handle) before closing the named pipe to ensure that all messages are read by the client.

What is the impact of this change?

Just refactoring. Nothing is changed.

How was this change tested?

All tests are passed.

Was this change documented?

No

Is this a breaking change?

No


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Honglichenn Honglichenn force-pushed the honglich/refactor_request branch 4 times, most recently from c967552 to c435098 Compare December 5, 2023 18:15
@@ -82,6 +82,9 @@ def instance_thread(self) -> None:
f"Encountered an error while sending the error response: {traceback.format_exc()}."
)
try:
# Flush the pipe to allow the client to read the pipe's contents before disconnecting.
# Then disconnect the pipe, and close the handle to this pipe instance.
win32file.FlushFileBuffers(self.pipe_handle)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not related to the code refactoring but just one line change so I put it here. This is required and I missed this before. Reference: https://learn.microsoft.com/en-us/windows/win32/ipc/multithreaded-pipe-server

return f"{self.message} (Error code: {self.error_code})"


class NamedPipeHelper:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

send_named_pipe_request and establish_named_pipe_connection are two new methods. The code is copied fro m the _send_windows_request, Other code exists in the old file. Due to renaming, all text have green background

@Honglichenn Honglichenn marked this pull request as ready for review December 5, 2023 18:33
@Honglichenn Honglichenn requested a review from a team as a code owner December 5, 2023 18:33
@Honglichenn Honglichenn merged commit f69291b into mainline Dec 6, 2023
9 checks passed
@Honglichenn Honglichenn deleted the honglich/refactor_request branch December 6, 2023 15:57
Honglichenn pushed a commit that referenced this pull request Jan 17, 2024
@ddneilson ddneilson added the security Pull requests that could impact security label Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
security Pull requests that could impact security
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants