cURL / Mailing Lists / curl-library / Single Mail


[PATCH] Keepalive - one step further

From: <>
Date: Wed, 2 Jan 2008 15:25:54 +0000 (GMT)

Hello, I have written a patch against current CVS for adding the possibility to change the tcp_keepalive_probes, tcp_keepalive_time and tcp_keepalive_intvl on a per-socket basis in libcurl and in curl (it avoids to have to change kernel parameters for every socket). It introduces new options --tcp-keepcnt <number>, --tcp-keepidle <seconds> and --tcp-keeintvl <seconds>. It should work on OS which have TCP_KEEPCNT, TCP_KEEPIDLE and TCP_INTVL defined on some header (<netinet/tcp.h> for Linux) ; on others OS, it does nothing. I did not yet change src/hugehelp.c, docs/libcurl/curl_easy_setopt.3, docs/curl.1 : I wait to see whether my patch is agreed (and there are also no changes in : a) ares/ares_process.c as I don't know if it's useful to add those functionalities here and (mainly) how to test, b) packages/OS400/ : I don't know how works OS/400). What I find not totally nice in the patch is that the time durations given as parameter are cast with str2num from a char* to an int (and finally to a long) in main.c. On a 32-bit architecture, I presume that maximal int is 2147483647 (it's 68 years... => no problem). On a 16-bit architecture, I presume that the maximal int is 32767 (it's 9 hours => it may be a problem ; one could get a negative time). The patch also adds in connect.c a cast from a long (which was previously casted from an int, with str2num) to a socklen_t. It may not be nice, dunno. What do you think of the patch ? It works on Fedora Linux Here is a test (you will find enclosed with the mail the associated tcpdump and curl output) : ~/_EXE_cURL/bin/curl --verbose --limit-rate 4K --tcp-keepidle 10 --tcp-keepintvl 20 --tcp-keepcnt 2 -o /tmp/freebsd.iso You can see in the tcpdump that the first TCP keep-alive packet is sent 10 seconds after initiating the connection, the following ones are sent each 20 seconds, and after having unplugged my DSL modem, the connection is dropped after two keep alive trials. From my search on Internet : - Those TCP parameters appeared in the Linux kernel since the 2.3.18 release ( - It may work on recent HP-UX 11i v3 according to (unfortunately, the only HP-UX at my disposal - HP-UX 11iv1 - does not define those parameters). - It may work on AIX 5.3 according to (unfortunately, the only AIX at my disposal - AIX 5.1 - does not define those parameters ; bad luck). - Those parameters are defined on OpenVMS according to - Solaris seems to use different options according to so it should not work on this OS. I don't know if such functionality is possible on OS/400. A friend of mine said it won't work on BSD (and so on Mac OS/X, I presume). On my FreeBSD 6.2 box, the netinet/tcp.h does not indeed define the keepalive variables. A patch has been recently submitted on FreeBSD but it does not seem to be yet very popular. The patch does nothing on Windows because Microsoft uses a different approach, as told on and : one should use the WSAIoctl function (i.e. neither setsockopt, nor ioctlsocket which are used in curl) for modifying the so-called SIO_KEEPALIVE_VALS parameter. This parameter is "supported on Windows 2000 and later". It is available either by including the mstcpip.h header (available from the MS SDK), or by redefining the appropriate parameters (that's what I did on a simple program compiled with mingw or cygwin, for sake of test). But implementing those functionalities in cURL for Windows seems to be too complicate (at least for me and for the time being), and I don't use cURL on Windows... _____________________________________________________________________________ Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail

Received on 2008-01-02