From 1331b420b3152dfeb8e42dd63097df015fbf03df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=A0=91=E6=96=B0?= Date: Fri, 15 Dec 2023 16:20:21 +0800 Subject: [PATCH] Load OpenSSL dll successfully on Windows platforms. --- lib_acl/lib_acl_vc2019.vcxproj | 4 ++-- lib_acl_cpp/lib_acl_cpp_vc2019.vcxproj | 20 ++++++++++---------- lib_acl_cpp/src/stream/openssl_io.cpp | 6 +++--- lib_fiber/c/src/hook/fiber_read.c | 14 +++++++++++++- lib_fiber/c/src/hook/fiber_write.c | 9 +++++++++ lib_fiber/c/src/hook/io.c | 19 +++++++++++++++++++ lib_protocol/lib_protocol_vc2019.vcxproj | 4 ++-- 7 files changed, 58 insertions(+), 18 deletions(-) diff --git a/lib_acl/lib_acl_vc2019.vcxproj b/lib_acl/lib_acl_vc2019.vcxproj index 84dbfd402..fd2dbc897 100644 --- a/lib_acl/lib_acl_vc2019.vcxproj +++ b/lib_acl/lib_acl_vc2019.vcxproj @@ -341,7 +341,7 @@ NDEBUG;_LIB;_MT;ACL_PREPARE_COMPILE;ACL_DLL;ACL_EXPORTS;%(PreprocessorDefinitions) MultiThreadedDLL Use - $(ProjectName).pdb + $(IntDir)vc$(PlatformToolsetVersion).pdb ProgramDatabase false @@ -391,7 +391,7 @@ EnableFastChecks MultiThreadedDebugDLL Use - $(ProjectName)_d.pdb + $(IntDir)vc$(PlatformToolsetVersion).pdb Level3 ProgramDatabase false diff --git a/lib_acl_cpp/lib_acl_cpp_vc2019.vcxproj b/lib_acl_cpp/lib_acl_cpp_vc2019.vcxproj index 4bbeb246d..b8b05225f 100644 --- a/lib_acl_cpp/lib_acl_cpp_vc2019.vcxproj +++ b/lib_acl_cpp/lib_acl_cpp_vc2019.vcxproj @@ -203,7 +203,7 @@ Disabled .\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\mysql;..\include\pgsql;..\include\openssl-1.1.1q;..\include;.\src;%(AdditionalIncludeDirectories) - _DEBUG;_LIB;_MT;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_PGSQL_DLL;HAS_POLARSSL_DLL;HAS_MBEDTLS_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions) + _DEBUG;_LIB;_MT;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_PGSQL_DLL;HAS_POLARSSL_DLL;HAS_MBEDTLS_DLL;HAS_OPENSSL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL Use @@ -227,7 +227,7 @@ .\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\mysql;..\include\pgsql;..\include\openssl-1.1.1q;..\include;.\src;%(AdditionalIncludeDirectories) - NDEBUG;_LIB;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_PGSQL_DLL;HAS_POLARSSL_DLL;HAS_MBEDTLS_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions) + NDEBUG;_LIB;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_PGSQL_DLL;HAS_POLARSSL_DLL;HAS_MBEDTLS_DLL;HAS_OPENSSL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions) MultiThreadedDLL Use acl_stdafx.hpp @@ -247,7 +247,7 @@ .\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\mysql;..\include\pgsql;..\include\openssl-1.1.1q;..\include;.\src;%(AdditionalIncludeDirectories) - NDEBUG;_LIB;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_PGSQL_DLL;HAS_POLARSSL_DLL;HAS_MBEDTLS_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions) + NDEBUG;_LIB;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_PGSQL_DLL;HAS_POLARSSL_DLL;HAS_MBEDTLS_DLL;HAS_OPENSSL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions) MultiThreadedDLL Use acl_stdafx.hpp @@ -269,7 +269,7 @@ Disabled .\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\mysql;..\include\pgsql;..\include\openssl-1.1.1q;..\include;.\src;%(AdditionalIncludeDirectories) - _DEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_PGSQL_DLL;HAS_POLARSSL_DLL;HAS_MBEDTLS_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions) + _DEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_PGSQL_DLL;HAS_POLARSSL_DLL;HAS_MBEDTLS_DLL;HAS_OPENSSL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions) false EnableFastChecks MultiThreadedDebugDLL @@ -300,13 +300,13 @@ Disabled .\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\mysql;..\include\pgsql;..\include\openssl-1.1.1q;..\include;.\src;%(AdditionalIncludeDirectories) - _DEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_PGSQL_DLL;HAS_POLARSSL_DLL;HAS_MBEDTLS_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions) + _DEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_PGSQL_DLL;HAS_POLARSSL_DLL;HAS_MBEDTLS_DLL;HAS_OPENSSL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebugDLL Use acl_stdafx.hpp $(IntDir)$(TargetName).pch - $(OutDir)$(ProjectName)_d.pdb + $(IntDir)vc$(PlatformToolsetVersion).pdb Level3 true ProgramDatabase @@ -331,7 +331,7 @@ Disabled .\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\mysql;..\include\pgsql;..\include\openssl-1.1.1q;..\include;.\src;%(AdditionalIncludeDirectories) - NDEBUG;_LIB;_MT;ACL_DLL;HTTP_DLL;SMTP_DLL;ICMP_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_PGSQL_DLL;HAS_POLARSSL_DLL;HAS_MBEDTLS_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions) + NDEBUG;_LIB;_MT;ACL_DLL;HTTP_DLL;SMTP_DLL;ICMP_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_PGSQL_DLL;HAS_POLARSSL_DLL;HAS_MBEDTLS_DLL;HAS_OPENSSL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions) false EnableFastChecks MultiThreadedDLL @@ -360,13 +360,13 @@ Disabled .\include;..\lib_acl\include;..\lib_protocol\include;..\include\sqlite;..\include\mysql;..\include\pgsql;..\include\openssl-1.1.1q;..\include;.\src;%(AdditionalIncludeDirectories) - NDEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_PGSQL_DLL;HAS_POLARSSL_DLL;HAS_MBEDTLS_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions) + NDEBUG;_LIB;_MT;ACL_DLL;ACL_CPP_DLL;ACL_CPP_EXPORTS;USE_WIN_ICONV;HAS_MYSQL_DLL;HAS_SQLITE_DLL;HAS_PGSQL_DLL;HAS_POLARSSL_DLL;HAS_MBEDTLS_DLL;HAS_OPENSSL_DLL;HAS_ZLIB_DLL;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDLL Use acl_stdafx.hpp $(IntDir)$(TargetName).pch - $(OutDir)$(ProjectName).pdb + $(IntDir)vc$(PlatformToolsetVersion).pdb Level3 true ProgramDatabase @@ -876,4 +876,4 @@ - + \ No newline at end of file diff --git a/lib_acl_cpp/src/stream/openssl_io.cpp b/lib_acl_cpp/src/stream/openssl_io.cpp index a2a7fde16..d8968838d 100644 --- a/lib_acl_cpp/src/stream/openssl_io.cpp +++ b/lib_acl_cpp/src/stream/openssl_io.cpp @@ -201,7 +201,7 @@ bool openssl_io::open(ACL_VSTREAM* s) SSL* ssl = __ssl_new(ctx); - if (!__ssl_set_fd(ssl, ACL_VSTREAM_SOCK(s))) { + if (!__ssl_set_fd(ssl, (int) ACL_VSTREAM_SOCK(s))) { logger_error("SSL_set_fd error"); __ssl_free(ssl); return false; @@ -322,7 +322,7 @@ int openssl_io::read(void* buf, size_t len) return -1; } - int ret = __ssl_read(ssl_, ptr, len); + int ret = __ssl_read(ssl_, ptr, (int) len); if (ret > 0) { nbytes += ret; ptr += ret; @@ -387,7 +387,7 @@ int openssl_io::send(const void* buf, size_t len) return -1; } - int ret = __ssl_write(ssl_, ptr, len); + int ret = __ssl_write(ssl_, ptr, (int) len); if (ret > 0) { nbytes += ret; ptr += ret; diff --git a/lib_fiber/c/src/hook/fiber_read.c b/lib_fiber/c/src/hook/fiber_read.c index 3a2e0860a..bce571fe4 100644 --- a/lib_fiber/c/src/hook/fiber_read.c +++ b/lib_fiber/c/src/hook/fiber_read.c @@ -346,7 +346,11 @@ ssize_t fiber_recv(FILE_EVENT *fe, void *buf, size_t len, int flags) #if defined(HAS_IOCP) if (EVENT_IS_IOCP(fiber_io_event())) { +# ifdef SYS_WIN + return (ssize_t) fiber_iocp_read(fe, buf, (int) len); +# else return fiber_iocp_read(fe, buf, len); +# endif } #elif defined(HAS_IO_URING) if (EVENT_IS_IO_URING(fiber_io_event())) { @@ -377,7 +381,11 @@ ssize_t fiber_recv(FILE_EVENT *fe, void *buf, size_t len, int flags) } #endif +#ifdef SYS_WIN + FIBER_READ(sys_recv, fe, buf, (int) len, flags); +#else FIBER_READ(sys_recv, fe, buf, len, flags); +#endif } ssize_t fiber_recvfrom(FILE_EVENT *fe, void *buf, size_t len, @@ -387,7 +395,7 @@ ssize_t fiber_recvfrom(FILE_EVENT *fe, void *buf, size_t len, #if defined(HAS_IOCP) if (EVENT_IS_IOCP(fiber_io_event())) { - return fiber_iocp_read(fe, buf, len); + return fiber_iocp_read(fe, buf, (int) len); } #elif defined(HAS_IO_URING) && defined(IO_URING_HAS_RECVFROM) if (EVENT_IS_IO_URING(fiber_io_event())) { @@ -420,5 +428,9 @@ ssize_t fiber_recvfrom(FILE_EVENT *fe, void *buf, size_t len, } #endif +#ifdef SYS_WIN + FIBER_READ(sys_recvfrom, fe, buf, (int) len, flags, src_addr, addrlen); +#else FIBER_READ(sys_recvfrom, fe, buf, len, flags, src_addr, addrlen); +#endif } diff --git a/lib_fiber/c/src/hook/fiber_write.c b/lib_fiber/c/src/hook/fiber_write.c index 013ec7b37..363299867 100644 --- a/lib_fiber/c/src/hook/fiber_write.c +++ b/lib_fiber/c/src/hook/fiber_write.c @@ -244,7 +244,11 @@ ssize_t fiber_send(FILE_EVENT *fe, const void *buf, size_t len, int flags) CHECK_SET_NBLOCK(fe->fd); while (1) { +#ifdef SYS_WIN + int n = (int) (*sys_send)(fe->fd, buf, (int) len, flags); +#else int n = (int) (*sys_send)(fe->fd, buf, len, flags); +#endif CHECK_WRITE_RESULT(fe, n); } @@ -293,8 +297,13 @@ ssize_t fiber_sendto(FILE_EVENT *fe, const void *buf, size_t len, CHECK_SET_NBLOCK(fe->fd); while (1) { +#ifdef SYS_WIN + int n = (int) (*sys_sendto)(fe->fd, buf, (int) len, flags, + dest_addr, addrlen); +#else int n = (int) (*sys_sendto)(fe->fd, buf, len, flags, dest_addr, addrlen); +#endif CHECK_WRITE_RESULT(fe, n); } diff --git a/lib_fiber/c/src/hook/io.c b/lib_fiber/c/src/hook/io.c index aec1ccac0..a2ed9506d 100644 --- a/lib_fiber/c/src/hook/io.c +++ b/lib_fiber/c/src/hook/io.c @@ -226,7 +226,11 @@ ssize_t acl_fiber_recv(socket_t sockfd, void *buf, size_t len, int flags) } fe = fiber_file_open(sockfd); +#ifdef SYS_WIN + return (int) fiber_recv(fe, buf, len, flags); +#else return fiber_recv(fe, buf, len, flags); +#endif } #ifdef SYS_WIN @@ -253,7 +257,12 @@ ssize_t acl_fiber_recvfrom(socket_t sockfd, void *buf, size_t len, } fe = fiber_file_open(sockfd); + +#ifdef SYS_WIN + return (int) fiber_recvfrom(fe, buf, len, flags, src_addr, addrlen); +#else return fiber_recvfrom(fe, buf, len, flags, src_addr, addrlen); +#endif } #ifdef SYS_UNIX @@ -385,7 +394,12 @@ ssize_t acl_fiber_send(socket_t sockfd, const void *buf, size_t len, int flags) } fe = fiber_file_open(sockfd); + +#ifdef SYS_WIN + return (int) fiber_send(fe, buf, len, flags); +#else return fiber_send(fe, buf, len, flags); +#endif } #ifdef SYS_WIN @@ -413,7 +427,12 @@ ssize_t acl_fiber_sendto(socket_t sockfd, const void *buf, size_t len, } fe = fiber_file_open(sockfd); + +#ifdef SYS_WIN + return (int) fiber_sendto(fe, buf, len, flags, dest_addr, addrlen); +#else return fiber_sendto(fe, buf, len, flags, dest_addr, addrlen); +#endif } #ifdef SYS_UNIX diff --git a/lib_protocol/lib_protocol_vc2019.vcxproj b/lib_protocol/lib_protocol_vc2019.vcxproj index b06af8b22..277d74711 100644 --- a/lib_protocol/lib_protocol_vc2019.vcxproj +++ b/lib_protocol/lib_protocol_vc2019.vcxproj @@ -304,7 +304,7 @@ NDEBUG;_LIB;ACL_DLL;HTTP_DLL;HTTP_EXPORTS;ICMP_DLL;ICMP_EXPORTS;SMTP_DLL;SMTP_EXPORTS;%(PreprocessorDefinitions) MultiThreadedDLL Use - $(ProjectName).pdb + $(IntDir)vc$(PlatformToolsetVersion).pdb ProgramDatabase false @@ -357,7 +357,7 @@ EnableFastChecks MultiThreadedDebugDLL Use - $(ProjectName)_d.pdb + $(IntDir)vc$(PlatformToolsetVersion).pdb ProgramDatabase false