From dd3453d364c9dc5d16cfe0aede4c6eed83c47bd6 Mon Sep 17 00:00:00 2001 From: lotodore Date: Thu, 24 Apr 2008 22:11:43 +0000 Subject: [PATCH] Fixed multithreading issue with gnutls. --- pokerth_game.pro | 8 ++--- pokerth_server.pro | 8 ++--- src/core/openssl_wrapper.h | 9 ++++-- src/net/common/servergamestate.cpp | 2 +- src/net/common/socket_startup_cmn.cpp | 46 +++++++++++++++++++++++++++ src/net/linux/socket_startup.cpp | 3 +- src/net/socket_startup.h | 5 +++ src/net/win32/socket_startup.cpp | 3 +- src/pokerth.cpp | 4 +-- 9 files changed, 73 insertions(+), 15 deletions(-) diff --git a/pokerth_game.pro b/pokerth_game.pro index 0e630287..1de04b38 100644 --- a/pokerth_game.pro +++ b/pokerth_game.pro @@ -271,7 +271,7 @@ win32{ LIBPATH += Release/lib ../SDL/VisualC/SDL/Release ../SDL/VisualC/SDLmain/Release ../SDL_mixer/VisualC/Release #LIBPATH += Debug/lib ../SDL/VisualC/SDL/Debug ../SDL/VisualC/SDLmain/Debug ../SDL_mixer/VisualC/Debug - LIBS += -llibgnutls-openssl + LIBS += -llibgnutls-openssl -llibgcrypt LIBS += -llibcurl } @@ -279,7 +279,7 @@ win32{ LIBPATH += Release/lib #LIBPATH += Debug/lib LIBPATH += ../SDL/lib ../SDL_mixer/lib - LIBS += -lgnutls-openssl + LIBS += -lgnutls-openssl -lgcrypt LIBS += -lcurl LIBS += -lz LIBS += -llibboost_thread-mgw34-mt-1_35 @@ -344,7 +344,7 @@ unix: !mac{ LIBS += -lpokerth_lib LIBS += $$BOOST_LIBS - LIBS += -lgnutls-openssl -lSDL_mixer -lcurl -lz + LIBS += -lgnutls-openssl -lgcrypt -lSDL_mixer -lcurl -lz TARGETDEPS += ./lib/libpokerth_lib.a ## My release static libs @@ -393,7 +393,7 @@ mac{ LIBS += /usr/local/lib/libboost_thread-mt-1_34_1.a LIBS += /usr/local/lib/libboost_filesystem-mt-1_34_1.a # libraries installed on every mac - LIBS += -lcrypto -lz -lcurl -framework Carbon + LIBS += -lgnutls-openssl -lgcrypt -lz -lcurl -framework Carbon # set the application icon RC_FILE = pokerth.icns LIBPATH += /Developer/SDKs/MacOSX10.4u.sdk/usr/lib diff --git a/pokerth_server.pro b/pokerth_server.pro index 23e38ae2..785b036c 100644 --- a/pokerth_server.pro +++ b/pokerth_server.pro @@ -126,12 +126,12 @@ win32 { LIBS += -lpokerth_lib win32-msvc2005{ - LIBS += -llibgnutls-openssl + LIBS += -llibgnutls-openssl -llibgcrypt LIBS += -llibcurl } win32-g++{ - LIBS += -lgnutls-openssl + LIBS += -lgnutls-openssl -lgcrypt LIBS += -lcurl LIBS += -llibboost_thread-mgw34-mt-1_35 LIBS += -llibboost_filesystem-mgw34-mt-1_35 @@ -198,7 +198,7 @@ unix : !mac { LIBS += -lpokerth_lib LIBS += $$BOOST_LIBS - LIBS += -lgnutls-openssl -lcurl + LIBS += -lgnutls-openssl -lgcrypt -lcurl TARGETDEPS += ./lib/libpokerth_lib.a @@ -228,7 +228,7 @@ mac{ LIBS += /usr/local/lib/libboost_filesystem-mt-1_34_1.a LIBS += /usr/local/lib/libboost_program_options-mt-1_34_1.a # libraries installed on every mac - LIBS += -lgnutls-openssl -liconv + LIBS += -lgnutls-openssl -lgcrypt -liconv # set the application icon RC_FILE = pokerth.icns LIBPATH += /Developer/SDKs/MacOSX10.4u.sdk/usr/lib diff --git a/src/core/openssl_wrapper.h b/src/core/openssl_wrapper.h index d600c520..8a8aae5d 100644 --- a/src/core/openssl_wrapper.h +++ b/src/core/openssl_wrapper.h @@ -24,8 +24,13 @@ #ifndef HAVE_SSIZE_T # define HAVE_SSIZE_T #include -#if (defined _WIN32) && (!defined ssize_t) - typedef long ssize_t; // This is only for Windows. Supports only Win32. +#ifdef _WIN32 + #ifndef ssize_t + typedef long ssize_t; // This is only for Windows. Supports only Win32. + #endif + #ifndef pid_t + typedef unsigned pid_t; + #endif #endif #endif diff --git a/src/net/common/servergamestate.cpp b/src/net/common/servergamestate.cpp index 8dd5adf0..ae5c5d3e 100644 --- a/src/net/common/servergamestate.cpp +++ b/src/net/common/servergamestate.cpp @@ -36,7 +36,7 @@ using namespace std; -//#define SERVER_TEST +#define SERVER_TEST #define SERVER_START_GAME_TIMEOUT_SEC 10 diff --git a/src/net/common/socket_startup_cmn.cpp b/src/net/common/socket_startup_cmn.cpp index 872ec01d..fabe89ee 100644 --- a/src/net/common/socket_startup_cmn.cpp +++ b/src/net/common/socket_startup_cmn.cpp @@ -19,6 +19,52 @@ #include #include +#include +#include +#include + +extern "C" { + + int gcry_bthread_init() + { + return 0; + } + int gcry_bmutex_init(void **obj) { + *obj = (void*)(new boost::mutex); + return 0; + } + int gcry_bmutex_destroy(void **obj) { + delete (boost::mutex *)(*obj); + return 0; + } + int gcry_bmutex_lock(void **obj) { + ((boost::mutex *)(*obj))->lock(); + return 0; + } + int gcry_bmutex_unlock(void **obj) { + ((boost::mutex *)(*obj))->unlock(); + return 0; + } + + struct gcry_thread_cbs gcry_threads_boost = + { + GCRY_THREAD_OPTION_USER, gcry_bthread_init, gcry_bmutex_init, + gcry_bmutex_destroy, gcry_bmutex_lock, gcry_bmutex_unlock, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL + }; +} + +bool +internal_socket_startup() +{ + gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_boost); + return SSL_library_init() == 1; +} + +void +internal_socket_cleanup() +{ +} bool diff --git a/src/net/linux/socket_startup.cpp b/src/net/linux/socket_startup.cpp index 169af573..e61c388f 100644 --- a/src/net/linux/socket_startup.cpp +++ b/src/net/linux/socket_startup.cpp @@ -32,11 +32,12 @@ using namespace std; bool socket_startup() { - return true; + return internal_socket_startup(); } void socket_cleanup() { + internal_socket_cleanup(); } diff --git a/src/net/socket_startup.h b/src/net/socket_startup.h index d387f3c5..0fe90bf0 100644 --- a/src/net/socket_startup.h +++ b/src/net/socket_startup.h @@ -27,5 +27,10 @@ bool socket_has_sctp(); bool socket_has_ipv6(); bool socket_has_dual_stack(); +/* Internal common functions. */ +bool internal_socket_startup(); +void internal_socket_cleanup(); + + #endif diff --git a/src/net/win32/socket_startup.cpp b/src/net/win32/socket_startup.cpp index e5607f5d..0c5f75e7 100644 --- a/src/net/win32/socket_startup.cpp +++ b/src/net/win32/socket_startup.cpp @@ -57,12 +57,13 @@ socket_startup() } /* The WinSock DLL is acceptable. Proceed. */ - return true; + return internal_socket_startup(); } void socket_cleanup() { + internal_socket_cleanup(); WSACleanup(); } diff --git a/src/pokerth.cpp b/src/pokerth.cpp index 0f53ee2d..790e590a 100755 --- a/src/pokerth.cpp +++ b/src/pokerth.cpp @@ -75,8 +75,8 @@ int main( int argc, char **argv ) //_CrtSetBreakAlloc(49937); socket_startup(); - curl_global_init(CURL_GLOBAL_ALL); - + curl_global_init(CURL_GLOBAL_NOTHING); + /////// can be removed for non-qt-guis //////////// QApplication a( argc, argv );