cURL / Mailing Lists / curl-library / Single Mail

curl-library

[PATCH] Keepalive - one step further

From: <autrelandes-curl_at_yahoo.fr>
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/curl.inc.in : 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 2.6.23.1-42.fc8. 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 ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/ISO-IMAGES/6.2/6.2-RELEASE-i386-disc2.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 (http://www.linuxhq.com). - It may work on recent HP-UX 11i v3 according to http://www.docs.hp.com/en/B2355-60130/TCP.7P.html (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 http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.commtechref/doc/commtrf2/setsockopt.htm (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 http://h71000.www7.hp.com/DOC/82final/6529/6529pro_028.html - Solaris seems to use different options according to http://docs.sun.com/app/docs/doc/819-2254/6n4iaov5e?a=view 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 http://lists.freebsd.org/pipermail/freebsd-net/2007-November/016034.html 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 http://msdn2.microsoft.com/en-us/library/ms741621.aspx and http://msdn2.microsoft.com/en-us/library/ms740476.aspx : 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 http://mail.yahoo.fr

Received on 2008-01-02