1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLMOPT_MAX_HOST_CONNECTIONS
5Section: 3
6Source: libcurl
7See-also:
8  - CURLMOPT_MAXCONNECTS (3)
9  - CURLMOPT_MAX_TOTAL_CONNECTIONS (3)
10Protocol:
11  - All
12---
13
14# NAME
15
16CURLMOPT_MAX_HOST_CONNECTIONS - max number of connections to a single host
17
18# SYNOPSIS
19
20~~~c
21#include <curl/curl.h>
22
23CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_MAX_HOST_CONNECTIONS,
24                            long max);
25~~~
26
27# DESCRIPTION
28
29Pass a long to indicate **max**. The set number is used as the maximum amount
30of simultaneously open connections to a single host (a host being the same as
31a hostname + port number pair). For each new session to a host, libcurl might
32open a new connection up to the limit set by CURLMOPT_MAX_HOST_CONNECTIONS(3).
33When the limit is reached, new sessions are kept pending until a connection
34becomes available.
35
36The default **max** value is 0, unlimited. This set limit is also used for
37proxy connections, and then the proxy is considered to be the host for which
38this limit counts.
39
40When more transfers are added to the multi handle than what can be performed
41due to the set limit, they are queued up waiting for their chance. When that
42happens, the CURLOPT_TIMEOUT_MS(3) timeout is inclusive of the waiting time,
43meaning that if you set a too narrow timeout in such a case the transfer might
44never even start before it times out.
45
46Even in the queued up situation, the CURLOPT_CONNECTTIMEOUT_MS(3) timeout is
47however treated as a per-connect timeout.
48
49Changing this value when there are transfers in progress is possible, and the
50new value is then used the next time checks are performed. Lowering the value
51does however not close down any active transfers, it simply does not allow new
52ones to get made.
53
54# DEFAULT
55
560
57
58# EXAMPLE
59
60~~~c
61int main(void)
62{
63  CURLM *m = curl_multi_init();
64  /* do no more than 2 connections per host */
65  curl_multi_setopt(m, CURLMOPT_MAX_HOST_CONNECTIONS, 2L);
66}
67~~~
68
69# AVAILABILITY
70
71Added in 7.30.0
72
73# RETURN VALUE
74
75Returns CURLM_OK if the option is supported, and CURLM_UNKNOWN_OPTION if not.
76