Localhost Relay: non-blocking IO on Linux side, IOCP with fully async reads and writes on Windows side#40171
Open
Localhost Relay: non-blocking IO on Linux side, IOCP with fully async reads and writes on Windows side#40171
Conversation
added 2 commits
April 14, 2026 02:04
… reads and writes on Windows side
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Refactors the localhost relay implementation to use non-blocking, back-pressure-aware I/O on Linux and IOCP-based fully asynchronous I/O on Windows, improving full-duplex throughput and correct half-close behavior.
Changes:
- Windows: replaced wait/event-based overlapped I/O with IOCP dispatch and per-direction read/write state machines.
- Linux: switched sockets to non-blocking mode and implemented a poll-driven relay with per-direction buffering and compaction.
- Added per-direction half-close handling so each direction can complete independently.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/windows/common/relay.cpp | Reworks BidirectionalRelay to use IOCP with per-direction async read/write contexts and completion processing. |
| src/linux/init/localhost.cpp | Implements a non-blocking poll() relay loop with per-direction buffers, back-pressure, and half-close support. |
|
“Thanks for the notification. Update received.”
获取 Outlook for iOS<https://aka.ms/o0ukef>
________________________________
发件人: wangxin12 ***@***.***>
发送时间: Tuesday, April 14, 2026 5:43:42 AM
收件人: microsoft/WSL ***@***.***>
抄送: Subscribed ***@***.***>
主题: Re: [microsoft/WSL] Localhost Relay: non-blocking IO on Linux side, IOCP with fully async reads and writes on Windows side (PR #40171)
@wangxin12 commented on this pull request.
________________________________
In src/linux/init/localhost.cpp<#40171 (comment)>:
+ if (pfds[j].events & POLLOUT)
{
- bytesRead = UtilReadBuffer(pollDescriptors[Index].fd, buffer);
- if (bytesRead == 0)
+ // can't write to dstFd any more
+ if (pfds[j].revents & (POLLERR | POLLHUP))
{
- pollDescriptors[Index].fd = -1;
- shutdown(outFd[Index], SHUT_WR);
+ d.done = true;
+ continue;
}
- else if (bytesRead < 0)
+
+ if (!(pfds[j].revents & POLLOUT))
{
- return;
+ continue;
+ }
Both fds are owned by unique_fd and are never closed during the relay loop, so POLLNVAL cannot occur.
―
Reply to this email directly, view it on GitHub<#40171 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/B677FUKLYOJS6P74H5GV4N34VVNQZAVCNFSM6AAAAACXXZYSQCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHM2DCMBSGEYTOMJXGM>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary of the Pull Request
Linux — non-blocking poll-based state machine:
Windows — IOCP with fully async reads and writes:
Testing
Without the change, the test tool hangs.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed