2007-08-10 Ross Smith II <aria2spam at smithii dot com>

Move sleep functions to Util class:
	* src/Util.cc
	(sleep): New function.
	(usleep): New function.
	* src/DownloadCommand.cc: sleep -> Util::sleep
	* test/TimeSeedCriteriaTest.cc: sleep -> Util::sleep

	MinGW build enhancements. The following files are added:
	* src/timegm.{c,h}

	Changes to support the above new files:
	* configure.ac
	* src/Makefile.am
	* src/a2time.h
	* src/Util.cc:
	* src/strptime.c: Added support for %Z option.

	Miscellenous build fixes/enhancements.
	* configure.ac: Added summary report.
	* src/Platform.h: Tweaked #include's.
	* src/a2netcompat.h: Tweaked #include's.
	* src/strptime.h: Tweaked #include's.
	* src/gai_strerror.c: Tweaked #include's.
	* src/gai_strerror.h: _D_GETADDRINFO_H -> _D_GAI_STRERROR_H
	* src/getaddrinfo.h: Moved #ifndef __MINGW32__
	* src/gettimeofday.h: Added HAVE_CONFIG_H
This commit is contained in:
Tatsuhiro Tsujikawa 2007-08-14 14:51:08 +00:00
parent c14c80276a
commit 6aa98f9b9f
24 changed files with 425 additions and 77 deletions

View File

@ -1,3 +1,32 @@
2007-08-10 Ross Smith II <aria2spam at smithii dot com>
Move sleep functions to Util class:
* src/Util.cc
(sleep): New function.
(usleep): New function.
* src/DownloadCommand.cc: sleep -> Util::sleep
* test/TimeSeedCriteriaTest.cc: sleep -> Util::sleep
MinGW build enhancements. The following files are added:
* src/timegm.{c,h}
Changes to support the above new files:
* configure.ac
* src/Makefile.am
* src/a2time.h
* src/Util.cc:
* src/strptime.c: Added support for %Z option.
Miscellenous build fixes/enhancements.
* configure.ac: Added summary report.
* src/Platform.h: Tweaked #include's.
* src/a2netcompat.h: Tweaked #include's.
* src/strptime.h: Tweaked #include's.
* src/gai_strerror.c: Tweaked #include's.
* src/gai_strerror.h: _D_GETADDRINFO_H -> _D_GAI_STRERROR_H
* src/getaddrinfo.h: Moved #ifndef __MINGW32__
* src/gettimeofday.h: Added HAVE_CONFIG_H
2007-08-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Increased the initial connection size in BitTorrent download to 40.

View File

@ -142,6 +142,8 @@ HAVE_LOCALTIME_R_FALSE = @HAVE_LOCALTIME_R_FALSE@
HAVE_LOCALTIME_R_TRUE = @HAVE_LOCALTIME_R_TRUE@
HAVE_STRPTIME_FALSE = @HAVE_STRPTIME_FALSE@
HAVE_STRPTIME_TRUE = @HAVE_STRPTIME_TRUE@
HAVE_TIMEGM_FALSE = @HAVE_TIMEGM_FALSE@
HAVE_TIMEGM_TRUE = @HAVE_TIMEGM_TRUE@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@

View File

