mirror of https://github.com/sipwise/rtpengine.git
parent
b28e718ee4
commit
2029144368
@ -0,0 +1,51 @@
|
|||||||
|
#include "ssllib.h"
|
||||||
|
#include <openssl/ssl.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
|
||||||
|
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||||
|
static mutex_t *openssl_locks;
|
||||||
|
|
||||||
|
static void cb_openssl_threadid(CRYPTO_THREADID *tid) {
|
||||||
|
pthread_t me;
|
||||||
|
|
||||||
|
me = pthread_self();
|
||||||
|
|
||||||
|
if (sizeof(me) == sizeof(void *))
|
||||||
|
CRYPTO_THREADID_set_pointer(tid, (void *) me);
|
||||||
|
else
|
||||||
|
CRYPTO_THREADID_set_numeric(tid, (unsigned long) me);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cb_openssl_lock(int mode, int type, const char *file, int line) {
|
||||||
|
if ((mode & CRYPTO_LOCK))
|
||||||
|
mutex_lock(&openssl_locks[type]);
|
||||||
|
else
|
||||||
|
mutex_unlock(&openssl_locks[type]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void make_OpenSSL_thread_safe(void) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
openssl_locks = malloc(sizeof(*openssl_locks) * CRYPTO_num_locks());
|
||||||
|
for (i = 0; i < CRYPTO_num_locks(); i++)
|
||||||
|
mutex_init(&openssl_locks[i]);
|
||||||
|
|
||||||
|
CRYPTO_THREADID_set_callback(cb_openssl_threadid);
|
||||||
|
CRYPTO_set_locking_callback(cb_openssl_lock);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static void make_OpenSSL_thread_safe(void) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
void rtpe_ssl_init(void) {
|
||||||
|
struct timespec ts;
|
||||||
|
clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
|
srandom(ts.tv_sec ^ ts.tv_nsec);
|
||||||
|
SSL_library_init();
|
||||||
|
SSL_load_error_strings();
|
||||||
|
make_OpenSSL_thread_safe();
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
#ifndef __SSLLIB_H__
|
||||||
|
#define __SSLLIB_H__
|
||||||
|
|
||||||
|
|
||||||
|
void rtpe_ssl_init(void);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -1,10 +1,11 @@
|
|||||||
#include "poller.h"
|
#include "poller.h"
|
||||||
|
|
||||||
void poller_blocked(struct poller *p, void *fdp) {
|
void poller_blocked(struct poller *p, void *fdp) {
|
||||||
p->blocked = 1;
|
p->state = PS_WRITE_BLOCKED;
|
||||||
}
|
}
|
||||||
int poller_isblocked(struct poller *p, void *fdp) {
|
int poller_isblocked(struct poller *p, void *fdp) {
|
||||||
return p->blocked ? 1 : 0;
|
return p->state != PS_OPEN;
|
||||||
}
|
}
|
||||||
void poller_error(struct poller *p, void *fdp) {
|
void poller_error(struct poller *p, void *fdp) {
|
||||||
|
p->state = PS_ERROR;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in new issue