*** _ssl.c 2006-07-11 10:04:09.000000000 +0800 --- _ssl.patched.c 2008-01-31 06:49:59.000000000 +0800 *************** *** 668,673 **** --- 668,691 ---- {NULL, NULL} /* Sentinel */ }; + #include "pythread.h" + + static PyThread_type_lock openssl_lock[CRYPTO_NUM_LOCKS]; + + static unsigned long + id_function(void) + { + return (unsigned long)PyThread_get_thread_ident(); + } + + static void + locking_function(int mode, int n, const char *file, int line) + { + if (mode & CRYPTO_LOCK) + PyThread_acquire_lock(openssl_lock[n], 1); + else + PyThread_release_lock(openssl_lock[n]); + } PyDoc_STRVAR(module_doc, "Implementation module for SSL socket operations. See the socket module\n\ *************** *** 677,682 **** --- 695,701 ---- init_ssl(void) { PyObject *m, *d; + int i; PySSL_Type.ob_type = &PyType_Type; *************** *** 693,698 **** --- 712,723 ---- SSL_load_error_strings(); SSLeay_add_ssl_algorithms(); + /* Init OpenSSL for Multi-Threads Environment */ + for (i = 0; i < CRYPTO_NUM_LOCKS; i++) + openssl_lock[i] = PyThread_allocate_lock(); + CRYPTO_set_id_callback(id_function); + CRYPTO_set_locking_callback(locking_function); + /* Add symbols to module dict */ PySSLErrorObject = PyErr_NewException("socket.sslerror", PySocketModule.error,