Skip to content

Commit

Permalink
Add non-blocking pipe functionality to windows_handle_file_ref
Browse files Browse the repository at this point in the history
While experimenting with non-blocking pipes, I found some shortcomings
in windows_handle_file_ref. Address these shortcomings to achieve
feature parity with posix_fd_file_ref.

This commit should not change behavior because we don't use non-blocking
pipes on Windows. (We probably won't ever use non-blocking pipes on
Windows).
  • Loading branch information
strager committed Jun 16, 2021
1 parent 2e96fc2 commit 53e4f3b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/file-handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ file_read_result windows_handle_file_ref::read(void *buffer,
return file_read_result{
.at_end_of_file = error == ERROR_BROKEN_PIPE,
.bytes_read = 0,
.error_message = windows_error_message(error),
.error_message = error == ERROR_NO_DATA
? std::nullopt
: std::optional(windows_error_message(error)),
};
}
return file_read_result{
Expand Down Expand Up @@ -101,6 +103,16 @@ bool windows_handle_file_ref::is_pipe_non_blocking() {
return (state & PIPE_NOWAIT) == PIPE_NOWAIT;
}

void windows_handle_file_ref::set_pipe_non_blocking() {
DWORD mode = PIPE_READMODE_BYTE | PIPE_NOWAIT;
BOOL ok = ::SetNamedPipeHandleState(this->get(), /*lpMode=*/&mode,
/*lpMaxCollectionCount=*/nullptr,
/*lpCollectDataTimeout=*/nullptr);
if (!ok) {
QLJS_UNIMPLEMENTED();
}
}

std::size_t windows_handle_file_ref::get_pipe_buffer_size() {
DWORD outBufferSize = 0;
BOOL ok =
Expand Down
2 changes: 2 additions & 0 deletions src/quick-lint-js/file-handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class windows_handle_file_ref {
std::optional<int> write(const void *buffer, int buffer_size) noexcept;

bool is_pipe_non_blocking();
void set_pipe_non_blocking();
std::size_t get_pipe_buffer_size();

static std::string get_last_error_message();
Expand Down Expand Up @@ -84,6 +85,7 @@ class windows_handle_file : private windows_handle_file_ref {
using windows_handle_file_ref::get_pipe_buffer_size;
using windows_handle_file_ref::is_pipe_non_blocking;
using windows_handle_file_ref::read;
using windows_handle_file_ref::set_pipe_non_blocking;
using windows_handle_file_ref::write;

private:
Expand Down

0 comments on commit 53e4f3b

Please sign in to comment.