cURL / Mailing Lists / curl-library / Single Mail

curl-library

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

From: Daniel Stenberg <daniel_at_haxx.se>
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.

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2011-12-05