curl-library
Re: libcurl multi interface - handling abnormal disconnections
Date: Tue, 28 Jan 2014 14:56:44 +0000
On Tue, Jan 28, 2014 at 9:28 AM, Jonathan Masters <jon_at_than.cc> wrote:
> On Mon, Jan 27, 2014 at 7:10 PM, Fabian Frank <fabian.frank.de_at_gmail.com> wrote:
>>
>> On Jan 27, 2014, at 3:28 AM, Jonathan Masters <jon_at_than.cc> wrote:
>>> That's right, it's the reconnection which takes time, so I want to
>>> reconnect and have the connection setup *before* the next time I need
>>> to make a request. I don't want to only realise the connection is down
>>> at the time the request comes in, which would mean I would have the
>>> delay of connecting and the delay of the request.
>>
>> Instead of poking in the cURL code, it would probably be easier if you made a NOOP request to your server to achieve the same thing? If there is no > connection, curl will reconnect to do the noop. If there still is a connection, you just have a few bytes going back and forth (and you'd probably need > that anyway to be 100% sure the connection is still alive).
>
> It would be easier to do a NOOP but currently I don't want to go down
> that route due to the performance issues this may cause with the
> server I am connecting to, it's embedded with not many resources. As
> the connection is also over TLS it is more than just a few bytes and
> the crypto does strain the server. It would be easier though :(
>
> Thanks though
Right this is what I've done, it seems to work on Windows, I've not
tested it on Linux yet. For this to be able to detect disconnections
quickly I assume TCP keepalive must be on.
- Added function CURLMcode curl_multi_checkdead(CURLM *multi_handle),
I call this at some interval.
- All this does is really call,
Curl_conncache_foreach(multi->conn_cache, multi, &check_connection);
- check_connection() retrieves the socket fd via the connectdata
structure, conn->sock[0];
- Calls ssize_t result = send(fd,0,0,0), if result == -1, assume
disconnected, if so send a message and remove the connection from the
cache.
struct Curl_message *msg
msg = &conn->data->msg;
msg->extmsg.msg = CURLMSG_DONE;
msg->extmsg.easy_handle = conn->data;
msg->extmsg.data.result = CURLE_SEND_ERROR;
returnValue = multi_addmsg(multi, msg);
conn->data = multi->closure_handle;
(void)Curl_disconnect(conn, FALSE);
I've no experience with the libcurl code and this hasn't been tested
thoroughly. If I'm missing something obvious then please let me know.
Thanks.
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-01-28