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

Add select() to std for darwin. #16382

Open
il-k opened this issue Jul 11, 2023 · 1 comment
Open

Add select() to std for darwin. #16382

il-k opened this issue Jul 11, 2023 · 1 comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. os-macos standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@il-k
Copy link

il-k commented Jul 11, 2023

select() is left out from zig's std. Yet, it still has an important role in darwin systems: darwin does not support poll(), nor kqueue() for polling tty files. It appears the only way to do it, sadly, is to use select().

It would be nice if it was made available in standard library for darwin.

@ifreund
Copy link
Member

ifreund commented Jul 11, 2023

My first thought was "Please no, select is always a footgun because of the fd limit" but from the article linked it seems macOS has a workaround for that:

The avid reader might be wondering: “what if we have more than 1024 file descriptors? select is not going to work!” You’re right! This was a problem, so let’s enter The OSX select(2) Trick II: _DARWIN_UNLIMITED_SELECT.

This little gem hidden in the manual page tells us that if _DARWIN_UNLIMITED_SELECT is defined at compilation time, we are allowed to go beyond the FD_SETSIZE limit! We cannot create the fd_set as usual nor use FD_ZERO, we’ll need to manually allocate it and zero it with memset: 1, 2, 3.

I think that it would be reasonable to force usage of this darwin workaround for select if adding it to the standard library.

I don't think select should be added for any target for which it is not required, it's too big of a footgun on most unix like systems.

@ifreund ifreund added enhancement Solving this issue will likely involve adding new logic or components to the codebase. standard library This issue involves writing Zig code for the standard library. os-macos labels Jul 11, 2023
@ifreund ifreund added this to the 0.12.0 milestone Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. os-macos standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

2 participants