-
Notifications
You must be signed in to change notification settings - Fork 8
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
Implement a CurlClient
based on FileDescriptorPoller
#117
Comments
@armanbilge Interesting! 😍 |
I read the documents and implemented some stuff required for supporting curl multi-socket which is the base of this.
I can't understand how this looping needs to be implemented.
Or to put it in other words, how to detect if the socket is ready?
|
So basically you will want to start a fiber like this: pollHandle.pollReadRec(()) { _ =>
IO {
curl_multi_socket_action(multi_handle, sockfd, CURL_CSELECT_IN, null)
Left(()) // loop forever
}
} and a similar one for the write loop. This is a fiber that will invoke
This is the most unstable part of the API, that Daniel and I are still debating over. Here's how to do it currently, but it might change. |
Got it, Thank you! |
Thanks for your work, don't hesitate if you have other questions!! 🚀 |
The tests are passing for the new runtime, however it needs polishing and some cleaning. |
Wow, amazing!! Thanks so much for trying this out.
Yes, this is exactly what I'm thinking as well, if it's not too much maintenance burden we should keep both implementations. Edit:
Btw, the old runtime can be refactored as a |
Yes, I'm gonna do it after cleaning this one. Currently I've just put a nowarn annotation on it so that I can focus on the task at hand. |
Currently to use http4s-curl we use
CurlApp
which replaces theIORuntime
with aCurlRuntime
. This means that it is not possible to integrate http4s-curl with FS2-based applications (Ember, Skunk, Lepus) and other native libraries (e.g. SNUnit).In Cats Effect 3.6 the default runtime offers file descriptor I/O polling that works with all of these libraries. The idea would be to use
IOApp
as usual and then to construct aResource[IO, Client[IO]]
with aCurlClientBuilder
(similar to Ember).Here's a rough sketch for how to implement a
Client[IO]
using file descriptor polling:Create a
MapRef[IO, FileDescriptor, (Fiber, Fiber)]
to keep track of a dedicated fiber for polling each relevant file descriptor for each type of interest (read interest vs write interest).Configure the
CURLMOPT_SOCKETFUNCTION
to get notified about when cURL needs to start/stop monitoring sockets for read/writes. Use these callbacks to start/cancel fibers in theMapRef
.https://curl.se/libcurl/c/CURLMOPT_SOCKETFUNCTION.html
To add a new socket you should register the file descriptor.
Then, start a fiber looping on
read
-readiness and another looping onwrite
-readiness. Whenever the socket is ready, thecurl_multi_socket_action
should be invoked.https://curl.se/libcurl/c/curl_multi_socket_action.html
A callback for
CURLMOPT_TIMERFUNCTION
should also be registered. It should start a fiber thatsleep
s the requested time and then callscurl_multi_socket_action
.https://curl.se/libcurl/c/CURLMOPT_TIMERFUNCTION.html
The text was updated successfully, but these errors were encountered: