cURL / Mailing Lists / curl-library / Single Mail


Re: how to use same connection when we use curl_multi_socket_action() API

From: Daniel Stenberg <>
Date: Mon, 5 Dec 2011 10:20:18 +0100 (CET)

On Mon, 5 Dec 2011, venkataragavan vijayakumar wrote:

> I need to use same TCP connection between client and server for multiple
> request and response. I am using curl_multi_socket_action() API to trigger
> the operations for each request. For all request i am using the same
> multi_handle, but with different curl handle. But libcurl is generating
> different sockets for each request. How to use the same connection for all
> request?

If you do the requests sequentially and if the protocol and server agree that
the connection can be re-used, then libcurl makes a best effort to re-use
connections within multi handles. It doesn't even matter if you use the same
easy handles or not, as the connection pool is kept outside of the easy
handles when the multi interface is used.

> When I call first time the curl_multi_socket_action() i am giving the sockfd
> argument as 0 and for the further invoking i am giving sockfd argument given
> by the callback.

Don't use socket 0 as a dummy. That's a valid descriptor number for stdin so
you probably just confuse libcurl with it. To just trigger the timeout
actions, pass in CURL_SOCKET_TIMEOUT in the sockfd argument.

List admin:
Received on 2011-12-05