Fixed multithreading issue with gnutls.

This commit is contained in:
lotodore
2008-04-24 22:11:43 +00:00
parent 873b626c5f
commit dd3453d364
9 changed files with 73 additions and 15 deletions
+7 -2
View File
@@ -24,8 +24,13 @@
#ifndef HAVE_SSIZE_T
# define HAVE_SSIZE_T
#include <sys/types.h>
#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
+1 -1
View File
@@ -36,7 +36,7 @@
using namespace std;
//#define SERVER_TEST
#define SERVER_TEST
#define SERVER_START_GAME_TIMEOUT_SEC 10
+46
View File
@@ -19,6 +19,52 @@
#include <net/socket_startup.h>
#include <net/socket_helper.h>
#include <core/openssl_wrapper.h>
#include <gcrypt.h>
#include <boost/thread.hpp>
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
+2 -1
View File
@@ -32,11 +32,12 @@ using namespace std;
bool
socket_startup()
{
return true;
return internal_socket_startup();
}
void
socket_cleanup()
{
internal_socket_cleanup();
}
+5
View File
@@ -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
+2 -1
View File
@@ -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();
}
+2 -2
View File
@@ -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 );