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

Use nix::select directly to fix MacOS support #2

Closed
wants to merge 1 commit into from

Conversation

zeenix
Copy link
Contributor

@zeenix zeenix commented Mar 9, 2024

On MacOS, poll and kqueue are not supported for tty. So let's ditch mio completely and directly call select ourselves. It's not a lot of work anyway.

This fixes MacOS support.

On MacOS, `poll` and `kqueue` are not supported for tty[1]. So let's ditch
mio completely and directly call `select` ourselves. It's not a lot of
work anyway.

This fixes MacOS support.

[1]: tokio-rs/mio#1377
@zeenix
Copy link
Contributor Author

zeenix commented Mar 9, 2024

I tested this to work on both Linux and Mac.

@Canop
Copy link
Owner

Canop commented Mar 10, 2024

I'm trying to ponder the downsides of using the old select.

As I understand it, this would fail if the application using xterm-query has already opened many files, because of the file selector limit of select ?

Using epoll for platforms supporting it and select for Mac might be better. And maybe the Mac should use poll instead of select.

@Canop
Copy link
Owner

Canop commented Mar 10, 2024

wezterm's filedescriptor crate seems to have built a "poll" wrapper with compatibility for linux, mac, and windows: https://docs.rs/filedescriptor/latest/filedescriptor/index.html#polling

@zeenix
Copy link
Contributor Author

zeenix commented Mar 10, 2024

And maybe the Mac should use poll instead of select.

The whole issue is that Mac doesn't support poll or kqueue for tty (it's in the first line of the pr description 😉).

AFAIK the difference between poll and select is that the former is more efficient than the latter, for repeatedly calling. In here, we only need to call once and even if we didn't, we've only one FD so it wouldn't be so inefficient to re-initialising the fdset all the time.

I can't find any information about how they differ in terms of the number of open FDs in the process. Could you point me to some resource?

To summarise, I think only select usage keeps things simple here but if there are good reasons to avoid it for this very simple case, I can update the pr to use select only for Mac.

@Canop
Copy link
Owner

Canop commented Mar 10, 2024

To summarise, I think only select usage keeps things simple here but if there are good reasons to avoid it for this very simple case, I can update the pr to use select only for Mac.

https://beesbuzz.biz/code/5739-The-problem-with-select-vs-poll

I'm not sure of the exact consequences of this problem.

Wezterm seems to have adopted the logic of using select only for mac: https://docs.rs/filedescriptor/latest/filedescriptor/index.html#polling

@zeenix
Copy link
Contributor Author

zeenix commented Mar 10, 2024

I can't find any information about how they differ in terms of the number of open FDs in the process. Could you point me to some resource?

NM, I found it. I'll update the pr as per your suggestion.

@zeenix
Copy link
Contributor Author

zeenix commented Mar 10, 2024

Closing this in favor of #4, that uses select on MacOS but poll on other OSes.

@zeenix zeenix closed this Mar 10, 2024
@zeenix zeenix mentioned this pull request Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants