Skip to content

fix: add poll() compatibility shim for Windows to fix VLC header compilation - #769

Closed
kt286 wants to merge 1 commit into
linuxdeepin:masterfrom
kt286:fix/poll-compat
Closed

fix: add poll() compatibility shim for Windows to fix VLC header compilation#769
kt286 wants to merge 1 commit into
linuxdeepin:masterfrom
kt286:fix/poll-compat

Conversation

@kt286

@kt286 kt286 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor
  • Add src/compat/poll.h compatibility header implementing poll() on Windows using select()
  • Modify CMakeLists.txt to force-include poll.h for Windows platform
  • Link ws2_32 library for poll() compatibility implementation

fix: 添加 Windows 平台 poll() 兼容性实现,修复 VLC 头文件编译问题

  • 添加 src/compat/poll.h 兼容性头文件,在 Windows 上基于 select() 实现 poll() 函数
  • 修改 CMakeLists.txt,为 Windows 平台添加 poll.h 强制包含
  • 链接 ws2_32 库以支持 poll() 兼容性实现

Summary by Sourcery

Add Windows poll() compatibility support so VLC headers compile successfully on the Windows build.

Bug Fixes:

  • Fix Windows VLC header compilation by providing a poll() compatibility implementation backed by Winsock select().

Build:

  • Configure the Windows target to force-include the compatibility header and link the Winsock library.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: kt286

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot

Copy link
Copy Markdown

Hi @kt286. Thanks for your PR.

I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@sourcery-ai

sourcery-ai Bot commented Aug 18, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds a Windows-only poll() compatibility shim and wires it into the build so VLC headers that use poll() compile on Windows, including linking the required Winsock library.

Sequence diagram for Windows compat poll implementation using select

sequenceDiagram
  participant Caller
  participant poll
  participant Winsock

  Caller->>poll: poll(fds, nfds, timeout)
  poll->>Winsock: FD_SET / FD_ZERO on fd_set
  poll->>Winsock: select(0, &r, &w, &e, &tv)
  Winsock-->>poll: ret
  poll-->>Caller: ret with updated fds[i].revents
Loading

File-Level Changes

Change Details Files
Introduce a Windows-only poll() compatibility header providing a select()-based implementation and missing poll event constants.
  • Add new compat header guarded by _COMPAT_POLL_H and _WIN32.
  • Include Winsock headers to access SOCKET, struct pollfd/WSAPOLLFD, and select().
  • Define POLLIN, POLLOUT, POLLERR, POLLHUP, POLLNVAL if not already defined.
  • Implement inline poll() that maps requested events to fd_sets, calls select(), and fills revents based on ready sets.
src/compat/poll.h
Adjust the build configuration to force-include the compatibility header on Windows and link the needed system libraries.
  • Change from a global add_definitions(-include poll.h) to a Windows-only add_compile_options that force-includes the new compat/poll.h via an absolute path.
  • Extend Windows SMTC support linking to also link ws2_32, alongside other Windows runtime libraries, for the poll() implementation.
  • Scope both compile option and extra libraries to WIN32 (and non-MSVC for libraries) to avoid impacting other platforms and toolchains.
src/libdmusic/CMakeLists.txt

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 2 issues, and left some high level feedback:

  • The Windows-only poll shim currently never sets POLLHUP or POLLNVAL, so callers expecting full POSIX poll() semantics may misbehave; consider mapping these based on closed/invalid sockets or the select() return value where possible.
  • You only link ws2_32 when WIN32 AND NOT MSVC, but the compatibility poll in poll.h uses Winsock APIs for all Windows builds; ensure ws2_32 is linked for any configuration where this header can be force-included.
  • Using add_compile_options(-include "${CMAKE_SOURCE_DIR}/src/compat/poll.h") hardcodes an absolute path into the compiler flags; you may want to switch to a relative include and ensure the directory is in the include path to avoid issues with out-of-tree builds or different source layouts.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The Windows-only `poll` shim currently never sets `POLLHUP` or `POLLNVAL`, so callers expecting full POSIX `poll()` semantics may misbehave; consider mapping these based on closed/invalid sockets or the `select()` return value where possible.
- You only link `ws2_32` when `WIN32 AND NOT MSVC`, but the compatibility `poll` in `poll.h` uses Winsock APIs for all Windows builds; ensure `ws2_32` is linked for any configuration where this header can be force-included.
- Using `add_compile_options(-include "${CMAKE_SOURCE_DIR}/src/compat/poll.h")` hardcodes an absolute path into the compiler flags; you may want to switch to a relative include and ensure the directory is in the include path to avoid issues with out-of-tree builds or different source layouts.

