Compare commits

...

2 commits

Author SHA1 Message Date
Simon Cruanes
4b7d9ec769
make CURLOPT_NOSIGNAL=false the default; simplify
Some checks failed
build / Build (push) Has been cancelled
2025-01-29 21:55:16 -05:00
Stéphane Lavergne
ebf1e1fc12 Expose underlying no signal in a global setting 2025-01-29 21:46:19 -05:00
2 changed files with 23 additions and 4 deletions

View file

@ -71,17 +71,27 @@ end
type t = { curl: Curl.t } [@@unboxed]
type client = t
let _top_mutex = Mutex.create ()
let _with_mutex f =
Mutex.lock _top_mutex;
match f () with
| res ->
Mutex.unlock _top_mutex;
res
| exception e ->
Mutex.unlock _top_mutex;
raise e
let _init =
let initialized = ref false in
let mutex = Mutex.create () in
fun () ->
Mutex.lock mutex;
_with_mutex @@ fun () ->
if not !initialized then (
initialized := true;
Curl.global_init Curl.CURLINIT_GLOBALALL;
at_exit Curl.global_cleanup
);
Mutex.unlock mutex
)
let make ?(set_opts = fun _ -> ()) ?cookiejar_file
?(enable_session_cookies = false) () : t =
@ -96,6 +106,9 @@ let make ?(set_opts = fun _ -> ()) ?cookiejar_file
{ curl }
let delete (self : t) = Curl.cleanup self.curl
let _cfg_no_signal = ref false (* default: 0 *)
let _get_no_signal () : bool = _with_mutex @@ fun () -> !_cfg_no_signal
let set_no_signal v = _with_mutex @@ fun () -> _cfg_no_signal := v
module Cookies = struct
let reload_cookiejar (self : t) : unit =
@ -131,6 +144,7 @@ let _apply_config (self : t) (config : Config.t) : unit =
opt_iter authmethod ~f:(Curl.set_httpauth self.curl);
opt_iter username ~f:(Curl.set_username self.curl);
opt_iter password ~f:(Curl.set_password self.curl);
Curl.set_nosignal self.curl (_get_no_signal ());
()
let _set_headers (self : t) (headers : _ list) : unit =

View file

@ -37,6 +37,11 @@ val delete : t -> unit
val with_client : ?set_opts:(Curl.t -> unit) -> (t -> 'a) -> 'a
(** Make a temporary client, call the function with it, then cleanup. *)
val set_no_signal : bool -> unit
(** Set no_signal default value for each new client instance. Default is [true].
See [CURLOPT_NOSIGNAL].
@since NEXT_RELEASE *)
(** Cookie handling.
@since NEXT_RELEASE *)