On Mar 21, 2009, at 9:25 AM, Daniel Stenberg wrote:

On Fri, 20 Mar 2009, Chad Monroe wrote:

* Expire cleared
* Connection #0 to host 10.4.4.204 left intact

About ~10 seconds later the server sends another packet on this socket, poll() fires, and my application calls curl_multi_perform(). I'm guessing that because the transfer is finished, curl_multi_perform() does not perform any action on this socket as I get stuck in this loop forever. poll() continuously fires with an event of POLLIN and curl_multi_perform() gets called. curl_multi_fdset() still reports the descriptor as in use at this time.

I don't get it. If the transfer is complete and the socket is no longer used by any active easy handle, why does it still get used in poll() ? The moment that transfer was completed, libcurl will of course no longer use that socket nor care about it if something arrives on it.

Looking at the libcurl code, it looks like sockets are only closed upon error, or when calling curl_multi_cleanup().

Yes, or if the server says so or just closes it, or if you tell libcurl to not re-use the handle for that specific transfer (CURLOPT_FORBID_REUSE).

1.) retrieve all sockets used by a specific easy handle so I can close them manually
2.) tell libcurl to close all sockets associated with an easy handle

Neither option exist but for the reason that they really shouldn't be needed. You _either_ don't want the connection to be kept around and re-use and then you tell libcurl to not re-use it, or you want it to be re-use and then you want it kept open as much as possible (of course limited by the limiter for max number of connections).

And recently libcurl has also got a lot better to kill connections that died recently, even before they are attempted to get re-used so thus it will now keep less sockets in TIME_WAIT or other "almost- dead" states.

Or is there some other better way to solve my problem?

The primary question is simply why you poll() on sockets not used by libcurl any longer?

--

/ daniel.haxx.se

Hi Daniel,

Thanks for the quick response. The reason I continue to poll() on sockets "not used by libcurl any longer" is because curl_multi_fdset() returns them in the fd_set data even after the connection has finished. I assume this is because libcurl leaves the sockets open as denoted by the message:

* Connection #0 to host 10.4.4.204 left intact

I'm not sure if this is the intended behavior of curl_multi_fdset() or if it's possibly a bug. If you think it's an issue I can investigate further if you'd like.

In any case, I checked out CURLOPT_FORBID_REUSE and it causes libcurl to perform exactly how I want. When the connection is complete it closes the sockets and removes them from the fd_set returned by curl_multi_fdset() which causes my application to remove them from poll().
--
Chad Monroe

Reply via email to