## Individual Comments

### Comment 1
<location path="src/compat/poll.h" line_range="31-40" />
<code_context>
+#define POLLNVAL    0x0008
+#endif
+
+static inline int poll(struct pollfd *fds, unsigned int nfds, int timeout) {
+    fd_set r, w, e;
+    FD_ZERO(&r); FD_ZERO(&w); FD_ZERO(&e);
+
+    SOCKET max_fd = 0;
+    for (unsigned int i = 0; i < nfds; i++) {
+        if (fds[i].events & POLLIN)  FD_SET(fds[i].fd, &r);
+        if (fds[i].events & POLLOUT) FD_SET(fds[i].fd, &w);
+        FD_SET(fds[i].fd, &e);
+        if (fds[i].fd > max_fd) max_fd = fds[i].fd;
+    }
+
+    timeval tv;
+    tv.tv_sec  = timeout / 1000;
+    tv.tv_usec = (timeout % 1000) * 1000;
+
+    int ret = select(0, &r, &w, &e, timeout >= 0 ? &tv : NULL);
+
+    for (unsigned int i = 0; i < nfds; i++) {
</code_context>
<issue_to_address>
**issue (bug_risk):** Handle select() error return before inspecting fd_sets to avoid undefined behavior.

On Windows, when `select()` fails it returns `SOCKET_ERROR` and the `fd_set`s become undefined. The current logic still iterates over `fds` and derives `revents` when `ret < 0`, which can produce incorrect `POLLIN`/`POLLOUT`/`POLLERR` flags. Please short‑circuit on error (e.g. return immediately when `ret <= 0`), or at minimum guard the loop with `if (ret > 0)`.
</issue_to_address>

### Comment 2
<location path="src/compat/poll.h" line_range="35-40" />
<code_context>
+    fd_set r, w, e;
+    FD_ZERO(&r); FD_ZERO(&w); FD_ZERO(&e);
+
+    SOCKET max_fd = 0;
+    for (unsigned int i = 0; i < nfds; i++) {
+        if (fds[i].events & POLLIN)  FD_SET(fds[i].fd, &r);
+        if (fds[i].events & POLLOUT) FD_SET(fds[i].fd, &w);
+        FD_SET(fds[i].fd, &e);
+        if (fds[i].fd > max_fd) max_fd = fds[i].fd;
+    }
+
</code_context>
<issue_to_address>
**suggestion:** Remove unused max_fd or use it consistently for future non-Windows paths.

`max_fd` is calculated but never used in the `select()` call, so it’s currently dead code on Windows and may mislead readers into thinking it matters. Please either remove `max_fd` or clearly document why it’s unused, particularly if this code may be shared with non-Windows implementations later.

Suggested implementation:

```c
    fd_set r, w, e;
    FD_ZERO(&r); FD_ZERO(&w); FD_ZERO(&e);


```

```c
    fd_set r, w, e;
    FD_ZERO(&r); FD_ZERO(&w); FD_ZERO(&e);

    for (unsigned int i = 0; i < nfds; i++) {
        if (fds[i].events & POLLIN)  FD_SET(fds[i].fd, &r);
        if (fds[i].events & POLLOUT) FD_SET(fds[i].fd, &w);
        FD_SET(fds[i].fd, &e);
    }

#ifndef _COMPAT_POLL_H
#define _COMPAT_POLL_H

```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/compat/poll.h Outdated
Comment thread src/compat/poll.h Outdated
@deepin-bot

deepin-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 7.0.66
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #779

…ilation

- Add src/compat/poll.h compatibility header implementing poll() on Windows using select()
- Modify CMakeLists.txt to force-include poll.h for Windows platform
- Link ws2_32 library for poll() compatibility implementation

fix: 添加 Windows 平台 poll() 兼容性实现,修复 VLC 头文件编译问题

- 添加 src/compat/poll.h 兼容性头文件,在 Windows 上基于 select() 实现 poll() 函数
- 修改 CMakeLists.txt,为 Windows 平台添加 poll.h 强制包含
- 链接 ws2_32 库以支持 poll() 兼容性实现
@kt286
kt286 marked this pull request as draft August 24, 2026 11:54
@kt286

kt286 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

给 msys2 中的 vlc 提交了补丁,不需要处理了

@kt286 kt286 closed this Aug 24, 2026
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.

2 participants