Skip to content

Commit

Permalink
Allow setting max-streams for multi handle
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed Dec 4, 2024
1 parent 21b7793 commit 403fc62
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
8 changes: 5 additions & 3 deletions R/multi.R
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,20 @@ multi_run <- function(timeout = Inf, poll = FALSE, pool = NULL){

#' @param total_con max total concurrent connections.
#' @param host_con max concurrent connections per host.
#' @param multiplex enable HTTP/2 multiplexing if supported by host and client.
#' @param max_streams max concurrent multiplex streams for HTTP/2.
#' @param multiplex use HTTP/2 multiplexing if supported by host and client.
#' @export
#' @useDynLib curl R_multi_setopt
#' @rdname multi
multi_set <- function(total_con = 50, host_con = 6, multiplex = TRUE, pool = NULL){
multi_set <- function(total_con = 50, host_con = 6, max_streams = 10, multiplex = TRUE, pool = NULL){
if(is.null(pool))
pool <- multi_default()
stopifnot(inherits(pool, "curl_multi"))
stopifnot(is.numeric(total_con))
stopifnot(is.numeric(host_con))
stopifnot(is.numeric(max_streams))
stopifnot(is.logical(multiplex))
.Call(R_multi_setopt, pool, total_con, host_con, multiplex)
.Call(R_multi_setopt, pool, total_con, host_con, max_streams, multiplex)
}

#' @export
Expand Down
12 changes: 10 additions & 2 deletions man/multi.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/curl-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#define HAS_CURL_PARSER 1
#endif

#if AT_LEAST_CURL(7, 67)
#define HAS_MAX_STREAMS 1
#endif

#if AT_LEAST_CURL(7, 72)
#define HAS_CURLINFO_EFFECTIVE_METHOD 1
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static const R_CallMethodDef CallEntries[] = {
{"R_multi_list", (DL_FUNC) &R_multi_list, 1},
{"R_multi_new", (DL_FUNC) &R_multi_new, 0},
{"R_multi_run", (DL_FUNC) &R_multi_run, 3},
{"R_multi_setopt", (DL_FUNC) &R_multi_setopt, 4},
{"R_multi_setopt", (DL_FUNC) &R_multi_setopt, 5},
{"R_new_file_writer", (DL_FUNC) &R_new_file_writer, 1},
{"R_new_handle", (DL_FUNC) &R_new_handle, 0},
{"R_nslookup", (DL_FUNC) &R_nslookup, 2},
Expand Down
5 changes: 4 additions & 1 deletion src/multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,15 @@ SEXP R_multi_new(void){
return ptr;
}

SEXP R_multi_setopt(SEXP pool_ptr, SEXP total_con, SEXP host_con, SEXP multiplex){
SEXP R_multi_setopt(SEXP pool_ptr, SEXP total_con, SEXP host_con, SEXP max_streams, SEXP multiplex){
CURLM *multi = get_multiref(pool_ptr)->m;
massert(curl_multi_setopt(multi, CURLMOPT_MAX_TOTAL_CONNECTIONS, (long) Rf_asInteger(total_con)));
massert(curl_multi_setopt(multi, CURLMOPT_MAX_HOST_CONNECTIONS, (long) Rf_asInteger(host_con)));
massert(curl_multi_setopt(multi, CURLMOPT_PIPELINING,
Rf_asLogical(multiplex) ? CURLPIPE_MULTIPLEX : CURLPIPE_NOTHING));
#ifdef HAS_MAX_STREAMS
massert(curl_multi_setopt(multi, CURLMOPT_MAX_CONCURRENT_STREAMS, (long) Rf_asInteger(max_streams)));
#endif
return pool_ptr;
}

Expand Down

0 comments on commit 403fc62

Please sign in to comment.