Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions ext/curb_multi.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,25 @@ static VALUE ruby_curl_multi_max_connects(VALUE self, VALUE count) {
return count;
}

/*
* call-seq:
* multi = Curl::Multi.new
* multi.max_host_connections = 1
*
* Set the max number of connections per host
*/
static VALUE ruby_curl_multi_max_host_connections(VALUE self, VALUE count) {
#ifdef HAVE_CURLMOPT_MAX_HOST_CONNECTIONS
ruby_curl_multi *rbcm;

Data_Get_Struct(self, ruby_curl_multi, rbcm);

curl_multi_setopt(rbcm->handle, CURLMOPT_MAX_HOST_CONNECTIONS, NUM2LONG(count));
#endif

return count;
}

/*
* call-seq:
* multi = Curl::Multi.new
Expand Down Expand Up @@ -704,6 +723,7 @@ void init_curb_multi() {
rb_define_singleton_method(cCurlMulti, "autoclose", ruby_curl_multi_get_autoclose, 0);
/* Instance methods */
rb_define_method(cCurlMulti, "max_connects=", ruby_curl_multi_max_connects, 1);
rb_define_method(cCurlMulti, "max_host_connections=", ruby_curl_multi_max_host_connections, 1);
rb_define_method(cCurlMulti, "pipeline=", ruby_curl_multi_pipeline, 1);
rb_define_method(cCurlMulti, "_add", ruby_curl_multi_add, 1);
rb_define_method(cCurlMulti, "_remove", ruby_curl_multi_remove, 1);
Expand Down
3 changes: 3 additions & 0 deletions ext/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ def have_constant(name)
have_constant :CURL_SSLVERSION_SSLv2
have_constant :CURL_SSLVERSION_SSLv3

# Added in 7.30.0
have_constant "curlmopt_max_host_connections"

# Added in 7.34.0
have_constant :CURL_SSLVERSION_TLSv1_0
have_constant :CURL_SSLVERSION_TLSv1_1
Expand Down
19 changes: 19 additions & 0 deletions tests/tc_curl_multi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,25 @@ def test_multi_easy_http_with_max_connects
end
end

def test_multi_easy_http_with_max_host_connections
urls = [
{ :url => TestServlet.url + '?q=1', :method => :get },
{ :url => TestServlet.url + '?q=2', :method => :get },
{ :url => TestServlet.url + '?q=3', :method => :get }
]
Curl::Multi.http(urls, {:pipeline => true, :max_host_connections => 1}) do|easy, code, method|
assert_equal 200, code
case method
when :post
assert_match(/POST/, easy.body)
when :get
assert_match(/GET/, easy.body)
when :put
assert_match(/PUT/, easy.body)
end
end
end

def test_multi_recieves_500
m = Curl::Multi.new
e = Curl::Easy.new("http://127.0.0.1:9129/methods")
Expand Down