test openssl in fiber mode.

This commit is contained in:
zhengshuxin 2022-08-29 18:40:15 +08:00
parent ae39d3ec94
commit 97028886a8
5 changed files with 28 additions and 11 deletions

View File

@ -131,13 +131,13 @@ service httpd_proxy
# loop_read = 1
# 启用MbedTLS时加载的动态库
libcrypto_path = ./libmbedtls_all.so
libx509_path = ./libmbedtls_all.so
libssl_path = ./libmbedtls_all.so
# libcrypto_path = ./libmbedtls_all.so
# libx509_path = ./libmbedtls_all.so
# libssl_path = ./libmbedtls_all.so
# 启用OpenSSL时加载的动态库
# libcrypto_path = /usr/local/lib64/libcrypto.so
# libssl_path = /usr/local/lib64/libssl.so
libcrypto_path = /usr/local/lib64/libcrypto.so
libssl_path = /usr/local/lib64/libssl.so
# 加载的证书及证书私钥
# crt_file = ./ssl_crt.pem

View File

@ -196,8 +196,8 @@ void master_service::proc_on_init(void)
logger("OpenSSL loaded, crypto=%s, ssl=%s",
var_cfg_libcrypto_path, var_cfg_libssl_path);
server_conf_ = new acl::openssl_conf(true);
client_conf_ = new acl::openssl_conf(false);
server_conf_ = new acl::openssl_conf(true, 5);
client_conf_ = new acl::openssl_conf(false, 5);
} else {
logger("unsupported ssl=%s", var_cfg_libssl_path);
return;

View File

@ -43,11 +43,14 @@ int acl_write_wait_ms(ACL_SOCKET fd, int timeout)
const char *myname = "acl_write_wait";
struct pollfd fds;
int delay = timeout;
time_t begin, end;
fds.events = POLLOUT;
fds.revents = 0;
fds.fd = fd;
begin = time(NULL);
for (;;) {
switch (__sys_poll(&fds, 1, delay)) {
#ifdef ACL_WINDOWS
@ -68,8 +71,10 @@ int acl_write_wait_ms(ACL_SOCKET fd, int timeout)
} else {
acl_set_error(ACL_ETIMEDOUT);
}
acl_msg_error("%s(%d), %s: poll return 0, delay=%d",
__FILE__, __LINE__, myname, delay);
end = time(NULL);
acl_msg_error("%s(%d), %s: poll return 0, delay=%d, "
"fd=%d, cost=%ld", __FILE__, __LINE__,
myname, delay, fd, end - begin);
return -1;
default:
if (fds.revents & POLLNVAL) {

View File

@ -11,7 +11,7 @@ class openssl_io;
class ACL_CPP_API openssl_conf : public sslbase_conf {
public:
openssl_conf(bool server_side = false);
openssl_conf(bool server_side = false, int timeout = 30);
~openssl_conf(void);
/**
@ -78,6 +78,7 @@ private:
bool server_side_;
void* ssl_ctx_;
int timeout_;
string crt_file_;
unsigned init_status_;
thread_mutex lock_;

View File

@ -106,6 +106,10 @@ static ssl_ctx_check_pkey_fn __ssl_ctx_check_pkey;
typedef void (*ssl_ctx_set_def_pass_fn)(SSL_CTX*, void*);
static ssl_ctx_set_def_pass_fn __ssl_ctx_set_def_pass;
# define SSL_CTX_SET_TIMEOUT "SSL_CTX_set_timeout"
typedef long (*ssl_ctx_set_timeout_fn)(SSL_CTX*, long);
static ssl_ctx_set_timeout_fn __ssl_ctx_set_timeout;
static acl_pthread_once_t __openssl_once = ACL_PTHREAD_ONCE_INIT;
static acl::string* __crypto_path_buf = NULL;
static acl::string* __ssl_path_buf = NULL;
@ -186,6 +190,7 @@ static bool load_from_ssl(void)
LOAD_SSL(SSL_CTX_USE_PKEY_FILE, ssl_ctx_use_pkey_fn, __ssl_ctx_use_pkey);
LOAD_SSL(SSL_CTX_CHECK_PKEY, ssl_ctx_check_pkey_fn, __ssl_ctx_check_pkey);
LOAD_SSL(SSL_CTX_SET_DEF_PASS, ssl_ctx_set_def_pass_fn, __ssl_ctx_set_def_pass);
LOAD_SSL(SSL_CTX_SET_TIMEOUT, ssl_ctx_set_timeout_fn, __ssl_ctx_set_timeout);
return true;
}
@ -275,6 +280,7 @@ static void openssl_dll_load(void)
# define __ssl_ctx_use_pkey SSL_CTX_use_PrivateKey_file
# define __ssl_ctx_check_pkey SSL_CTX_check_private_key
# define __ssl_ctx_set_def_pass SSL_CTX_set_default_passwd_cb_userdata
# define __ssl_ctx_set_timeout SSL_CTX_set_timeout
# endif // !HAS_OPENSSL_DLL
#endif // HAS_OPENSSL
@ -337,6 +343,10 @@ bool openssl_conf::init_once(void)
ssl_ctx_ = (void*) __ssl_ctx_new(__sslv23_method());
if (timeout_ > 0) {
__ssl_ctx_set_timeout((SSL_CTX*) ssl_ctx_, timeout_);
}
# if OPENSSL_VERSION_NUMBER >= 0x10100003L
if (__ssl_init(OPENSSL_INIT_LOAD_CONFIG, NULL) == 0) {
logger_error("OPENSSL_init_ssl error");
@ -373,9 +383,10 @@ bool openssl_conf::init_once(void)
#endif // HAS_OPENSSL
}
openssl_conf::openssl_conf(bool server_side /* false */)
openssl_conf::openssl_conf(bool server_side /* false */, int timeout /* 30 */)
: server_side_(server_side)
, ssl_ctx_(NULL)
, timeout_(timeout)
, init_status_(CONF_INIT_NIL)
{
}