From c830797d7e21b71293b41033b72ecfb6fa38473c Mon Sep 17 00:00:00 2001 From: yomnes Date: Fri, 9 Feb 2024 11:12:26 +0100 Subject: [PATCH 1/7] [core] Fix some warnings when compiling with mingw Removed duplicate declaration of SRT_API Moved around variables to avoid set but not used warnings --- srtcore/channel.cpp | 17 ++++++++++------- srtcore/srt.h | 3 ++- srtcore/srt_compat.c | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/srtcore/channel.cpp b/srtcore/channel.cpp index 0b448d681..4198558ee 100644 --- a/srtcore/channel.cpp +++ b/srtcore/channel.cpp @@ -51,7 +51,7 @@ modified by *****************************************************************************/ #include "platform_sys.h" - +#include "srt.h" #include #include // Logging #include @@ -189,6 +189,7 @@ void srt::CChannel::createSocket(int family) m_iSocket = ::socket(family, SOCK_DGRAM, IPPROTO_UDP); cloexec_flag = true; #endif + #else // ENABLE_SOCK_CLOEXEC m_iSocket = ::socket(family, SOCK_DGRAM, IPPROTO_UDP); #endif // ENABLE_SOCK_CLOEXEC @@ -197,17 +198,18 @@ void srt::CChannel::createSocket(int family) throw CUDTException(MJ_SETUP, MN_NONE, NET_ERROR); #if ENABLE_SOCK_CLOEXEC -#ifdef _WIN32 - // XXX ::SetHandleInformation(hInputWrite, HANDLE_FLAG_INHERIT, 0) -#else + if (cloexec_flag) { +#ifdef _WIN32 + // XXX ::SetHandleInformation(hInputWrite, HANDLE_FLAG_INHERIT, 0) +#else if (0 != set_cloexec(m_iSocket, 1)) { throw CUDTException(MJ_SETUP, MN_NONE, NET_ERROR); } +#endif //_WIN32 } -#endif #endif // ENABLE_SOCK_CLOEXEC if ((m_mcfg.iIpV6Only != -1) && (family == AF_INET6)) // (not an error if it fails) @@ -795,8 +797,9 @@ int srt::CChannel::sendto(const sockaddr_any& addr, CPacket& packet, const socka { if (NET_ERROR == WSA_IO_PENDING) { - res = WSAWaitForMultipleEvents(1, &m_SendOverlapped.hEvent, TRUE, 100 /*ms*/, FALSE); - if (res == WAIT_FAILED) + DWORD res_wait = 0; + res_wait = WSAWaitForMultipleEvents(1, &m_SendOverlapped.hEvent, TRUE, 100 /*ms*/, FALSE); + if (res_wait == WAIT_FAILED) { LOGC(kslog.Warn, log << "CChannel::WSAWaitForMultipleEvents: failed with " << NET_ERROR); res = -1; diff --git a/srtcore/srt.h b/srtcore/srt.h index 53b6fd274..87040649b 100644 --- a/srtcore/srt.h +++ b/srtcore/srt.h @@ -33,7 +33,7 @@ written by //if compiling with MinGW, it only works on XP or above //use -D_WIN32_WINNT=0x0501 - +#ifndef SRT_API #ifdef _WIN32 #ifndef __MINGW32__ // Explicitly define 32-bit and 64-bit numbers @@ -59,6 +59,7 @@ written by #else #define SRT_API __attribute__ ((visibility("default"))) #endif +#endif // For feature tests if you need. diff --git a/srtcore/srt_compat.c b/srtcore/srt_compat.c index fbf4859ae..cad00bf0c 100644 --- a/srtcore/srt_compat.c +++ b/srtcore/srt_compat.c @@ -17,7 +17,7 @@ written by // Prevents from misconfiguration through preprocessor. #include "platform_sys.h" - +#include "srt.h" #include #include From e4cf02662a1fcc391fcec690522c429dc01bd89b Mon Sep 17 00:00:00 2001 From: yomnes0 <127947185+yomnes0@users.noreply.github.com> Date: Mon, 12 Feb 2024 16:57:51 +0100 Subject: [PATCH 2/7] [core] Merged initialization and assignation of res_wait Co-authored-by: Maxim Sharabayko --- srtcore/channel.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/srtcore/channel.cpp b/srtcore/channel.cpp index 4198558ee..eba621a2c 100644 --- a/srtcore/channel.cpp +++ b/srtcore/channel.cpp @@ -797,8 +797,7 @@ int srt::CChannel::sendto(const sockaddr_any& addr, CPacket& packet, const socka { if (NET_ERROR == WSA_IO_PENDING) { - DWORD res_wait = 0; - res_wait = WSAWaitForMultipleEvents(1, &m_SendOverlapped.hEvent, TRUE, 100 /*ms*/, FALSE); + DWORD res_wait = WSAWaitForMultipleEvents(1, &m_SendOverlapped.hEvent, TRUE, 100 /*ms*/, FALSE); if (res_wait == WAIT_FAILED) { LOGC(kslog.Warn, log << "CChannel::WSAWaitForMultipleEvents: failed with " << NET_ERROR); From 0bc5fa2cc05e66c75aa0353c1aaa717bace12834 Mon Sep 17 00:00:00 2001 From: yomnes Date: Mon, 26 Feb 2024 10:55:00 +0100 Subject: [PATCH 3/7] [core] Moved declaration of SRT_API from srt.h to platform_sys.h --- srtcore/channel.cpp | 1 - srtcore/platform_sys.h | 27 ++++++++++++++++++++++++++ srtcore/srt.h | 31 ++---------------------------- srtcore/srt_compat.c | 1 - srtcore/srt_compat.h | 43 ------------------------------------------ 5 files changed, 29 insertions(+), 74 deletions(-) diff --git a/srtcore/channel.cpp b/srtcore/channel.cpp index 4198558ee..4a35af38e 100644 --- a/srtcore/channel.cpp +++ b/srtcore/channel.cpp @@ -51,7 +51,6 @@ modified by *****************************************************************************/ #include "platform_sys.h" -#include "srt.h" #include #include // Logging #include diff --git a/srtcore/platform_sys.h b/srtcore/platform_sys.h index e2f0aa4d9..361d2abcb 100644 --- a/srtcore/platform_sys.h +++ b/srtcore/platform_sys.h @@ -21,6 +21,33 @@ // // SRT_IMPORT_TIME (mach time on Mac, portability gettimeofday on WIN32) // SRT_IMPORT_EVENT (includes kevent on Mac) +#ifndef SRT_API +#ifdef _WIN32 + #ifndef __MINGW32__ + // Explicitly define 32-bit and 64-bit numbers + typedef __int32 int32_t; + typedef __int64 int64_t; + typedef unsigned __int32 uint32_t; + #ifndef LEGACY_WIN32 + typedef unsigned __int64 uint64_t; + #else + // VC 6.0 does not support unsigned __int64: may cause potential problems. + typedef __int64 uint64_t; + #endif + #endif + #ifdef SRT_DYNAMIC + #ifdef SRT_EXPORTS + #define SRT_API __declspec(dllexport) + #else + #define SRT_API __declspec(dllimport) + #endif + #else // !SRT_DYNAMIC + #define SRT_API + #endif +#else + #define SRT_API __attribute__ ((visibility("default"))) +#endif +#endif #ifdef _WIN32 diff --git a/srtcore/srt.h b/srtcore/srt.h index 87040649b..118ab1e1c 100644 --- a/srtcore/srt.h +++ b/srtcore/srt.h @@ -20,6 +20,8 @@ written by #include "platform_sys.h" +#include "srt_compat.h" + #include #include @@ -33,35 +35,6 @@ written by //if compiling with MinGW, it only works on XP or above //use -D_WIN32_WINNT=0x0501 -#ifndef SRT_API -#ifdef _WIN32 - #ifndef __MINGW32__ - // Explicitly define 32-bit and 64-bit numbers - typedef __int32 int32_t; - typedef __int64 int64_t; - typedef unsigned __int32 uint32_t; - #ifndef LEGACY_WIN32 - typedef unsigned __int64 uint64_t; - #else - // VC 6.0 does not support unsigned __int64: may cause potential problems. - typedef __int64 uint64_t; - #endif - #endif - #ifdef SRT_DYNAMIC - #ifdef SRT_EXPORTS - #define SRT_API __declspec(dllexport) - #else - #define SRT_API __declspec(dllimport) - #endif - #else // !SRT_DYNAMIC - #define SRT_API - #endif -#else - #define SRT_API __attribute__ ((visibility("default"))) -#endif -#endif - - // For feature tests if you need. // You can use these constants with SRTO_MINVERSION option. #define SRT_VERSION_FEAT_HSv5 0x010300 diff --git a/srtcore/srt_compat.c b/srtcore/srt_compat.c index cad00bf0c..bbdf7f795 100644 --- a/srtcore/srt_compat.c +++ b/srtcore/srt_compat.c @@ -17,7 +17,6 @@ written by // Prevents from misconfiguration through preprocessor. #include "platform_sys.h" -#include "srt.h" #include #include diff --git a/srtcore/srt_compat.h b/srtcore/srt_compat.h index 960c1b85a..2dccb6765 100644 --- a/srtcore/srt_compat.h +++ b/srtcore/srt_compat.h @@ -20,49 +20,6 @@ written by #include #include -#ifndef SRT_API -#ifdef _WIN32 - #ifndef __MINGW32__ - #ifdef SRT_DYNAMIC - #ifdef SRT_EXPORTS - #define SRT_API __declspec(dllexport) - #else - #define SRT_API __declspec(dllimport) - #endif - #else - #define SRT_API - #endif - #else - #define SRT_API - #endif -#else - #define SRT_API __attribute__ ((visibility("default"))) -#endif -#endif - -#ifdef _WIN32 - // https://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx - // printf() Format for ssize_t - #if !defined(PRIzd) - #define PRIzd "Id" - #endif - // printf() Format for size_t - #if !defined(PRIzu) - #define PRIzu "Iu" - #endif -#else - // http://www.gnu.org/software/libc/manual/html_node/Integer-Conversions.html - // printf() Format for ssize_t - #if !defined(PRIzd) - #define PRIzd "zd" - #endif - // printf() Format for size_t - #if !defined(PRIzu) - #define PRIzu "zu" - #endif -#endif - - #ifdef __cplusplus extern "C" { #endif From eec3cda21c102a40d762f540bcccda0eea09256e Mon Sep 17 00:00:00 2001 From: yomnes0 Date: Tue, 5 Mar 2024 14:11:34 +0100 Subject: [PATCH 4/7] [core] Move SRT_API definition to srt.h Add srt.h include where needed --- srtcore/channel.cpp | 1 + srtcore/platform_sys.h | 13 ------------- srtcore/srt.h | 15 +++++++++++++++ srtcore/srt_compat.c | 1 + 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/srtcore/channel.cpp b/srtcore/channel.cpp index 4e3ebdcae..b203c29b6 100644 --- a/srtcore/channel.cpp +++ b/srtcore/channel.cpp @@ -51,6 +51,7 @@ modified by *****************************************************************************/ #include "platform_sys.h" +#include #include #include // Logging #include diff --git a/srtcore/platform_sys.h b/srtcore/platform_sys.h index 361d2abcb..83763e5ea 100644 --- a/srtcore/platform_sys.h +++ b/srtcore/platform_sys.h @@ -21,7 +21,6 @@ // // SRT_IMPORT_TIME (mach time on Mac, portability gettimeofday on WIN32) // SRT_IMPORT_EVENT (includes kevent on Mac) -#ifndef SRT_API #ifdef _WIN32 #ifndef __MINGW32__ // Explicitly define 32-bit and 64-bit numbers @@ -35,18 +34,6 @@ typedef __int64 uint64_t; #endif #endif - #ifdef SRT_DYNAMIC - #ifdef SRT_EXPORTS - #define SRT_API __declspec(dllexport) - #else - #define SRT_API __declspec(dllimport) - #endif - #else // !SRT_DYNAMIC - #define SRT_API - #endif -#else - #define SRT_API __attribute__ ((visibility("default"))) -#endif #endif diff --git a/srtcore/srt.h b/srtcore/srt.h index 118ab1e1c..57a3062e6 100644 --- a/srtcore/srt.h +++ b/srtcore/srt.h @@ -16,6 +16,21 @@ written by #ifndef INC_SRTC_H #define INC_SRTC_H +#ifndef SRT_API + + #ifdef SRT_DYNAMIC + #ifdef SRT_EXPORTS + #define SRT_API __declspec(dllexport) + #else + #define SRT_API __declspec(dllimport) + #endif + #else // !SRT_DYNAMIC + #define SRT_API + #endif +#else + #define SRT_API __attribute__ ((visibility("default"))) +#endif + #include "version.h" #include "platform_sys.h" diff --git a/srtcore/srt_compat.c b/srtcore/srt_compat.c index bbdf7f795..bca44a13d 100644 --- a/srtcore/srt_compat.c +++ b/srtcore/srt_compat.c @@ -17,6 +17,7 @@ written by // Prevents from misconfiguration through preprocessor. #include "platform_sys.h" +#include #include #include From b952bb629526828b7586bb3f3904e2b5ceaf2b9f Mon Sep 17 00:00:00 2001 From: yomnes0 Date: Tue, 5 Mar 2024 15:47:16 +0100 Subject: [PATCH 5/7] [core] Fix build for other os than windows --- srtcore/srt.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/srtcore/srt.h b/srtcore/srt.h index 57a3062e6..3c60f3086 100644 --- a/srtcore/srt.h +++ b/srtcore/srt.h @@ -17,7 +17,7 @@ written by #define INC_SRTC_H #ifndef SRT_API - +#ifdef _WIN32 #ifdef SRT_DYNAMIC #ifdef SRT_EXPORTS #define SRT_API __declspec(dllexport) @@ -30,6 +30,7 @@ written by #else #define SRT_API __attribute__ ((visibility("default"))) #endif +#endif #include "version.h" From 886b7e4efd1bea032fa8536d6f460f2d2df3d6a4 Mon Sep 17 00:00:00 2001 From: yomnes0 Date: Thu, 7 Mar 2024 10:57:31 +0100 Subject: [PATCH 6/7] [core] Removed SRT_API attribute of SysStrError --- srtcore/srt_compat.c | 1 - srtcore/srt_compat.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/srtcore/srt_compat.c b/srtcore/srt_compat.c index bca44a13d..bbdf7f795 100644 --- a/srtcore/srt_compat.c +++ b/srtcore/srt_compat.c @@ -17,7 +17,6 @@ written by // Prevents from misconfiguration through preprocessor. #include "platform_sys.h" -#include #include #include diff --git a/srtcore/srt_compat.h b/srtcore/srt_compat.h index 2dccb6765..d4fd2361e 100644 --- a/srtcore/srt_compat.h +++ b/srtcore/srt_compat.h @@ -25,7 +25,7 @@ extern "C" { #endif /* Ensures that we store the error in the buffer and return the bufer. */ -SRT_API const char * SysStrError(int errnum, char * buf, size_t buflen); +const char * SysStrError(int errnum, char * buf, size_t buflen); #ifdef __cplusplus } // extern C From 55c028cbc08a76e648f1adefc49f5abddd067192 Mon Sep 17 00:00:00 2001 From: yomnes0 Date: Thu, 7 Mar 2024 15:54:05 +0100 Subject: [PATCH 7/7] [build] Remove useless include --- srtcore/channel.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/srtcore/channel.cpp b/srtcore/channel.cpp index b203c29b6..4e3ebdcae 100644 --- a/srtcore/channel.cpp +++ b/srtcore/channel.cpp @@ -51,7 +51,6 @@ modified by *****************************************************************************/ #include "platform_sys.h" -#include #include #include // Logging #include