Hi,

I'm writing an application using the libcurl multi interface with HTTPS. The primary reason for using the multi interface is so that I can perform multiple asynchronous operations at once within a single threaded application. My application uses poll() so i've written a function to transform fd_set data to something which poll() can use. After I init my multi handle, init my easy handles, bind them, and start I call curl_multi_fdset() to figure out which descriptors libcurl is using. I continue to call this function periodically and also upon certain events so that I can add/remove items from my pollfd struct as needed. This works great.

The problem I'm running into revolves around open connections. I know libcurl leaves sockets open for re-use in the future, I verified by checking some of the log messages and the code. On completion of a successful HTTPS transaction, I see this:

* 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.

Looking at the libcurl code, it looks like sockets are only closed upon error, or when calling curl_multi_cleanup(). My application is always doing something with libcurl so I never actually call curl_multi_cleanup() except on exit. I do however remove easy handles from the multi stack, call curl_easy_cleanup(), and re-allocate easy handles later with curl_easy_init() and add them back onto the multi stack as needed. Is there any way that I can either:

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

Or is there some other better way to solve my problem? Thanks in advance for any ideas!
--
Chad Monroe

Reply via email to