Prechádzať zdrojové kódy

2010-04-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Implemented clock_gettime() using timeGetTime in mingw.
	* configure.ac
	* src/Makefile.am
	* src/a2time.h
	* src/clock_gettime_mingw.cc
	* src/clock_gettime_mingw.h
	* src/timespec.h
	* test/Makefile.am
Tatsuhiro Tsujikawa 15 rokov pred
rodič
commit
7e22cc38bb
12 zmenil súbory, kde vykonal 237 pridanie a 22 odobranie
  1. 11 0
      ChangeLog
  2. 6 0
      config.h.in
  3. 39 5
      configure
  4. 15 4
      configure.ac
  5. 5 1
      src/Makefile.am
  6. 11 6
      src/Makefile.in
  7. 6 4
      src/a2time.h
  8. 58 0
      src/clock_gettime_mingw.cc
  9. 41 0
      src/clock_gettime_mingw.h
  10. 43 0
      src/timespec.h
  11. 1 1
      test/Makefile.am
  12. 1 1
      test/Makefile.in

+ 11 - 0
ChangeLog

@@ -1,3 +1,14 @@
+2010-04-14  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Implemented clock_gettime() using timeGetTime in mingw.
+	* configure.ac
+	* src/Makefile.am
+	* src/a2time.h
+	* src/clock_gettime_mingw.cc
+	* src/clock_gettime_mingw.h
+	* src/timespec.h
+	* test/Makefile.am
+
 2010-04-14  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Ensure that std::ofstream is destroyed before renaming.

+ 6 - 0
config.h.in

@@ -277,6 +277,9 @@
 /* Define to 1 if you have a working `mmap' system call. */
 #undef HAVE_MMAP
 
+/* Define to 1 if you have the <mmsystem.h> header file. */
+#undef HAVE_MMSYSTEM_H
+
 /* Define to 1 if you have the `munmap' function. */
 #undef HAVE_MUNMAP
 
@@ -500,6 +503,9 @@
 /* Define to 1 if you have the `wcslen' function. */
 #undef HAVE_WCSLEN
 
+/* Define to 1 if you have the <windows.h> header file. */
+#undef HAVE_WINDOWS_H
+
 /* Define to 1 if you have the <winsock2.h> header file. */
 #undef HAVE_WINSOCK2_H
 

+ 39 - 5
configure

@@ -600,6 +600,8 @@ ac_func_list=
 ac_subst_vars='am__EXEEXT_FALSE
 am__EXEEXT_TRUE
 LTLIBOBJS
+HAVE_TIMEGETTIME_FALSE
+HAVE_TIMEGETTIME_TRUE
 HAVE_DAEMON_FALSE
 HAVE_DAEMON_TRUE
 HAVE_TIMEGM_FALSE
@@ -3579,8 +3581,9 @@ ac_config_headers="$ac_config_headers config.h"
 
 case "$target" in
   *mingw*|*cygwin*)
-    WINSOCK_LIBS="-lws2_32 -lpthread"
+    WINSOCK_LIBS="-lws2_32"
 
+    LIBS="-lws2_32 -lcrypto -lwsock32 -lgdi32 -lwinmm $LIBS"
     ;;
 esac
 
@@ -7855,11 +7858,17 @@ fi
 
 case "$target" in
 	*mingw*)
-                for ac_header in winsock2.h \
-                                  ws2tcpip.h
+                for ac_header in windows.h \
+				  winsock2.h \
+                                  ws2tcpip.h \
+				  mmsystem.h
 do :
   as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
-ac_fn_cxx_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
+ac_fn_cxx_check_header_compile "$LINENO" "$ac_header" "$as_ac_Header" "#ifdef HAVE_WINDOWS_H
+# include <windows.h>
+#endif
+
+"
 eval as_val=\$$as_ac_Header
    if test "x$as_val" = x""yes; then :
   cat >>confdefs.h <<_ACEOF
@@ -14623,7 +14632,6 @@ for ac_func in __argz_count \
                 __argz_next \
                 __argz_stringify \
                 atexit \
-		clock_gettime \
                 ftruncate \
                 getcwd \
                 gethostbyaddr \
@@ -14984,6 +14992,18 @@ else
 fi
 
 
+for ac_func in clock_gettime
+do :
+  ac_fn_cxx_check_func "$LINENO" "clock_gettime" "ac_cv_func_clock_gettime"
+if test "x$ac_cv_func_clock_gettime" = x""yes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_CLOCK_GETTIME 1
+_ACEOF
+ have_clock_gettime=yes
+fi
+done
+
+
 case "$target" in
   *mingw*)
          if true; then
@@ -15002,6 +15022,16 @@ else
   HAVE_GAI_STRERROR_FALSE=
 fi
 
+    if test "x$have_clock_gettime" != "xyes"; then
+       if true; then
+  HAVE_TIMEGETTIME_TRUE=
+  HAVE_TIMEGETTIME_FALSE='#'
+else
+  HAVE_TIMEGETTIME_TRUE='#'
+  HAVE_TIMEGETTIME_FALSE=
+fi
+
+    fi
     ;;
 esac
 
@@ -15339,6 +15369,10 @@ if test -z "${HAVE_GAI_STRERROR_TRUE}" && test -z "${HAVE_GAI_STRERROR_FALSE}";
   as_fn_error "conditional \"HAVE_GAI_STRERROR\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${HAVE_TIMEGETTIME_TRUE}" && test -z "${HAVE_TIMEGETTIME_FALSE}"; then
+  as_fn_error "conditional \"HAVE_TIMEGETTIME\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 
 : ${CONFIG_STATUS=./config.status}
 ac_write_fail=0

+ 15 - 4
configure.ac

@@ -12,8 +12,9 @@ AC_CONFIG_HEADERS([config.h])
 
 case "$target" in
   *mingw*|*cygwin*)
-    WINSOCK_LIBS="-lws2_32 -lpthread"
+    WINSOCK_LIBS="-lws2_32"
     AC_SUBST(WINSOCK_LIBS)
+    LIBS="-lws2_32 -lcrypto -lwsock32 -lgdi32 -lwinmm $LIBS"
     ;;
 esac
 
@@ -222,8 +223,14 @@ AC_HEADER_STDC
 
 case "$target" in
 	*mingw*)
-                AC_CHECK_HEADERS([winsock2.h \
-                                  ws2tcpip.h])
+                AC_CHECK_HEADERS([windows.h \
+				  winsock2.h \
+                                  ws2tcpip.h \
+				  mmsystem.h], [], [],
+[[#ifdef HAVE_WINDOWS_H
+# include <windows.h>
+#endif
+]])
 		;;
 esac
 
