Skip to content

Commit

Permalink
Add more curl options
Browse files Browse the repository at this point in the history
Add max_send_speed, max_recv_speed, low_speed_limit, low_speed_time
  • Loading branch information
astrada committed Dec 7, 2015
1 parent c8e2da6 commit 575b3fe
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/gapi/gapiConfig.ml
Expand Up @@ -63,6 +63,10 @@ type t = {
compress : bool;
auth : auth_config;
upload_chunk_size : int;
max_send_speed : int64;
max_recv_speed : int64;
low_speed_limit : int;
low_speed_time : int;
}

let application_name = {
Expand Down Expand Up @@ -93,6 +97,22 @@ let upload_chunk_size = {
GapiLens.get = (fun x -> x.upload_chunk_size);
GapiLens.set = (fun v x -> { x with upload_chunk_size = v })
}
let max_send_speed = {
GapiLens.get = (fun x -> x.max_send_speed);
GapiLens.set = (fun v x -> { x with max_send_speed = v })
}
let max_recv_speed = {
GapiLens.get = (fun x -> x.max_recv_speed);
GapiLens.set = (fun v x -> { x with max_recv_speed = v })
}
let low_speed_limit = {
GapiLens.get = (fun x -> x.low_speed_limit);
GapiLens.set = (fun v x -> { x with low_speed_limit = v })
}
let low_speed_time = {
GapiLens.get = (fun x -> x.low_speed_time);
GapiLens.set = (fun v x -> { x with low_speed_time = v })
}

let default = {
application_name = "gapi-ocaml";
Expand All @@ -102,6 +122,10 @@ let default = {
compress = true;
auth = NoAuth;
upload_chunk_size = 10485760;
max_send_speed = 0L;
max_recv_speed = 0L;
low_speed_limit = 0;
low_speed_time = 0;
}

let default_debug = {
Expand All @@ -112,5 +136,9 @@ let default_debug = {
compress = false;
auth = NoAuth;
upload_chunk_size = 10485760;
max_send_speed = 0L;
max_recv_speed = 0L;
low_speed_limit = 0;
low_speed_time = 0;
}

24 changes: 24 additions & 0 deletions src/gapi/gapiConfig.mli
Expand Up @@ -85,6 +85,14 @@ type t = {
(** Authorization configuration. *)
upload_chunk_size : int;
(** Chunk default size (in bytes) used by resumable upload. Should be a multiple of 512KB. *)
max_send_speed : int64;
(** If an upload exceeds this speed (counted in bytes per second) on cumulative average during the transfer, the transfer will pause to keep the average rate less than or equal to the parameter value. Defaults to unlimited speed. *)
max_recv_speed : int64;
(** If a download exceeds this speed (counted in bytes per second) on cumulative average during the transfer, the transfer will pause to keep the average rate less than or equal to the parameter value. Defaults to unlimited speed. *)
low_speed_limit : int;
(** It contains the average transfer speed in bytes per second that the transfer should be below during [low_speed_time] seconds for libcurl to consider it to be too slow and abort. Defaults to 0 (disabled). *)
low_speed_time : int;
(** It contains the time in number seconds that the transfer speed should be below the [low_speed_limit] for the library to consider it too slow and abort. Defaults to 0 (disabled). *)
}

val application_name : (t, string) GapiLens.t
Expand All @@ -101,6 +109,14 @@ val auth : (t, auth_config) GapiLens.t
(** Authorization configuration lens. *)
val upload_chunk_size : (t, int) GapiLens.t
(** Upload chunk size lens. *)
val max_send_speed : (t, int64) GapiLens.t
(** Max send speed lens. *)
val max_recv_speed : (t, int64) GapiLens.t
(** Max receive speed lens. *)
val low_speed_limit : (t, int) GapiLens.t
(** Low speed limit lens. *)
val low_speed_time : (t, int) GapiLens.t
(** Low speed time lens. *)

val default : t
(** Default configuration.
Expand All @@ -113,6 +129,10 @@ val default : t
compress = true;
auth = NoAuth;
upload_chunk_size = 10485760; (* 10MB *)
max_send_speed = 0L;
max_recv_speed = 0L;
low_speed_limit = 0;
low_speed_time = 0;
}]}
*)
Expand All @@ -128,6 +148,10 @@ val default_debug : t
compress = false;
auth = NoAuth;
upload_chunk_size = 10485760; (* 10MB *)
max_send_speed = 0L;
max_recv_speed = 0L;
low_speed_limit = 0;
low_speed_time = 0;
}]}
*)
Expand Down
8 changes: 8 additions & 0 deletions src/gapi/gapiConversation.ml
Expand Up @@ -244,11 +244,19 @@ let with_session
let timeout = config.GapiConfig.timeout in
let connect_timeout = config.GapiConfig.connect_timeout in
let compress = config.GapiConfig.compress in
let max_recv_speed = config.GapiConfig.max_recv_speed in
let max_send_speed = config.GapiConfig.max_send_speed in
let low_speed_limit = config.GapiConfig.low_speed_limit in
let low_speed_time = config.GapiConfig.low_speed_time in
let curl_session = GapiCurl.init
?debug_function
?timeout
?connect_timeout
~compress
~max_recv_speed
~max_send_speed
~low_speed_limit
~low_speed_time
curl_state in
let cleanup () = ignore (GapiCurl.cleanup curl_session) in
let session =
Expand Down
12 changes: 12 additions & 0 deletions src/gapi/gapiCurl.ml
Expand Up @@ -43,6 +43,10 @@ let init
?connect_timeout
?(follow_location = false)
?(compress = false)
?(max_send_speed = 0L)
?(max_recv_speed = 0L)
?(low_speed_limit = 0)
?(low_speed_time = 0)
?options
(state : [`Initialized] t) : [`Created] t =
let error_buffer = ref "" in
Expand Down Expand Up @@ -70,6 +74,14 @@ let init
| true ->
Curl.set_encoding curl Curl.CURL_ENCODING_DEFLATE
end;
if max_send_speed > 0L then
Curl.set_maxsendspeedlarge curl max_send_speed;
if max_recv_speed > 0L then
Curl.set_maxrecvspeedlarge curl max_recv_speed;
if low_speed_limit > 0 then
Curl.set_lowspeedlimit curl low_speed_limit;
if low_speed_time > 0 then
Curl.set_lowspeedtime curl low_speed_time;
begin match options with
None -> ()
| Some option_list -> set_curl_options option_list curl
Expand Down
4 changes: 4 additions & 0 deletions src/gapi/gapiCurl.mli
Expand Up @@ -17,6 +17,10 @@ val init :
?connect_timeout:int ->
?follow_location:bool ->
?compress:bool ->
?max_send_speed:int64 ->
?max_recv_speed:int64 ->
?low_speed_limit:int ->
?low_speed_time:int ->
?options:Curl.curlOption list ->
[ `Initialized ] t ->
[ `Created ] t
Expand Down

0 comments on commit 575b3fe

Please sign in to comment.