-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Currently to use http4s-curl we use CurlApp which replaces the IORuntime with a CurlRuntime. 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 a Resource[IO, Client[IO]] with a CurlClientBuilder (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_SOCKETFUNCTIONto 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_actionshould be invoked.
https://curl.se/libcurl/c/curl_multi_socket_action.html -
A callback for
CURLMOPT_TIMERFUNCTIONshould also be registered. It should start a fiber thatsleeps the requested time and then callscurl_multi_socket_action.
https://curl.se/libcurl/c/CURLMOPT_TIMERFUNCTION.html