ygrek / ocurl

OCaml bindings to libcurl
https://ygrek.org/p/ocurl
MIT License
60 stars 32 forks source link

Allow opensocketfunction to create the socket #51

Closed dwwoelfel closed 3 years ago

dwwoelfel commented 3 years ago

The current implementation of set_opensocketfunction has internal code creates the socket and then calls the provided callback with the new socket.

Would it be possible to create a separate function that allows the user of ocurl to create the socket?

I'd like to use opensocketfunction and closesocketfunction to get more control over creating and releasing the sockets to make ocurl play more nicely with janestreet's Async. With the current opensocketfunction, I'll occasionally see the socket in the set_socket_function callback before I see it in the opensocketfunction callback.

I'm happy to try to implement this if there's no technical reason why it's not possible. Before I start, it would be helpful to get some guidance. Should I just add a new function, e.g. set_createsocketfunction, or would it be better to make a breaking change to the existing function to accept a variant, e.g. | CreateSocket of (unit -> Unix.file_descr) | UseSocket of (Unix.file_descr -> unit)?

ygrek commented 3 years ago

Separate set_createsocketfunction sounds better to me (with a comment explaining the difference).

dwwoelfel commented 3 years ago

I started work on this, but it didn't solve the underlying issue I was having, so I'm abandoning it for now. WIP is at https://github.com/dwwoelfel/ocurl/tree/set_createsocketfunction if anybody else wants a starting point.

The issue I thought I was having with seeing a socket in the set_socket_function callback before seeing it in the opensocketfunction callback is a different issue with libcurl, described in more detail here https://github.com/curl/curl/issues/5747.