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

Create callback based on file descriptor monitoring #190

Merged
merged 102 commits into from
Nov 8, 2024
Merged

Conversation

jcheng5
Copy link
Member

@jcheng5 jcheng5 commented Oct 21, 2024

No description provided.

src/fd.cpp Outdated Show resolved Hide resolved
@jcheng5
Copy link
Member Author

jcheng5 commented Oct 22, 2024

Thinking out loud: Again, impressed at your pace in getting this done. I haven't actually run the code but I will assume for now that it works as advertised.

I looked at later_posix.cpp for the first time in a long while and (re)learned that the Timer class always uses a background thread--I'd forgotten that. Sorry if I said anything too misleading.

It makes me a little itchy that there is a new thread being launched for each later_fd call. Probably not noticeable to any of our users, but it's such a common idiom to have a single thread/loop calling select/poll/epoll for many jobs that a dedicated thread per callback feels a bit shocking. I'm fine if you want to leave this the way it is for now while we complete the end-to-end scenario.

src/fd.cpp Show resolved Hide resolved
src/fd.cpp Outdated Show resolved Hide resolved
@shikokuchuo
Copy link
Collaborator

Adding a note that I've tweaked the error behaviour slightly in 0fa8ed3.

Before, I had later_fd() throw an error if no file descriptors were provided, more as a safety measure than any particular reason, but the code handles this possibility safely.

During initial integration testing, I came across cases where curl could return no files descriptors at the start of a transaction. Probably user error on my part, but I can't say for certain yet. But this led me to think it could be helpful for others in a similar situation, where either the callback can handle the length zero response or it just needs to loop again.

@jcheng5
Copy link
Member Author

jcheng5 commented Nov 5, 2024

We need loop_empty to reflect pending later_fd() calls, not just pending later() calls.

test_that("loop_empty() reflects later_fd callbacks", {
  # Windows can't `later_fd` on `file()` probably?
  testthat::skip_on_os("windows")
  
  expect_true(loop_empty())
  f1 <- file()
  on.exit(close(f1))

  cancel <- later_fd(~{}, f1)
  expect_false(loop_empty())
  cancel()
  expect_true(loop_empty())

  later_fd(~{}, f1, timeout = 0)
  expect_false(loop_empty())
  run_now()
  expect_true(loop_empty())
})

src/fd.cpp Outdated Show resolved Hide resolved
src/fd.cpp Show resolved Hide resolved
src/fd.cpp Outdated Show resolved Hide resolved
src/fd.cpp Outdated Show resolved Hide resolved
src/fd.cpp Outdated Show resolved Hide resolved
src/fd.cpp Outdated Show resolved Hide resolved
src/fd.cpp Outdated Show resolved Hide resolved
src/fd.cpp Outdated Show resolved Hide resolved
@shikokuchuo
Copy link
Collaborator

We need loop_empty to reflect pending later_fd() calls, not just pending later() calls.

Just to confirm that this is noted, and I will be addressing it.

@jcheng5
Copy link
Member Author

jcheng5 commented Nov 7, 2024

Looks great, I'm really excited!!

GitHub won't let me mark this PR as Approved as I technically opened the PR, but LGTM 👍

Let me know if you were planning to make any more changes, if not I'll go ahead and merge!

@shikokuchuo
Copy link
Collaborator

Oh yes I have some final cleanups - will commit shortly!

@shikokuchuo
Copy link
Collaborator

And done. All good from my side. I had planned on writing you a note on the changes but you had already picked it up! You can see I've embraced RAII :) Thanks for your thorough code review on this PR.

Copy link
Collaborator

@shikokuchuo shikokuchuo left a comment

Choose a reason for hiding this comment

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

Please proceed with the merge, thanks!

@jcheng5
Copy link
Member Author

jcheng5 commented Nov 8, 2024

You keep saying you're done and then adding more commits 🤣

I'm pressing the button!!

@jcheng5 jcheng5 merged commit 8210bc8 into r-lib:main Nov 8, 2024
16 checks passed
@jcheng5
Copy link
Member Author

jcheng5 commented Nov 8, 2024

🥂🍾

@shikokuchuo shikokuchuo deleted the fd branch November 14, 2024 22:08
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.

2 participants