Skip to content

Commit

Permalink
Fixed C deprecated enum support. Added C++03 support for examples (#997)
Browse files Browse the repository at this point in the history
* Fixed deprecated option declarations to work in C mode
* Fixed old compiler support. Fixed no-C++11 support for examples
  • Loading branch information
ethouris authored and rndi committed Dec 6, 2019
1 parent 596c7fc commit 3838fbf
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 18 deletions.
11 changes: 7 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ macro(srt_make_application name)
endif()

# We state that Darwin always uses CLANG compiler, which honors this flag the same way.
set_target_properties(${name} PROPERTIES COMPILE_FLAGS "${CFLAGS_CXX_STANDARD} ${EXTRA_stransmit}" ${FORCE_RPATH})
set_target_properties(${name} PROPERTIES COMPILE_FLAGS "${CFLAGS_CXX_STANDARD}" ${FORCE_RPATH})

target_link_libraries(${name} ${srt_link_library})
if (USE_GNUSTL)
Expand Down Expand Up @@ -878,6 +878,9 @@ if (ENABLE_APPS)
# Applications

srt_add_application(srt-live-transmit ${VIRTUAL_srtsupport})
if (DEFINED EXTRA_stransmit)
set_target_properties(srt-live-transmit PROPERTIES COMPILE_FLAGS "${EXTRA_stransmit}")
endif()
srt_add_application(srt-file-transmit ${VIRTUAL_srtsupport})

if (MINGW)
Expand Down Expand Up @@ -940,13 +943,13 @@ if (ENABLE_EXAMPLES)
srt_add_program(${name} examples/${mainsrc} ${ARGN})
endmacro()

srt_add_example(sendfile.cpp apps/logsupport.cpp)
srt_add_example(sendfile.cpp)
srt_make_application(sendfile)

srt_add_example(recvfile.cpp apps/logsupport.cpp)
srt_add_example(recvfile.cpp)
srt_make_application(recvfile)

srt_add_example(recvlive.cpp apps/logsupport.cpp)
srt_add_example(recvlive.cpp)
srt_make_application(recvlive)

srt_add_example(test-c-client.c)
Expand Down
4 changes: 2 additions & 2 deletions examples/recvlive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int main(int argc, char* argv[])
// use this function to initialize the UDT library
srt_startup();

srt_setloglevel(logging::LogLevel::debug);
srt_setloglevel(srt_logging::LogLevel::debug);

addrinfo hints;
addrinfo* res;
Expand Down Expand Up @@ -110,7 +110,7 @@ int main(int argc, char* argv[])
return 0;
}

constexpr int srtrfdslenmax = 100;
const int srtrfdslenmax = 100;
SRTSOCKET srtrfds[srtrfdslenmax];
char data[1500];

Expand Down
53 changes: 41 additions & 12 deletions srtcore/srt.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,20 @@ written by
// When compiling in C++17 mode, use the standard C++17 attributes
// (out of these, only [[deprecated]] is supported in C++14, so
// for all lesser standard use compiler-specific attributes).
#if defined(__cplusplus) && __cplusplus > 201406
#if defined(SRT_NO_DEPRECATED)

#define SRT_ATR_UNUSED
#define SRT_ATR_DEPRECATED
#define SRT_ATR_NODISCARD

#elif defined(__cplusplus) && __cplusplus > 201406

#define SRT_ATR_UNUSED [[maybe_unused]]
#define SRT_ATR_DEPRECATED [[deprecated]]
#define SRT_ATR_NODISCARD [[nodiscard]]

// GNUG is GNU C++; this syntax is also supported by Clang
#elif defined( __GNUG__)
// GNUG is GNU C/C++; this syntax is also supported by Clang
#elif defined( __GNUC__)
#define SRT_ATR_UNUSED __attribute__((unused))
#define SRT_ATR_DEPRECATED __attribute__((deprecated))
#define SRT_ATR_NODISCARD __attribute__((warn_unused_result))
Expand Down Expand Up @@ -185,6 +192,27 @@ typedef enum SRT_SOCKOPT {
SRTO_PACKETFILTER = 60 // Add and configure a packet filter
} SRT_SOCKOPT;


#ifdef __cplusplus

