diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-06-16 11:59:34 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2008-06-16 11:59:34 +0000 |
| commit | aaa2ecaa6fd16fa6a03e1c9051b0a481e8d4f20a (patch) | |
| tree | 230b5f6a71d1e4d09c22d70ae6b314cd8a5723cc /src/Platform.cc | |
| parent | 06644332c2cc5b229ef41857ceed73f7caf2775f (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.
Diffstat (limited to 'src/Platform.cc')
| -rw-r--r-- | src/Platform.cc | 80 |
1 files changed, 75 insertions, 5 deletions
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 |
