implement Windows platform compatibility via WSAPoll and IOCP#60
Closed
qdsxinyee wants to merge 15 commits into
Closed
implement Windows platform compatibility via WSAPoll and IOCP#60qdsxinyee wants to merge 15 commits into
qdsxinyee wants to merge 15 commits into
Conversation
- platform.hpp: add Windows compatibility shim - define iovec, msghdr, socklen_t, pollfd, nfds_t - map POSIX errno names to WSA equivalents - wrap close/fcntl/poll/recvmsg/sendmsg/getsockopt/setsockopt - undef interface macro to fix local_endpoint.hpp conflict - netfwd.hpp: use uintptr_t for native_handle_type on Windows to avoid truncating 64-bit SOCKET values - poll_context.hpp: replace errno with sock_errno() fix ::socket() return type handling for Windows - internet.hpp: replace memcpy with explicit loop in constexpr constructor to satisfy MSVC constexpr rules - io_context.hpp: add IOCP backend selection, guard SIGPIPE - iocp_context.hpp: new IOCP backend implementation - AcceptEx / ConnectEx / WSARecv / WSASend async operations - iocp_op_kind tag for zero-RTTI completion dispatch - wsa_guard RAII for WSAStartup/WSACleanup - CMakeLists.txt: add BEMAN_NET_WITH_IOCP option (Windows only) - src/beman/net/CMakeLists.txt: link ws2_32/mswsock on Windows
Add iocp_context as the primary Windows io_context backend using I/O Completion Ports (IOCP), and waspoll_context as a poll-based fallback. iocp_context design: - Each pending async operation is represented by an iocp_op embedding OVERLAPPED as its first member, recovered via reinterpret_cast on GQCS completion - Synchronous completions (rc==0) are handled via deferred_io_task to avoid re-entering the dispatch call stack; FILE_SKIP_COMPLETION_PORT_ON_SUCCESS is set on each socket to prevent the kernel posting a redundant IOCP packet for the same operation - AcceptEx/ConnectEx loaded dynamically via WSAIoctl per socket - Timers implemented as a sorted_list keyed on time_point, checked on every run_one() call - d_socket_count tracked alongside d_outstanding_io to prevent premature event loop termination - WSAStartup/WSACleanup managed by RAII wsa_guard platform.hpp: add Windows-specific type aliases and Winsock includes
On Windows, accepted sockets are set non-blocking via set_nonblocking(), causing add_outstanding() to invoke work() inline. If the operation completes synchronously (e.g. async_send with data already buffered), work() calls complete() internally, which decrements d_outstanding, resumes the coroutine, and may destroy his before submit() returns. The previous code unconditionally called this->complete() after submit() returned ready, resulting in a heap-use-after-free detected by ASan. Fix: on Windows, do not touch his after submit(). On POSIX, sockets default to blocking so work() is never called inline; the explicit this->complete() call is still required there. Fixes: ASan heap-use-after-free in sender_state::start() / complete()
Author
|
Closing as upstream has added IOCP support in main. Thanks! |
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.
Description
This PR implements the core network capabilities for Windows platforms, addressing the missing Windows support mentioned in the project's current state. It is intended to be merged into the
windows-supportbranch to finalize the cross-platform compatibility.Key Implementations:
WSAPoll):WSAPollfor basic I/O polling, acting as a counterpart to the POSIXpoll(2)implementation.IOCP):-DBEMAN_NET_WITH_IOCP=ON.How to test this locally (Windows):
Test default WSAPoll:
Test IOCP backend: