summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-06-16 11:59:34 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2008-06-16 11:59:34 +0000
commitaaa2ecaa6fd16fa6a03e1c9051b0a481e8d4f20a (patch)
tree230b5f6a71d1e4d09c22d70ae6b314cd8a5723cc
parent06644332c2cc5b229ef41857ceed73f7caf2775f (diff)
2008-06-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Applied Ross's aria2-0.13.2+1-mingw-4.patch. In this commit, only the follow sources are applied. * src/Platform.h: I removed HAVE_WINSOCK2_H directive from Platform.h. * src/Platform.cc: Moved common setup/teardown code to Platform class. I moved #endif // HAVE_WINSOCK2_H to the front of #include "DlAbortEx.h" I included locale.h from Platform.cc. * src/main.cc: Moved common setup/teardown code to Platform class. * test/AllTest.cc: Use Platform class. Set locale to C in AllTest.cc to prevent the messages to be localized.
-rw-r--r--ChangeLog12
-rw-r--r--src/Platform.cc80
-rw-r--r--src/Platform.h13
-rw-r--r--src/main.cc31
-rw-r--r--test/AllTest.cc29
5 files changed, 105 insertions, 60 deletions
diff --git a/ChangeLog b/ChangeLog
index 546917c7..541c0cab 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2008-06-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
+ Applied Ross's aria2-0.13.2+1-mingw-4.patch. In this commit, only the
+ follow sources are applied.
+ * src/Platform.h: I removed HAVE_WINSOCK2_H directive from Platform.h.
+ * src/Platform.cc: Moved common setup/teardown code to Platform class.
+ I moved #endif // HAVE_WINSOCK2_H to the front of #include "DlAbortEx.h"
+ I included locale.h from Platform.cc.
+ * src/main.cc: Moved common setup/teardown code to Platform class.
+ * test/AllTest.cc: Use Platform class.
+ Set locale to C in AllTest.cc to prevent the messages to be localized.
+
+2008-06-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
+
Applied Ross's aria2-0.13.2+1-mingw-3.patch.
* test/HttpHeaderTest.cc: Casted to off_t where it should.
* test/HttpRequestTest.cc: Casted to off_t where it should.
diff --git a/src/Platform.cc b/src/Platform.cc
index 4b334f0a..a438d9cf 100644
--- a/src/Platform.cc
+++ b/src/Platform.cc
@@ -33,6 +33,15 @@
*/
/* copyright --> */
#include "Platform.h"
+
+#ifdef HAVE_LIBSSL
+# include <openssl/err.h>
+# include <openssl/ssl.h>
+#endif // HAVE_LIBSSL
+#ifdef HAVE_LIBGNUTLS
+# include <gnutls/gnutls.h>
+#endif // HAVE_LIBGNUTLS
+
#ifdef HAVE_WINSOCK2_H
#ifndef _WIN32_WINNT
@@ -44,26 +53,87 @@
# include <ws2tcpip.h>
#endif // HAVE_WS2TCPIP_H
+#endif // HAVE_WINSOCK2_H
+
#include "DlAbortEx.h"
#include "message.h"
#include <stdlib.h> /* _fmode */
#include <fcntl.h> /* _O_BINARY */
+#include <locale.h> // For setlocale, LC_*
namespace aria2 {
-Platform::Platform() {
- unsigned int _CRT_fmode = _O_BINARY;
+bool Platform::_initialized = false;
+
+Platform::Platform()
+{
+ setUp();
+}
+
+Platform::~Platform()
+{
+ tearDown();
+}
+
+bool Platform::setUp()
+{
+ if (_initialized) {
+ return false;
+ }
+ _initialized = true;
+
+#ifdef ENABLE_NLS
+ setlocale (LC_CTYPE, "");
+ setlocale (LC_MESSAGES, "");
+ bindtextdomain (PACKAGE, LOCALEDIR);
+ textdomain (PACKAGE);
+#endif // ENABLE_NLS
+
+#ifdef HAVE_LIBSSL
+ // for SSL initialization
+ SSL_load_error_strings();
+ SSL_library_init();
+#endif // HAVE_LIBSSL
+#ifdef HAVE_LIBGNUTLS
+ gnutls_global_init();
+#endif // HAVE_LIBGNUTLS
+
+#ifdef HAVE_WINSOCK2_H
WSADATA wsaData;
memset((char*)&wsaData, 0, sizeof(wsaData));
if (WSAStartup(MAKEWORD(1, 1), &wsaData)) {
throw DlAbortEx(MSG_WINSOCK_INIT_FAILD);
}
+#endif // HAVE_WINSOCK2_H
+
+#ifdef __MINGW32__
+ unsigned int _CRT_fmode = _O_BINARY;
+#endif // __MINGW32__
+
+ return true;
}
-Platform::~Platform() {
+bool Platform::tearDown()
+{
+ if (!_initialized) {
+ return false;
+ }
+ _initialized = false;
+
+#ifdef HAVE_LIBGNUTLS
+ gnutls_global_deinit();
+#endif // HAVE_LIBGNUTLS
+
+#ifdef HAVE_WINSOCK2_H
WSACleanup();
+#endif // HAVE_WINSOCK2_H
+
+ return true;
}
-} // namespace aria2
+bool Platform::isInitialized()
+{
+ return _initialized;
+}
-#endif // HAVE_WINSOCK2_H
+} // namespace aria2
diff --git a/src/Platform.h b/src/Platform.h
index 5d55061a..0b4146e9 100644
--- a/src/Platform.h
+++ b/src/Platform.h
@@ -39,16 +39,21 @@
namespace aria2 {
-#ifdef HAVE_WINSOCK2_H
-
class Platform {
+private:
+ static bool _initialized;
+
public:
Platform();
~Platform();
-};
-#endif // HAVE_WINSOCK2_H
+ static bool setUp();
+
+ static bool tearDown();
+
+ static bool isInitialized();
+};
} // namespace aria2
diff --git a/src/main.cc b/src/main.cc
index d16bdf72..0be2f133 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -85,15 +85,6 @@ extern char* optarg;
extern int optind, opterr, optopt;
#include <getopt.h>
-#ifdef HAVE_LIBSSL
-// for SSL
-# include <openssl/err.h>
-# include <openssl/ssl.h>
-#endif // HAVE_LIBSSL
-#ifdef HAVE_LIBGNUTLS
-# include <gnutls/gnutls.h>
-#endif // HAVE_LIBGNUTLS
-
namespace aria2 {
// output stream to /dev/null
@@ -460,31 +451,9 @@ int main(int argc, char* argv[])
} // namespace aria2
int main(int argc, char* argv[]) {
-#ifdef HAVE_WINSOCK2_H
aria2::Platform platform;
-#endif // HAVE_WINSOCK2_H
-
-#ifdef ENABLE_NLS
- setlocale (LC_CTYPE, "");
- setlocale (LC_MESSAGES, "");
- bindtextdomain (PACKAGE, LOCALEDIR);
- textdomain (PACKAGE);
-#endif // ENABLE_NLS
-
-#ifdef HAVE_LIBSSL
- // for SSL initialization
- SSL_load_error_strings();
- SSL_library_init();
-#endif // HAVE_LIBSSL
-#ifdef HAVE_LIBGNUTLS
- gnutls_global_init();
-#endif // HAVE_LIBGNUTLS
int r = aria2::main(argc, argv);
-#ifdef HAVE_LIBGNUTLS
- gnutls_global_deinit();
-#endif // HAVE_LIBGNUTLS
-
return r;
}
diff --git a/test/AllTest.cc b/test/AllTest.cc
index 41e44e95..a457673a 100644
--- a/test/AllTest.cc
+++ b/test/AllTest.cc
@@ -1,20 +1,22 @@
+#include "Platform.h"
#include "CookieBoxFactory.h"
#include <iostream>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/ui/text/TestRunner.h>
-#ifdef HAVE_LIBSSL
-# include <openssl/err.h>
-# include <openssl/ssl.h>
-#endif // HAVE_LIBSSL
-#ifdef HAVE_LIBGNUTLS
-# include <gnutls/gnutls.h>
-#endif // HAVE_LIBGNUTLS
using aria2::SharedHandle;
using aria2::SingletonHolder;
int main(int argc, char* argv[]) {
+ aria2::Platform platform;
+
+#ifdef ENABLE_NLS
+ // Set locale to C to prevent the messages to be localized.
+ setlocale (LC_CTYPE, "C");
+ setlocale (LC_MESSAGES, "C");
+#endif // ENABLE_NLS
+
CppUnit::Test* suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
CppUnit::TextUi::TestRunner runner;
runner.addTest(suite);
@@ -23,15 +25,6 @@ int main(int argc, char* argv[]) {
// setup
-#ifdef HAVE_LIBSSL
- // for SSL initialization
- SSL_load_error_strings();
- SSL_library_init();
-#endif // HAVE_LIBSSL
-#ifdef HAVE_LIBGNUTLS
- gnutls_global_init();
-#endif // HAVE_LIBGNUTLS
-
SharedHandle<aria2::CookieBoxFactory> cookieBoxFactory
(new aria2::CookieBoxFactory());
SingletonHolder<SharedHandle<aria2::CookieBoxFactory> >::instance(cookieBoxFactory);
@@ -39,9 +32,5 @@ int main(int argc, char* argv[]) {
// Run the tests.
bool successfull = runner.run();
-#ifdef HAVE_LIBGNUTLS
- gnutls_global_deinit();
-#endif // HAVE_LIBGNUTLS
-
return successfull ? 0 : 1;
}