curl-library
[patch] move src/main/go_sleep to lib/sleep.c & curlx.h
Date: Wed, 14 Jun 2006 05:11:36 -0400
Second try at a series of patches to move rate-limiting into libcurl.
patch #1: move go_sleep to curlx_sleep in lib/sleep.c & curlx.h
Is this OK?
diff -cr curl-7.15.3/lib/Makefile.in curl-7.15.3_sleep/lib/Makefile.in
*** curl-7.15.3/lib/Makefile.in Mon Mar 20 02:48:21 2006
--- curl-7.15.3_sleep/lib/Makefile.in Tue Jun 13 19:53:07 2006
***************
*** 59,65 ****
libLTLIBRARIES_INSTALL = $(INSTALL)
LTLIBRARIES = $(lib_LTLIBRARIES)
libcurl_la_LIBADD =
! am__objects_1 = file.lo timeval.lo base64.lo hostip.lo progress.lo \
formdata.lo cookie.lo http.lo sendf.lo ftp.lo url.lo dict.lo \
if2ip.lo speedcheck.lo ldap.lo ssluse.lo version.lo getenv.lo \
escape.lo mprintf.lo telnet.lo netrc.lo getinfo.lo transfer.lo \
--- 59,65 ----
libLTLIBRARIES_INSTALL = $(INSTALL)
LTLIBRARIES = $(lib_LTLIBRARIES)
libcurl_la_LIBADD =
! am__objects_1 = file.lo timeval.lo sleep.lo base64.lo hostip.lo progress.lo
\
formdata.lo cookie.lo http.lo sendf.lo ftp.lo url.lo dict.lo \
if2ip.lo speedcheck.lo ldap.lo ssluse.lo version.lo getenv.lo \
escape.lo mprintf.lo telnet.lo netrc.lo getinfo.lo transfer.lo \
***************
*** 312,318 ****
# allocatable but non-writable sections" problems.
@MIMPURE_TRUE_at_MIMPURE = -mimpure-text
libcurl_la_LDFLAGS = $(UNDEF) $(VERSION) $(MIMPURE)
! CSOURCES = file.c timeval.c base64.c hostip.c progress.c formdata.c \
cookie.c http.c sendf.c ftp.c url.c dict.c if2ip.c speedcheck.c \
ldap.c ssluse.c version.c getenv.c escape.c mprintf.c telnet.c \
netrc.c getinfo.c transfer.c strequal.c easy.c security.c krb4.c \
--- 312,318 ----
# allocatable but non-writable sections" problems.
@MIMPURE_TRUE_at_MIMPURE = -mimpure-text
libcurl_la_LDFLAGS = $(UNDEF) $(VERSION) $(MIMPURE)
! CSOURCES = file.c sleep.c timeval.c base64.c hostip.c progress.c formdata.c
\
cookie.c http.c sendf.c ftp.c url.c dict.c if2ip.c speedcheck.c \
ldap.c ssluse.c version.c getenv.c escape.c mprintf.c telnet.c \
netrc.c getinfo.c transfer.c strequal.c easy.c security.c krb4.c \
***************
*** 479,484 ****
--- 479,485 ----
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/telnet.Plo_at_am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tftp.Plo_at_am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timeval.Plo_at_am__quote@
+ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sleep.Plo_at_am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/transfer.Plo_at_am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/url.Plo_at_am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/version.Plo_at_am__quote@
diff -cr curl-7.15.3/lib/ca-bundle.h curl-7.15.3_sleep/lib/ca-bundle.h
*** curl-7.15.3/lib/ca-bundle.h Mon Mar 20 02:50:34 2006
--- curl-7.15.3_sleep/lib/ca-bundle.h Tue Jun 13 19:53:47 2006
***************
*** 1 ****
! /* ca bundle path set in here*/
--- 1,2 ----
! /* This file is generated automatically */
! #define CURL_CA_BUNDLE "/usr/local/share/curl/curl-ca-bundle.crt"
diff -cr curl-7.15.3/lib/curlx.h curl-7.15.3_sleep/lib/curlx.h
*** curl-7.15.3/lib/curlx.h Mon May 24 07:57:34 2004
--- curl-7.15.3_sleep/lib/curlx.h Tue Jun 13 19:39:35 2006
***************
*** 61,66 ****
--- 61,67 ----
curlx_strnequal
*/
+ void curlx_sleep(long ms);
#define curlx_getenv curl_getenv
#define curlx_strequal curl_strequal
diff -cr curl-7.15.3/lib/sleep.c curl-7.15.3_sleep/lib/sleep.c
*** curl-7.15.3/lib/sleep.c Wed Jun 14 05:04:32 2006
--- curl-7.15.3_sleep/lib/sleep.c Tue Jun 13 19:54:14 2006
***************
*** 0 ****
--- 1,53 ----
+
+ /***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel_at_haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id: timeval.c,v 1.26 2006/01/09 13:17:14 bagder Exp $
+
***************************************************************************/
+
+ #include "curlx.h"
+
+ void curlx_sleep(long ms)
+ {
+ #ifdef HAVE_POLL_FINE
+ /* portable subsecond "sleep" */
+ poll((void *)0, 0, (int)ms);
+ #else
+ /* systems without poll() need other solutions */
+
+ #ifdef WIN32
+ /* Windows offers a millisecond sleep */
+ Sleep(ms);
+ #elif defined(__MSDOS__)
+ delay(ms);
+ #else
+ /* Other systems must use select() for this */
+ struct timeval timeout;
+
+ timeout.tv_sec = ms/1000;
+ ms = ms%1000;
+ timeout.tv_usec = ms * 1000;
+
+ select(0, NULL, NULL, NULL, &timeout);
+ #endif
+
+ #endif
+ }
+
diff -cr curl-7.15.3/lib/timeval.h curl-7.15.3_sleep/lib/timeval.h
*** curl-7.15.3/lib/timeval.h Mon Jan 9 08:19:26 2006
--- curl-7.15.3_sleep/lib/timeval.h Tue Jun 13 19:38:03 2006
***************
*** 30,35 ****
--- 30,36 ----
#include "setup.h"
+
#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
#include <time.h>
#else
***************
*** 63,68 ****
--- 64,70 ----
*/
double curlx_tvdiff_secs(struct timeval t1, struct timeval t2);
+
long Curl_tvlong(struct timeval t1);
/* These two defines below exist to provide the older API for library
***************
*** 71,74 ****
--- 73,77 ----
#define Curl_tvdiff(x,y) curlx_tvdiff(x,y)
#define Curl_tvdiff_secs(x,y) curlx_tvdiff_secs(x,y)
+
#endif
diff -cr curl-7.15.3/src/main.c curl-7.15.3_sleep/src/main.c
*** curl-7.15.3/src/main.c Mon Mar 13 19:07:21 2006
--- curl-7.15.3_sleep/src/main.c Wed Jun 14 05:07:20 2006
***************
*** 2590,2622 ****
}
}
- static void go_sleep(long ms)
- {
- #ifdef HAVE_POLL_FINE
- /* portable subsecond "sleep" */
- poll((void *)0, 0, (int)ms);
- #else
- /* systems without poll() need other solutions */
-
- #ifdef WIN32
- /* Windows offers a millisecond sleep */
- Sleep(ms);
- #elif defined(__MSDOS__)
- delay(ms);
- #else
- /* Other systems must use select() for this */
- struct timeval timeout;
-
- timeout.tv_sec = ms/1000;
- ms = ms%1000;
- timeout.tv_usec = ms * 1000;
-
- select(0, NULL, NULL, NULL, &timeout);
- #endif
-
- #endif
- }
-
struct OutStruct {
char *filename;
FILE *stream;
--- 2590,2595 ----
***************
*** 2690,2696 ****
sleep_time = MIN(sleep_time,(config->low_speed_time * 1000) / 2);
if(sleep_time > 0) {
! go_sleep(sleep_time);
now = curlx_tvnow();
}
}
--- 2663,2669 ----
sleep_time = MIN(sleep_time,(config->low_speed_time * 1000) / 2);
if(sleep_time > 0) {
! curlx_sleep(sleep_time);
now = curlx_tvnow();
}
}
***************
*** 2783,2789 ****
/* figure out how many milliseconds to rest */
sleep_time = (long)(xfered*1000/config->sendpersecond - timediff);
if(sleep_time > 0) {
! go_sleep (sleep_time);
now = curlx_tvnow();
}
}
--- 2756,2762 ----
/* figure out how many milliseconds to rest */
sleep_time = (long)(xfered*1000/config->sendpersecond - timediff);
if(sleep_time > 0) {
! curlx_sleep (sleep_time);
now = curlx_tvnow();
}
}
***************
*** 4091,4097 ****
retry_sleep/1000,
retry_numretries);
! go_sleep(retry_sleep);
retry_numretries--;
if(!config->retry_delay) {
retry_sleep *= 2;
--- 4064,4070 ----
retry_sleep/1000,
retry_numretries);
! curlx_sleep(retry_sleep);
retry_numretries--;
if(!config->retry_delay) {
retry_sleep *= 2;
Received on 2006-06-14