mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-29 18:37:41 +08:00
Fixed one bug in openssl_io.cpp when seting IO timeout by setsockopt.
This commit is contained in:
parent
59634b0ac8
commit
58058dde10
@ -16,8 +16,8 @@ class openssl_io;
|
||||
|
||||
class ACL_CPP_API openssl_conf : public sslbase_conf {
|
||||
public:
|
||||
openssl_conf(bool server_side = false, int timeout = 30);
|
||||
~openssl_conf(void);
|
||||
explicit openssl_conf(bool server_side = false, int timeout = 30);
|
||||
~openssl_conf();
|
||||
|
||||
/**
|
||||
* @override
|
||||
@ -59,20 +59,20 @@ public:
|
||||
* 显式调用本方法,动态加载 libssl.so 动态库
|
||||
* @return {bool} 加载是否成功
|
||||
*/
|
||||
static bool load(void);
|
||||
static bool load();
|
||||
|
||||
/**
|
||||
* 调用 load() 成功加载 OpenSSL 动态库后,调用本静态函数获得 libssl
|
||||
* 动态加载库句柄,从而可以从该句柄中获得指定函数指针
|
||||
* @return {void*} 返回 NULL 表示还未加载
|
||||
*/
|
||||
static void* get_libssl_handle(void);
|
||||
static void* get_libssl_handle();
|
||||
|
||||
/**
|
||||
* 获得 libcrypto 动态加载库句柄
|
||||
* @return {void*} 返回 NULL 表示还未加载
|
||||
*/
|
||||
static void* get_libcrypto_handle(void);
|
||||
static void* get_libcrypto_handle();
|
||||
|
||||
public:
|
||||
// @override sslbase_conf
|
||||
@ -83,7 +83,7 @@ public:
|
||||
* 是否为 SSL 服务模式
|
||||
* @return {bool}
|
||||
*/
|
||||
bool is_server_side(void) const {
|
||||
bool is_server_side() const {
|
||||
return server_side_;
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ public:
|
||||
* 获得缺省的SSL_CTX对象
|
||||
* @return {SSL_CTX*}
|
||||
*/
|
||||
SSL_CTX* get_ssl_ctx(void) const;
|
||||
SSL_CTX* get_ssl_ctx() const;
|
||||
|
||||
/**
|
||||
* 获得所有的已经初始完成的 SSL_CTX 对象
|
||||
@ -105,7 +105,7 @@ public:
|
||||
* 加载或静态加载的 SSL_CTX_new() API.
|
||||
* @return {SSL_CTX*} 返回 NULL 表示未开启 OpenSSL 功能
|
||||
*/
|
||||
SSL_CTX* create_ssl_ctx(void);
|
||||
SSL_CTX* create_ssl_ctx();
|
||||
|
||||
/**
|
||||
* 服务模式下, 添加外部已经初始完毕的 SSL_CTX, 该对象必须是由上面
|
||||
|
@ -16,16 +16,16 @@ public:
|
||||
/*
|
||||
* @override stream_hook
|
||||
*/
|
||||
void destroy(void);
|
||||
void destroy();
|
||||
|
||||
/**
|
||||
* @override sslbase_io
|
||||
* @return {bool}
|
||||
*/
|
||||
bool handshake(void);
|
||||
bool handshake();
|
||||
|
||||
protected:
|
||||
~openssl_io(void);
|
||||
~openssl_io();
|
||||
|
||||
// 实现 stream_hook 类的虚方法
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
os=$(echo `uname -s`)
|
||||
if [ $os == "Darwin" ]; then
|
||||
./client -s "127.0.0.1|2443" -l "/usr/local/lib64/libcrypto.dylib;/usr/local/lib64/libssl.dylib" -c 1 -n 1
|
||||
./client -s "127.0.0.1|2443" -l "/usr/local/lib/libcrypto.dylib;/usr/local/lib/libssl.dylib" -c 1 -n 1
|
||||
elif [ $os == "Linux" ]; then
|
||||
./client -s "127.0.0.1|2443" -l "/usr/local/lib64/libcrypto.so;/usr/local/lib64/libssl.so" -c 1 -n 1
|
||||
else
|
||||
|
@ -12,4 +12,4 @@ ifeq ($(findstring Darwin, $(UNIXNAME)), Darwin)
|
||||
endif
|
||||
|
||||
PROG = server
|
||||
EXTLIBS += -L../../../lib/linux64 -ldl -lz
|
||||
EXTLIBS += -L../../../lib -ldl -lz
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
os=$(echo `uname -s`)
|
||||
if [ $os == "Darwin" ]; then
|
||||
./server -s "0.0.0.0|2443" -r 2 -o 2 -t openssl -L "/usr/local/lib64/libcrypto.dylib; /usr/local/lib64/libssl.dylib" -c ../ssl_crt.pem -k ../ssl_key.pem
|
||||
./server -s "0.0.0.0|2443" -r 2 -o 2 -t openssl -L "/usr/local/lib/libcrypto.dylib; /usr/local/lib/libssl.dylib" -c ../ssl_crt.pem -k ../ssl_key.pem
|
||||
elif [ $os == "Linux" ]; then
|
||||
./server -s "0.0.0.0|2443" -r 2 -o 2 -t openssl -L "/usr/local/lib64/libcrypto.so; /usr/local/lib64/libssl.so" -c ../ssl_crt.pem -k ../ssl_key.pem
|
||||
else
|
||||
|
@ -578,7 +578,7 @@ openssl_conf::openssl_conf(bool server_side /* false */, int timeout /* 30 */)
|
||||
#endif // HAS_OPENSSL
|
||||
}
|
||||
|
||||
openssl_conf::~openssl_conf(void)
|
||||
openssl_conf::~openssl_conf()
|
||||
{
|
||||
#ifdef HAS_OPENSSL
|
||||
for (std::set<SSL_CTX*>::iterator it = ssl_ctxes_.begin();
|
||||
@ -597,7 +597,7 @@ void openssl_conf::use_sockopt_timeout(bool yes)
|
||||
}
|
||||
|
||||
|
||||
SSL_CTX* openssl_conf::create_ssl_ctx(void)
|
||||
SSL_CTX* openssl_conf::create_ssl_ctx()
|
||||
{
|
||||
#ifdef HAS_OPENSSL
|
||||
if (status_ != CONF_INIT_OK) {
|
||||
@ -651,7 +651,7 @@ bool openssl_conf::push_ssl_ctx(SSL_CTX* ctx)
|
||||
#endif
|
||||
}
|
||||
|
||||
SSL_CTX* openssl_conf::get_ssl_ctx(void) const
|
||||
SSL_CTX* openssl_conf::get_ssl_ctx() const
|
||||
{
|
||||
// The ssl_ctx_ should be created in client mode, and in server mode,
|
||||
// it should also be created when loading certificate.
|
||||
|
@ -197,14 +197,7 @@ static bool set_sock_timeo(ACL_SOCKET fd, int opt, int timeout)
|
||||
last_serror(), timeout, opt, (int) fd);
|
||||
return false;
|
||||
}
|
||||
# elif defined(__APPLE__)
|
||||
timeout *= 1000; // From seconds to millisecond.
|
||||
if (setsockopt(fd, SOL_SOCKET, opt, &timeout, sizeof(timeout)) < 0) {
|
||||
logger_error("setsockopt error=%s, timeout=%d, opt=%d, fd=%d",
|
||||
last_serror(), timeout, opt, (int) fd);
|
||||
return false;
|
||||
}
|
||||
# else // Must be Linux.
|
||||
# else // Must be Linux or __APPLE__.
|
||||
struct timeval tm;
|
||||
tm.tv_sec = timeout;
|
||||
tm.tv_usec = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user