typedef SRT_ATR_DEPRECATED SRT_SOCKOPT SRT_SOCKOPT_DEPRECATED;
#define SRT_DEPRECATED_OPTION(value) ((SRT_SOCKOPT_DEPRECATED)value)

#else

// deprecated enum labels are supported only since gcc 6, so in C there
// will be a whole deprecated enum type, as it's not an error in C to mix
// enum types
enum SRT_ATR_DEPRECATED SRT_SOCKOPT_DEPRECATED
{

// Dummy last option, as every entry ends with a comma
SRTO_DEPRECATED_END = 0

};
#define SRT_DEPRECATED_OPTION(value) ((enum SRT_SOCKOPT_DEPRECATED)value)
#endif

// DEPRECATED OPTIONS:

// SRTO_TWOWAYDATA: not to be used. SRT connection is always bidirectional if
Expand All @@ -194,36 +222,37 @@ typedef enum SRT_SOCKOPT {
// differences between bidirectional support (especially concerning encryption)
// with HSv4 and HSv5 (that is, HSv4 was decided to remain unidirectional only,
// even though partial support is already provided in this version).
static const SRT_SOCKOPT SRTO_TWOWAYDATA SRT_ATR_DEPRECATED = (SRT_SOCKOPT)37;

#define SRTO_TWOWAYDATA SRT_DEPRECATED_OPTION(37)

// This has been deprecated a long time ago, treat this as never implemented.
// The value is also already reused for another option.
static const SRT_SOCKOPT SRTO_TSBPDMAXLAG SRT_ATR_DEPRECATED = (SRT_SOCKOPT)32;
#define SRTO_TSBPDMAXLAG SRT_DEPRECATED_OPTION(32)

// This option is a derivative from UDT; the mechanism that uses it is now
// settable by SRTO_CONGESTION, or more generally by SRTO_TRANSTYPE. The freed
// number has been reused for a read-only option SRTO_ISN. This option should
// have never been used anywhere, just for safety this is temporarily declared
// as deprecated.
static const SRT_SOCKOPT SRTO_CC SRT_ATR_DEPRECATED = (SRT_SOCKOPT)3;
#define SRTO_CC SRT_DEPRECATED_OPTION(3)

// These two flags were derived from UDT, but they were never used.
// Probably it didn't make sense anyway. The maximum size of the message
// in File/Message mode is defined by SRTO_SNDBUF, and the MSGTTL is
// a parameter used in `srt_sendmsg` and `srt_sendmsg2`.
static const SRT_SOCKOPT SRTO_MAXMSG SRT_ATR_DEPRECATED = (SRT_SOCKOPT)10;
static const SRT_SOCKOPT SRTO_MSGTTL SRT_ATR_DEPRECATED = (SRT_SOCKOPT)11;
#define SRTO_MAXMSG SRT_DEPRECATED_OPTION(10)
#define SRTO_MSGTTL SRT_DEPRECATED_OPTION(11)

// These flags come from an older experimental implementation of bidirectional
// encryption support, which were used two different SEKs, KEKs and passphrases
// per direction. The current implementation uses just one in both directions,
// so SRTO_PBKEYLEN should be used for both cases.
static const SRT_SOCKOPT SRTO_SNDPBKEYLEN SRT_ATR_DEPRECATED = (SRT_SOCKOPT)38;
static const SRT_SOCKOPT SRTO_RCVPBKEYLEN SRT_ATR_DEPRECATED = (SRT_SOCKOPT)39;
#define SRTO_SNDPBKEYLEN SRT_DEPRECATED_OPTION(38)
#define SRTO_RCVPBKEYLEN SRT_DEPRECATED_OPTION(39)

// Keeping old name for compatibility (deprecated)
static const SRT_SOCKOPT SRTO_SMOOTHER SRT_ATR_DEPRECATED = SRTO_CONGESTION;
static const SRT_SOCKOPT SRTO_STRICTENC SRT_ATR_DEPRECATED = SRTO_ENFORCEDENCRYPTION;
#define SRTO_SMOOTHER SRT_DEPRECATED_OPTION(47)
#define SRTO_STRICTENC SRT_DEPRECATED_OPTION(53)

typedef enum SRT_TRANSTYPE
{
Expand Down

0 comments on commit 3838fbf

Please sign in to comment.