Fixed one bug in openssl_io.cpp when seting IO timeout by setsockopt.

This commit is contained in:
shuxin   zheng 2024-05-25 11:26:08 +08:00
parent 59634b0ac8
commit 58058dde10
7 changed files with 18 additions and 25 deletions

View File

@ -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,

View File

@ -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 类的虚方法

View File

@ -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

View File

@ -12,4 +12,4 @@ ifeq ($(findstring Darwin, $(UNIXNAME)), Darwin)
endif
PROG = server
EXTLIBS += -L../../../lib/linux64 -ldl -lz
EXTLIBS += -L../../../lib -ldl -lz

View File

@ -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

View File

@ -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.

View File

@ -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;