@ -334,6 +334,9 @@
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if you have the `unsetenv' function. */
#undef HAVE_UNSETENV
/* Define if you have the unsigned long long type. */
#undef HAVE_UNSIGNED_LONG_LONG

169
configure vendored
View File

@ -778,6 +778,8 @@ HAVE_LOCALTIME_R_TRUE
HAVE_LOCALTIME_R_FALSE
HAVE_STRPTIME_TRUE
HAVE_STRPTIME_FALSE
HAVE_TIMEGM_TRUE
HAVE_TIMEGM_FALSE
LTLIBOBJS'
ac_subst_files=''
ac_precious_vars='build_alias
@ -12693,7 +12695,7 @@ done
for ac_func in __argz_count __argz_next __argz_stringify daemon ftruncate getcwd getpagesize inet_ntoa memchr mempcpy memset mkdir munmap nl_langinfo random rmdir select setlocale setmode sigaction sleep socket srandom stpcpy strcasecmp strchr strcspn strdup strerror strstr strtol strtoul timegm usleep
for ac_func in __argz_count __argz_next __argz_stringify daemon ftruncate getcwd getpagesize inet_ntoa memchr mempcpy memset mkdir munmap nl_langinfo random rmdir select setlocale setmode sigaction sleep socket srandom stpcpy strcasecmp strchr strcspn strdup strerror strstr strtol strtoul unsetenv usleep
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
{ echo "$as_me:$LINENO: checking for $ac_func" >&5
@ -13586,6 +13588,120 @@ fi
done
for ac_func in timegm
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
{ echo "$as_me:$LINENO: checking for $ac_func" >&5
echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6; }
if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
For example, HP-UX 11i <limits.h> declares gettimeofday. */
#define $ac_func innocuous_$ac_func
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func (); below.
Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
<limits.h> exists even on freestanding compilers. */
#ifdef __STDC__
# include <limits.h>
#else
# include <assert.h>
#endif
#undef $ac_func
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char $ac_func ();
/* The GNU C library defines this for functions which it implements
to always fail with ENOSYS. Some functions are actually named
something starting with __ and the normal name is an alias. */
#if defined __stub_$ac_func || defined __stub___$ac_func
choke me
#endif
int
main ()
{
return $ac_func ();
;
return 0;
}
_ACEOF
rm -f conftest.$ac_objext conftest$ac_exeext
if { (ac_try="$ac_link"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
(eval "$ac_link") 2>conftest.er1
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } && {
test -z "$ac_c_werror_flag" ||
test ! -s conftest.err
} && test -s conftest$ac_exeext &&
$as_test_x conftest$ac_exeext; then
eval "$as_ac_var=yes"
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
eval "$as_ac_var=no"
fi
rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
conftest$ac_exeext conftest.$ac_ext
fi
ac_res=`eval echo '${'$as_ac_var'}'`
{ echo "$as_me:$LINENO: result: $ac_res" >&5
echo "${ECHO_T}$ac_res" >&6; }
if test `eval echo '${'$as_ac_var'}'` = yes; then
cat >>confdefs.h <<_ACEOF
#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF
if true; then
HAVE_TIMEGM_TRUE=
HAVE_TIMEGM_FALSE='#'
else
HAVE_TIMEGM_TRUE='#'
HAVE_TIMEGM_FALSE=
fi
else
if false; then
HAVE_TIMEGM_TRUE=
HAVE_TIMEGM_FALSE='#'
else
HAVE_TIMEGM_TRUE='#'
HAVE_TIMEGM_FALSE=
fi
fi
done
case "$target" in
*mingw*)
@ -13598,6 +13714,16 @@ else
HAVE_GETADDRINFO_FALSE=
fi
if false; then
HAVE_GAI_STRERROR_TRUE=
HAVE_GAI_STRERROR_FALSE='#'
else
HAVE_GAI_STRERROR_TRUE='#'
HAVE_GAI_STRERROR_FALSE=
fi
;;
esac
@ -13874,6 +14000,20 @@ echo "$as_me: error: conditional \"HAVE_STRPTIME\" was never defined.
Usually this means the macro was only invoked conditionally." >&2;}
{ (exit 1); exit 1; }; }
fi
if test -z "${HAVE_TIMEGM_TRUE}" && test -z "${HAVE_TIMEGM_FALSE}"; then
{ { echo "$as_me:$LINENO: error: conditional \"HAVE_TIMEGM\" was never defined.
Usually this means the macro was only invoked conditionally." >&5
echo "$as_me: error: conditional \"HAVE_TIMEGM\" was never defined.
Usually this means the macro was only invoked conditionally." >&2;}
{ (exit 1); exit 1; }; }
fi
if test -z "${HAVE_TIMEGM_TRUE}" && test -z "${HAVE_TIMEGM_FALSE}"; then
{ { echo "$as_me:$LINENO: error: conditional \"HAVE_TIMEGM\" was never defined.
Usually this means the macro was only invoked conditionally." >&5
echo "$as_me: error: conditional \"HAVE_TIMEGM\" was never defined.
Usually this means the macro was only invoked conditionally." >&2;}
{ (exit 1); exit 1; }; }
fi
if test -z "${HAVE_GETADDRINFO_TRUE}" && test -z "${HAVE_GETADDRINFO_FALSE}"; then
{ { echo "$as_me:$LINENO: error: conditional \"HAVE_GETADDRINFO\" was never defined.
Usually this means the macro was only invoked conditionally." >&5
@ -13881,6 +14021,13 @@ echo "$as_me: error: conditional \"HAVE_GETADDRINFO\" was never defined.
Usually this means the macro was only invoked conditionally." >&2;}
{ (exit 1); exit 1; }; }
fi
if test -z "${HAVE_GAI_STRERROR_TRUE}" && test -z "${HAVE_GAI_STRERROR_FALSE}"; then
{ { echo "$as_me:$LINENO: error: conditional \"HAVE_GAI_STRERROR\" was never defined.
Usually this means the macro was only invoked conditionally." >&5
echo "$as_me: error: conditional \"HAVE_GAI_STRERROR\" was never defined.
Usually this means the macro was only invoked conditionally." >&2;}
{ (exit 1); exit 1; }; }
fi
: ${CONFIG_STATUS=./config.status}
ac_clean_files_save=$ac_clean_files
@ -14630,10 +14777,12 @@ HAVE_LOCALTIME_R_TRUE!$HAVE_LOCALTIME_R_TRUE$ac_delim
HAVE_LOCALTIME_R_FALSE!$HAVE_LOCALTIME_R_FALSE$ac_delim
HAVE_STRPTIME_TRUE!$HAVE_STRPTIME_TRUE$ac_delim
HAVE_STRPTIME_FALSE!$HAVE_STRPTIME_FALSE$ac_delim
HAVE_TIMEGM_TRUE!$HAVE_TIMEGM_TRUE$ac_delim
HAVE_TIMEGM_FALSE!$HAVE_TIMEGM_FALSE$ac_delim
LTLIBOBJS!$LTLIBOBJS$ac_delim
_ACEOF
if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 67; then
if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 69; then
break
elif $ac_last_try; then
{ { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
@ -15325,3 +15474,19 @@ if test "$no_create" != yes; then
$ac_cs_success || { (exit 1); exit 1; }
fi
echo " "
echo "Build: $build"
echo "Target: $target"
echo "Install prefix: $prefix"
echo "CFLAGS: $CFLAGS"
echo "CPPFLAGS: $CPPFLAGS"
echo "LDFLAGS: $LDFLAGS"
echo "LIBS: $LIBS"
echo "GnuTLS: $have_libgnutls"
echo "OpenSSL: $have_openssl"
echo "LibXML2: $have_libxml2"
echo "LibAres: $have_libares"
echo "LibCares: $have_libcares"
echo "Bittorrent: $enable_bittorrent"
echo "Metalink: $enable_metalink"

View File

@ -141,7 +141,7 @@ AC_FUNC_MMAP
AC_FUNC_SELECT_ARGTYPES
AC_FUNC_STAT
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([__argz_count __argz_next __argz_stringify daemon ftruncate getcwd getpagesize inet_ntoa memchr mempcpy memset mkdir munmap nl_langinfo random rmdir select setlocale setmode sigaction sleep socket srandom stpcpy strcasecmp strchr strcspn strdup strerror strstr strtol strtoul timegm usleep])
AC_CHECK_FUNCS([__argz_count __argz_next __argz_stringify daemon ftruncate getcwd getpagesize inet_ntoa memchr mempcpy memset mkdir munmap nl_langinfo random rmdir select setlocale setmode sigaction sleep socket srandom stpcpy strcasecmp strchr strcspn strdup strerror strstr strtol strtoul unsetenv usleep])
AC_CHECK_FUNCS([basename],
[AM_CONDITIONAL([HAVE_BASENAME], true)],
@ -164,11 +164,16 @@ AC_CHECK_FUNCS([localtime_r],
AC_CHECK_FUNCS([strptime],
[AM_CONDITIONAL([HAVE_STRPTIME], true)],
[AM_CONDITIONAL([HAVE_STRPTIME], false)])
AC_CHECK_FUNCS([timegm],
[AM_CONDITIONAL([HAVE_TIMEGM], true)],
[AM_CONDITIONAL([HAVE_TIMEGM], false)])
case "$target" in
*mingw*)
dnl true if _WIN32_WINNT >= 0x0501
dnl defined in ws2tcpip.h, but only if _WIN32_WINNT >= 0x0501
AM_CONDITIONAL([HAVE_GETADDRINFO], true)
dnl defined in ws2tcpip.h, but missing in C:\mingw\lib\libws2_32.a
AM_CONDITIONAL([HAVE_GAI_STRERROR], false)
;;
esac
@ -180,3 +185,19 @@ AC_CONFIG_FILES([Makefile
intl/Makefile
doc/Makefile])
AC_OUTPUT
echo " "
echo "Build: $build"
echo "Target: $target"
echo "Install prefix: $prefix"
echo "CFLAGS: $CFLAGS"
echo "CPPFLAGS: $CPPFLAGS"
echo "LDFLAGS: $LDFLAGS"
echo "LIBS: $LIBS"
echo "GnuTLS: $have_libgnutls"
echo "OpenSSL: $have_openssl"
echo "LibXML2: $have_libxml2"
echo "LibAres: $have_libares"
echo "LibCares: $have_libcares"
echo "Bittorrent: $enable_bittorrent"
echo "Metalink: $enable_metalink"

View File

@ -120,6 +120,8 @@ HAVE_LOCALTIME_R_FALSE = @HAVE_LOCALTIME_R_FALSE@
HAVE_LOCALTIME_R_TRUE = @HAVE_LOCALTIME_R_TRUE@
HAVE_STRPTIME_FALSE = @HAVE_STRPTIME_FALSE@
HAVE_STRPTIME_TRUE = @HAVE_STRPTIME_TRUE@
HAVE_TIMEGM_FALSE = @HAVE_TIMEGM_FALSE@
HAVE_TIMEGM_TRUE = @HAVE_TIMEGM_TRUE@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@

View File

@ -116,6 +116,8 @@ HAVE_LOCALTIME_R_FALSE = @HAVE_LOCALTIME_R_FALSE@
HAVE_LOCALTIME_R_TRUE = @HAVE_LOCALTIME_R_TRUE@
HAVE_STRPTIME_FALSE = @HAVE_STRPTIME_FALSE@
HAVE_STRPTIME_TRUE = @HAVE_STRPTIME_TRUE@
HAVE_TIMEGM_FALSE = @HAVE_TIMEGM_FALSE@
HAVE_TIMEGM_TRUE = @HAVE_TIMEGM_TRUE@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@

View File

@ -71,11 +71,7 @@ bool DownloadCommand::executeInternal() {
// TODO we need to specify the sum of all segmentMan's download speed here.
if(maxDownloadSpeedLimit > 0 &&
maxDownloadSpeedLimit < _requestGroup->getSegmentMan()->calculateDownloadSpeed()) {
#ifdef HAVE_USLEEP
usleep(1);
#else
_sleep(1);
#endif // HAVE_USLEEP
Util::usleep(1);
e->commands.push_back(this);
return false;
}

View File

@ -260,6 +260,10 @@ if !HAVE_STRPTIME
SRCS += strptime.c strptime.h
endif # !HAVE_STRPTIME
if !HAVE_TIMEGM
SRCS += timegm.c timegm.h
endif # !HAVE_TIMEGM
noinst_LIBRARIES = libaria2c.a
libaria2c_a_SOURCES = $(SRCS)
aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\

View File

@ -169,6 +169,7 @@ bin_PROGRAMS = aria2c$(EXEEXT)
@HAVE_INET_ATON_FALSE@am__append_8 = inet_aton.c inet_aton.h
@HAVE_LOCALTIME_R_FALSE@am__append_9 = localtime_r.c localtime_r.h
@HAVE_STRPTIME_FALSE@am__append_10 = strptime.c strptime.h
@HAVE_TIMEGM_FALSE@am__append_11 = timegm.c timegm.h
subdir = src
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in alloca.c
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@ -334,7 +335,8 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
MetalinkRequestInfo.cc MetalinkRequestInfo.h libgen.c libgen.h \
getaddrinfo.c getaddrinfo.h gai_strerror.c gai_strerror.h \
gettimeofday.c gettimeofday.h inet_aton.c inet_aton.h \
localtime_r.c localtime_r.h strptime.c strptime.h
localtime_r.c localtime_r.h strptime.c strptime.h timegm.c \
timegm.h
@ENABLE_MESSAGE_DIGEST_TRUE@am__objects_1 = \
@ENABLE_MESSAGE_DIGEST_TRUE@ ChunkChecksumValidator.$(OBJEXT) \
@ENABLE_MESSAGE_DIGEST_TRUE@ IteratableChunkChecksumValidator.$(OBJEXT) \
@ -421,7 +423,8 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
@HAVE_INET_ATON_FALSE@am__objects_8 = inet_aton.$(OBJEXT)
@HAVE_LOCALTIME_R_FALSE@am__objects_9 = localtime_r.$(OBJEXT)
@HAVE_STRPTIME_FALSE@am__objects_10 = strptime.$(OBJEXT)
am__objects_11 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
@HAVE_TIMEGM_FALSE@am__objects_11 = timegm.$(OBJEXT)
am__objects_12 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
AbstractCommand.$(OBJEXT) \
InitiateConnectionCommandFactory.$(OBJEXT) \
DownloadCommand.$(OBJEXT) \
@ -464,8 +467,9 @@ am__objects_11 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
FileEntry.$(OBJEXT) Platform.$(OBJEXT) $(am__objects_1) \
$(am__objects_2) $(am__objects_3) $(am__objects_4) \
$(am__objects_5) $(am__objects_6) $(am__objects_7) \
$(am__objects_8) $(am__objects_9) $(am__objects_10)
am_libaria2c_a_OBJECTS = $(am__objects_11)
$(am__objects_8) $(am__objects_9) $(am__objects_10) \
$(am__objects_11)
am_libaria2c_a_OBJECTS = $(am__objects_12)
libaria2c_a_OBJECTS = $(am_libaria2c_a_OBJECTS)
am__installdirs = "$(DESTDIR)$(bindir)"
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
@ -547,6 +551,8 @@ HAVE_LOCALTIME_R_FALSE = @HAVE_LOCALTIME_R_FALSE@
HAVE_LOCALTIME_R_TRUE = @HAVE_LOCALTIME_R_TRUE@
HAVE_STRPTIME_FALSE = @HAVE_STRPTIME_FALSE@
HAVE_STRPTIME_TRUE = @HAVE_STRPTIME_TRUE@
HAVE_TIMEGM_FALSE = @HAVE_TIMEGM_FALSE@
HAVE_TIMEGM_TRUE = @HAVE_TIMEGM_TRUE@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
@ -718,7 +724,7 @@ SRCS = Socket.h SocketCore.cc SocketCore.h Command.cc Command.h \
Platform.h $(am__append_1) $(am__append_2) $(am__append_3) \
$(am__append_4) $(am__append_5) $(am__append_6) \
$(am__append_7) $(am__append_8) $(am__append_9) \
$(am__append_10)
$(am__append_10) $(am__append_11)
noinst_LIBRARIES = libaria2c.a
libaria2c_a_SOURCES = $(SRCS)
aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\
@ -968,6 +974,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/messageDigest.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/strptime.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/timegm.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \

View File

@ -38,8 +38,16 @@
#ifdef HAVE_WINSOCK2_H
#ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x501
#endif // _WIN32_WINNT
#include <winsock2.h>
#undef ERROR
#ifdef HAVE_WS2TCPIP_H
# include <ws2tcpip.h>
#endif // HAVE_WS2TCPIP_H
#include "common.h"
#include "a2netcompat.h"
#include "DlAbortEx.h"
#include "Platform.h"

View File

@ -38,6 +38,7 @@
#include "message.h"
#include "SimpleRandomizer.h"
#include "a2netcompat.h"
#include "a2time.h"
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
@ -45,6 +46,13 @@
#include <signal.h>
#include <iomanip>
#ifndef HAVE_SLEEP
# ifdef HAVE_WINSOCK_H
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# endif // HAVE_WINSOCK_H
#endif // HAVE_SLEEP
template<typename T>
string uint2str(T value, bool comma) {
string str;
@ -625,23 +633,8 @@ time_t Util::httpGMT(const string& httpStdTime)
struct tm tm;
memset(&tm, 0, sizeof(tm));
strptime(httpStdTime.c_str(), "%a, %Y-%m-%d %H:%M:%S GMT", &tm);
#ifdef HAVE_TIMEGM
time_t thetime = timegm(&tm);
return thetime;
#else
char *tz;
tz = getenv("TZ");
putenv("TZ=");
tzset();
time_t thetime = mktime(&tm);
if (tz) {
char s[256];
snprintf(s, sizeof(s), "TZ=%s", tz);
putenv(s);
}
tzset();
return thetime;
#endif // HAVE_TIMEGM
}
void Util::toStream(ostream& os, const FileEntries& fileEntries)
@ -657,3 +650,50 @@ void Util::toStream(ostream& os, const FileEntries& fileEntries)
os << "---+---------------------------------------------------------------------------" << "\n";
}
}
void Util::sleep(long seconds) {
#ifdef HAVE_SLEEP
::sleep(seconds);
#elif defined(HAVE_USLEEP)
::usleep(seconds * 1000000);
#elif defined(HAVE_WINSOCK2_H)
::Sleep(seconds * 1000);
#else
#error no sleep function is available (nanosleep?)
#endif
}
void Util::usleep(long microseconds) {
#ifdef HAVE_USLEEP
::usleep(microseconds);
#elif defined(HAVE_WINSOCK2_H)
LARGE_INTEGER current, freq, end;
static enum {GET_FREQUENCY, GET_MICROSECONDS, SKIP_MICROSECONDS} state = GET_FREQUENCY;
if (state == GET_FREQUENCY) {
if (QueryPerformanceFrequency(&freq))
state = GET_MICROSECONDS;
else
state = SKIP_MICROSECONDS;
}
long msec = microseconds / 1000;
microseconds %= 1000;
if (state == GET_MICROSECONDS && microseconds) {
QueryPerformanceCounter(&end);
end.QuadPart += (freq.QuadPart * microseconds) / 1000000;
while (QueryPerformanceCounter(&current) && (current.QuadPart <= end.QuadPart))
/* noop */ ;
}
if (msec)
Sleep(msec);
#else
#error no usleep function is available (nanosleep?)
#endif
}

View File

@ -131,6 +131,10 @@ public:
static time_t httpGMT(const string& httpTimeFormat);
static void toStream(ostream& os, const FileEntries& entries);
static void sleep(long seconds);
static void usleep(long microseconds);
};
#endif // _D_UTIL_H_

View File

@ -36,6 +36,28 @@
#include "a2io.h"
#ifndef __CYGWIN__
# ifdef HAVE_WINSOCK2_H
# ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x501
# endif // _WIN32_WINNT
# include <winsock2.h>
# undef ERROR
# endif // HAVE_WINSOCK2_H
# ifdef HAVE_WS2TCPIP_H
# include <ws2tcpip.h>
# endif // HAVE_WS2TCPIP_H
#endif // !__CYGWIN__
#ifdef __MINGW32__
# define SOCKOPT_T const char
# define HAVE_GETADDRINFO
# undef HAVE_GAI_STRERROR
# undef gai_strerror
#else
# define SOCKOPT_T socklen_t
#endif // __MINGW32__
#ifdef HAVE_NETDB_H
# include <netdb.h>
#endif // HAVE_NETDB_H
@ -60,33 +82,13 @@
# include "inet_aton.h"
#endif // HAVE_INET_ATON
#ifdef HAVE_WINSOCK2_H
#ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x501
#endif // _WIN32_WINNT
# include <winsock2.h>
# undef ERROR
#endif // HAVE_WINSOCK2_H
#ifdef HAVE_WS2TCPIP_H
# include <ws2tcpip.h>
#endif // HAVE_WS2TCPIP_H
#ifdef __MINGW32__
# define SOCKOPT_T const char
# undef HAVE_GETADDRINFO
# undef HAVE_GAI_STRERROR
# undef gai_strerror
#else
# define SOCKOPT_T socklen_t
#endif // __MINGW32__
#ifndef HAVE_GETADDRINFO
# include "getaddrinfo.h"
# define HAVE_GAI_STRERROR
#endif // HAVE_GETADDRINFO
#ifndef HAVE_GAI_STRERROR
# include "gai_strerror.h"
#endif // HAVE_GAI_STRERROR
#ifndef HAVE_GETADDRINFO
# include "getaddrinfo.h"
#endif // HAVE_GETADDRINFO
#endif // _D_A2NETCOMPAT_H_

View File

@ -49,4 +49,8 @@
# include "strptime.h"
#endif // HAVE_STRPTIME
#ifndef HAVE_TIMEGM
# include "timegm.h"
#endif // HAVE_TIMEGM
#endif // _D_A2TIME_H_

View File

@ -26,16 +26,12 @@
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gai_strerror.h"
#ifdef ENABLE_NLS
#include <libintl.h>
#endif
#include "gai_strerror.h"
#ifdef ENABLE_NLS
#define _(string) gettext(string)
#ifdef gettext_noop

View File

@ -26,8 +26,8 @@
* SUCH DAMAGE.
*/
#ifndef _D_GETADDRINFO_H
#define _D_GETADDRINFO_H
#ifndef _D_GAI_STRERROR_H
#define _D_GAI_STRERROR_H
#ifdef __cplusplus
extern "C" {
@ -131,7 +131,7 @@ extern "C" {
* Fake struct and function names.
* <netdb.h> might declares all or some of them.
*/
#if defined(HAVE_GETADDRINFO) || defined(HAVE_GETNAMEINFO) || defined(HAVE_GAI_STRERROR)
#if defined(HAVE_GAI_STRERROR)
#define gai_strerror my_gai_strerror
#endif
@ -164,4 +164,4 @@ const char *gai_strerror();
};
#endif /* __cplusplus */
#endif /* not _D_GETADDRINFO_H */
#endif /* not _D_GAI_STRERROR_H */

View File

@ -211,6 +211,8 @@ extern "C" {
#define PF_UNSPEC PF_INET
#endif
#ifndef __MINGW32__
/*
* struct addrinfo.
*/
@ -225,6 +227,8 @@ struct addrinfo {
struct addrinfo *ai_next;
};
#endif // __MINGW32__
/*
* Functions.
*/

View File

@ -36,6 +36,10 @@
#ifndef _D_GETTIMEOFDAY_H
#define _D_GETTIMEOFDAY_H 1
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif // HAVE_CONFIG_H
#include <sys/time.h>
#ifdef __cplusplus

View File

@ -35,6 +35,7 @@
#include <time.h>
#include <stdlib.h>
#ifdef __MINGW32__
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
@ -51,12 +52,9 @@ static void localtime_r_atexit()
DeleteCriticalSection(&localtime_r_cs);
}
#endif // __MINGW32__
struct tm * localtime_r(const time_t *clock, struct tm *result)
{
static struct tm *local_tm;
#ifdef __MINGW32__
static int initialized = 0;
if (!initialized) {
@ -69,7 +67,7 @@ struct tm * localtime_r(const time_t *clock, struct tm *result)
local_tm = localtime(clock);
memcpy(result, local_tm, sizeof(struct tm));
LeaveCriticalSection(&localtime_r_cs);
#endif // __MINGW32__
return result;
};
#endif // __MINGW32__

View File

@ -30,6 +30,18 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
#ifndef HAVE_CONFIG_H
# include "config.h"
#endif // HAVE_CONFIG_H
#ifndef HAVE_LOCALTIME_R
# include "localtime_r.h"
#endif // HAVE_LOCALTIME_R
#ifndef HAVE_TIMEGM
# include "timegm.h"
#endif // HAVE_TIMEGM
#include <stddef.h>
#include <stdio.h>
#include <time.h>
@ -37,6 +49,14 @@
#include <ctype.h>
#include <stdlib.h>
#ifdef HAVE_ALLOCA_H
# include <alloca.h>
#endif // HAVE_ALLOCA_H
#ifdef HAVE_MALLOC_H
# include <malloc.h>
#endif // HAVE_MALLOC_H
#include "strptime.h"
static const char *abb_weekdays[] = {
@ -198,8 +218,8 @@ set_week_number_mon4 (struct tm *timeptr, int wnum)
/* strptime: roken */
//extern "C"
char *
strptime (const char *buf, const char *format, struct tm *timeptr)
static char *
_strptime (const char *buf, const char *format, struct tm *timeptr, int *gmt)
{
char c;
@ -414,7 +434,29 @@ strptime (const char *buf, const char *format, struct tm *timeptr)
buf = s;
break;
case 'Z' :
/* Unsupported. Just ignore. */
/* source: cygwin-1.5.24-2-src/cygwin-1.5.24-2/winsup/cygwin/libc/strptime.cc */
{
const char *cp;
char *zonestr;
for (cp = buf; *cp && isupper((unsigned char)*cp); ++cp) {/*empty*/}
if (cp - buf) {
zonestr = (char *) alloca(cp - buf + 1);
strncpy(zonestr, buf, cp - buf);
zonestr[cp - buf] = '\0';
tzset();
if (0 == strcmp(zonestr, "GMT")) {
*gmt = 1;
} else if (0 == strcmp(zonestr, tzname[0])) {
timeptr->tm_isdst = 0;
} else if (0 == strcmp(zonestr, tzname[1])) {
timeptr->tm_isdst = 1;
} else {
return 0;
}
buf += cp - buf;
}
}
break;
case '\0' :
--format;
@ -441,3 +483,19 @@ strptime (const char *buf, const char *format, struct tm *timeptr)
}
return (char *)buf;
}
char *
strptime (const char *buf, const char *format, struct tm *timeptr)
{
char *ret;
int gmt;
gmt = 0;
ret = _strptime(buf, format, timeptr, &gmt);
if (ret && gmt) {
time_t t = timegm(timeptr);
localtime_r(&t, timeptr);
}
return (ret);
}

View File

@ -36,12 +36,12 @@
#ifndef _D_STRPTIME_H
#define _D_STRPTIME_H
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <time.h>
char * strptime (const char *buf, const char *format, struct tm *timeptr);
#ifdef __cplusplus

View File

@ -288,6 +288,8 @@ HAVE_LOCALTIME_R_FALSE = @HAVE_LOCALTIME_R_FALSE@
HAVE_LOCALTIME_R_TRUE = @HAVE_LOCALTIME_R_TRUE@
HAVE_STRPTIME_FALSE = @HAVE_STRPTIME_FALSE@
HAVE_STRPTIME_TRUE = @HAVE_STRPTIME_TRUE@
HAVE_TIMEGM_FALSE = @HAVE_TIMEGM_FALSE@
HAVE_TIMEGM_TRUE = @HAVE_TIMEGM_TRUE@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@

View File

@ -1,4 +1,5 @@
#include "TimeSeedCriteria.h"
#include "Util.h"
#include <cppunit/extensions/HelperMacros.h>
#include <stdlib.h>
@ -18,11 +19,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(TimeSeedCriteriaTest);
void TimeSeedCriteriaTest::testEvaluate() {
TimeSeedCriteria cri(1);
#ifdef HAVE_SLEEP
sleep(1);
#else
_sleep(1);
#endif
Util::sleep(1);
CPPUNIT_ASSERT(cri.evaluate());
cri.reset();
cri.setDuration(10);