@@ -299,7 +306,6 @@ AC_CHECK_FUNCS([__argz_count \
                 __argz_next \
                 __argz_stringify \
                 atexit \
-		clock_gettime \
                 ftruncate \
                 getcwd \
                 gethostbyaddr \
@@ -379,12 +385,17 @@ AC_CHECK_FUNCS([timegm],
 AC_CHECK_FUNCS([daemon], [have_daemon=yes])
 AM_CONDITIONAL([HAVE_DAEMON], [test "x$have_daemon" = "xyes"])
 
+AC_CHECK_FUNCS([clock_gettime], [have_clock_gettime=yes])
+
 case "$target" in
   *mingw*)
     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)
+    if test "x$have_clock_gettime" != "xyes"; then
+      AM_CONDITIONAL([HAVE_TIMEGETTIME], true)
+    fi
     ;;
 esac
 

+ 5 - 1
src/Makefile.am

@@ -517,11 +517,15 @@ if !HAVE_DAEMON
 SRCS += daemon.cc daemon.h
 endif # !HAVE_DAEMON
 
+if HAVE_TIMEGETTIME
+SRCS += clock_gettime_mingw.cc clock_gettime_mingw.h
+endif # !HAVE_TIMEGETTIME
+
 noinst_LIBRARIES = libaria2c.a
 libaria2c_a_SOURCES = $(SRCS)
 aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\
 	@LIBGCRYPT_LIBS@ @OPENSSL_LIBS@ @XML_LIBS@\
-	@LIBCARES_LIBS@ @WINSOCK_LIBS@ @LIBEXPAT_LIBS@ @LIBZ_LIBS@\
+	@LIBCARES_LIBS@ @LIBEXPAT_LIBS@ @LIBZ_LIBS@\
 	@SQLITE3_LIBS@ #-lprofiler
 #aria2c_LDFLAGS =  -pg
 AM_CPPFLAGS =  -Wall\

+ 11 - 6
src/Makefile.in

@@ -277,6 +277,7 @@ bin_PROGRAMS = aria2c$(EXEEXT)
 @HAVE_STRPTIME_FALSE@am__append_24 = strptime.c strptime.h
 @HAVE_TIMEGM_FALSE@am__append_25 = timegm.c timegm.h
 @HAVE_DAEMON_FALSE@am__append_26 = daemon.cc daemon.h
+@HAVE_TIMEGETTIME_TRUE@am__append_27 = clock_gettime_mingw.cc clock_gettime_mingw.h
 subdir = src
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in alloca.c
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -602,7 +603,8 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
 	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 \
-	timegm.c timegm.h daemon.cc daemon.h
+	timegm.c timegm.h daemon.cc daemon.h clock_gettime_mingw.cc \
+	clock_gettime_mingw.h
 @ENABLE_XML_RPC_TRUE@am__objects_1 =  \
 @ENABLE_XML_RPC_TRUE@	XmlRpcRequestParserController.$(OBJEXT) \
 @ENABLE_XML_RPC_TRUE@	XmlRpcRequestParserStateMachine.$(OBJEXT) \
@@ -780,7 +782,8 @@ am__objects_6 =
 @HAVE_STRPTIME_FALSE@am__objects_24 = strptime.$(OBJEXT)
 @HAVE_TIMEGM_FALSE@am__objects_25 = timegm.$(OBJEXT)
 @HAVE_DAEMON_FALSE@am__objects_26 = daemon.$(OBJEXT)
-am__objects_27 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
+@HAVE_TIMEGETTIME_TRUE@am__objects_27 = clock_gettime_mingw.$(OBJEXT)
+am__objects_28 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
 	AbstractCommand.$(OBJEXT) \
 	InitiateConnectionCommandFactory.$(OBJEXT) \
 	DownloadCommand.$(OBJEXT) \
@@ -866,8 +869,9 @@ am__objects_27 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
 	$(am__objects_15) $(am__objects_16) $(am__objects_17) \
 	$(am__objects_18) $(am__objects_19) $(am__objects_20) \
 	$(am__objects_21) $(am__objects_22) $(am__objects_23) \
-	$(am__objects_24) $(am__objects_25) $(am__objects_26)
-am_libaria2c_a_OBJECTS = $(am__objects_27)
+	$(am__objects_24) $(am__objects_25) $(am__objects_26) \
+	$(am__objects_27)
+am_libaria2c_a_OBJECTS = $(am__objects_28)
 libaria2c_a_OBJECTS = $(am_libaria2c_a_OBJECTS)
 am__installdirs = "$(DESTDIR)$(bindir)"
 PROGRAMS = $(bin_PROGRAMS)
@@ -1202,12 +1206,12 @@ SRCS = Socket.h SocketCore.cc SocketCore.h BinaryStream.h Command.cc \
 	$(am__append_16) $(am__append_17) $(am__append_18) \
 	$(am__append_19) $(am__append_20) $(am__append_21) \
 	$(am__append_22) $(am__append_23) $(am__append_24) \
-	$(am__append_25) $(am__append_26)
+	$(am__append_25) $(am__append_26) $(am__append_27)
 noinst_LIBRARIES = libaria2c.a
 libaria2c_a_SOURCES = $(SRCS)
 aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\
 	@LIBGCRYPT_LIBS@ @OPENSSL_LIBS@ @XML_LIBS@\
-	@LIBCARES_LIBS@ @WINSOCK_LIBS@ @LIBEXPAT_LIBS@ @LIBZ_LIBS@\
+	@LIBCARES_LIBS@ @LIBEXPAT_LIBS@ @LIBZ_LIBS@\
 	@SQLITE3_LIBS@ #-lprofiler
 
 #aria2c_LDFLAGS =  -pg
@@ -1604,6 +1608,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bencode.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bitfield.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bittorrent_helper.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/clock_gettime_mingw.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/daemon.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/download_helper.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gai_strerror.Po@am__quote@

+ 6 - 4
src/a2time.h

@@ -64,11 +64,13 @@
 #ifndef CLOCK_MONOTONIC
 # define CLOCK_MONOTONIC 0
 #endif // !CLOCK_MONOTONIC
-#ifndef HAVE_STRUCT_TIMESPEC
-struct timespec { time_t tv_sec; long tv_nsec; };
-#endif // !HAVE_STRUCT_TIMESPEC
 #ifndef HAVE_CLOCK_GETTIME
-# define clock_gettime(ID, TP) (-1)
+# ifdef __MINGW32__
+#   include "clock_gettime_mingw.h"
+# else // !__MINGW32__
+#   include "timespec.h"
+#   define clock_gettime(ID, TP) (-1)
+# endif // !__MINGW32__
 #endif // !HAVE_CLOCK_GETTIME
 
 #endif // _D_A2TIME_H_

+ 58 - 0
src/clock_gettime_mingw.cc

@@ -0,0 +1,58 @@
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL.  If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so.  If you
+ * do not wish to do so, delete this exception statement from your
+ * version.  If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#include "clock_gettime_mingw.h"
+
+#include <windows.h>
+#include <mmsystem.h>
+
+int clock_gettime(int dummyid, struct timespec* tp)
+{
+  timeBeginPeriod(1);
+  static DWORD lasttime = timeGetTime();
+  timeEndPeriod(1);
+  static struct timespec monotime = {2678400, 0}; // 1month offset(24*3600*31)
+  timeBeginPeriod(1);
+  DWORD now = timeGetTime();
+  timeEndPeriod(1);
+  DWORD elapsed = now-lasttime;
+  monotime.tv_sec += elapsed/1000;
+  monotime.tv_nsec += elapsed%1000*1000000;
+  if(monotime.tv_nsec >= 1000000000) {
+    monotime.tv_sec += monotime.tv_nsec/1000000000;
+    monotime.tv_nsec %= 1000000000;
+  }
+  lasttime = now;
+  *tp = monotime;
+  return 0;
+}

+ 41 - 0
src/clock_gettime_mingw.h

@@ -0,0 +1,41 @@
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL.  If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so.  If you
+ * do not wish to do so, delete this exception statement from your
+ * version.  If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#ifndef _D_CLOCK_GETTIME_MINGW_H_
+#define _D_CLOCK_GETTIME_MINGW_H_
+
+#include "timespec.h"
+
+int clock_gettime(int dummyid, struct timespec* tp);
+
+#endif // _D_CLOCK_GETTIME_MINGW_H_

+ 43 - 0
src/timespec.h

@@ -0,0 +1,43 @@
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2010 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL.  If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so.  If you
+ * do not wish to do so, delete this exception statement from your
+ * version.  If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#ifndef _D_TIMESPEC_H_
+#define _D_TIMESPEC_H_
+
+#include <time.h>
+
+#ifndef HAVE_STRUCT_TIMESPEC
+struct timespec { time_t tv_sec; long tv_nsec; };
+#endif // !HAVE_STRUCT_TIMESPEC
+
+#endif // _D_TIMESPEC_H_

+ 1 - 1
test/Makefile.am

@@ -213,7 +213,7 @@ endif # ENABLE_METALINK
 aria2c_LDADD = ../src/libaria2c.a\
     @LIBINTL@ @LIBGNUTLS_LIBS@\
 	@LIBGCRYPT_LIBS@ @OPENSSL_LIBS@ @XML_LIBS@\
-	@LIBCARES_LIBS@ @WINSOCK_LIBS@ @LIBEXPAT_LIBS@ @LIBZ_LIBS@\
+	@LIBCARES_LIBS@ @LIBEXPAT_LIBS@ @LIBZ_LIBS@\
 	@SQLITE3_LIBS@\
 	${CPPUNIT_LIBS}
 AM_CPPFLAGS =  -Wall\

+ 1 - 1
test/Makefile.in

@@ -651,7 +651,7 @@ aria2c_SOURCES = AllTest.cc TestUtil.cc TestUtil.h SocketCoreTest.cc \
 aria2c_LDADD = ../src/libaria2c.a\
     @LIBINTL@ @LIBGNUTLS_LIBS@\
 	@LIBGCRYPT_LIBS@ @OPENSSL_LIBS@ @XML_LIBS@\
-	@LIBCARES_LIBS@ @WINSOCK_LIBS@ @LIBEXPAT_LIBS@ @LIBZ_LIBS@\
+	@LIBCARES_LIBS@ @LIBEXPAT_LIBS@ @LIBZ_LIBS@\
 	@SQLITE3_LIBS@\
 	${CPPUNIT_LIBS}