Merge pull request #142 from eliteraspberries/build-apple
Build on macOS
This commit is contained in:
commit
6b7e88d5d5
|
@ -154,6 +154,24 @@ if (DISABLE_CRYPTO)
|
|||
endif()
|
||||
|
||||
if (UNIX)
|
||||
# Check if platform-specific functions exist
|
||||
include(CheckCXXSymbolExists)
|
||||
check_cxx_symbol_exists(getrandom sys/random.h HAVE_GETRANDOM)
|
||||
check_cxx_symbol_exists(sendmsg sys/socket.h HAVE_SENDMSG)
|
||||
check_cxx_symbol_exists(sendmmsg sys/socket.h HAVE_SENDMMSG)
|
||||
|
||||
if(HAVE_GETRANDOM)
|
||||
list(APPEND UVGRTP_CXX_FLAGS "-DUVGRTP_HAVE_GETRANDOM=1")
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE UVGRTP_HAVE_GETRANDOM=1)
|
||||
endif()
|
||||
if(HAVE_SENDMSG)
|
||||
list(APPEND UVGRTP_CXX_FLAGS "-DUVGRTP_HAVE_SENDMSG=1")
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE UVGRTP_HAVE_SENDMSG=1)
|
||||
endif()
|
||||
if(HAVE_SENDMMSG)
|
||||
list(APPEND UVGRTP_CXX_FLAGS "-DUVGRTP_HAVE_SENDMMSG=1")
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE UVGRTP_HAVE_SENDMMSG=1)
|
||||
endif()
|
||||
|
||||
# Try finding if pkg-config installed in the system
|
||||
find_package(PkgConfig REQUIRED)
|
||||
|
@ -188,16 +206,12 @@ if (UNIX)
|
|||
else()
|
||||
message("pkg-config not found. Not generating pc file")
|
||||
endif(PkgConfig_FOUND)
|
||||
|
||||
# Check the getrandom() function exists
|
||||
include(CheckCXXSymbolExists)
|
||||
check_cxx_symbol_exists(getrandom sys/random.h HAVE_GETRANDOM)
|
||||
|
||||
if(HAVE_GETRANDOM)
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_GETRANDOM=1)
|
||||
endif()
|
||||
endif (UNIX)
|
||||
|
||||
if(APPLE)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE "-framework Security")
|
||||
endif()
|
||||
|
||||
add_subdirectory(test EXCLUDE_FROM_ALL)
|
||||
|
||||
#
|
||||
|
|
|
@ -22,6 +22,28 @@ namespace uvgrtp {
|
|||
typedef unsigned int socklen_t;
|
||||
#endif
|
||||
|
||||
#if defined(UVGRTP_HAVE_SENDMSG) && !defined(UVGRTP_HAVE_SENDMMSG)
|
||||
struct mmsghdr {
|
||||
struct msghdr msg_hdr;
|
||||
unsigned int msg_len;
|
||||
};
|
||||
static inline
|
||||
int sendmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
|
||||
int flags)
|
||||
{
|
||||
ssize_t n = 0;
|
||||
for (unsigned int i = 0; i < vlen; i++) {
|
||||
ssize_t ret = sendmsg(sockfd, &msgvec[i].msg_hdr, flags);
|
||||
if (ret < 0)
|
||||
break;
|
||||
n += ret;
|
||||
}
|
||||
if (n == 0)
|
||||
return -1;
|
||||
return n;
|
||||
}
|
||||
#endif
|
||||
|
||||
const int MAX_BUFFER_COUNT = 256;
|
||||
|
||||
/* Vector of buffers that contain a full RTP frame */
|
||||
|
|
|
@ -2,18 +2,20 @@
|
|||
|
||||
#include "uvgrtp/debug.hh"
|
||||
|
||||
#ifdef _WIN32
|
||||
#if defined(UVGRTP_HAVE_GETRANDOM)
|
||||
#include <sys/random.h>
|
||||
#elif defined(_WIN32)
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
#else // non _WIN32
|
||||
#ifdef HAVE_GETRANDOM
|
||||
#include <sys/random.h>
|
||||
#else // HAVE_GETRANDOM
|
||||
#elif defined(__APPLE__)
|
||||
#include <Security/SecRandom.h>
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#include <sys/syscall.h>
|
||||
#endif // HAVE_GETRANDOM
|
||||
#endif // _WIN32
|
||||
#endif
|
||||
|
||||
|
||||
#include <cstdlib>
|
||||
|
@ -31,10 +33,11 @@ rtp_error_t uvgrtp::random::init()
|
|||
|
||||
int uvgrtp::random::generate(void *buf, size_t n)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
#ifdef HAVE_GETRANDOM
|
||||
#if defined(UVGRTP_HAVE_GETRANDOM)
|
||||
|
||||
return getrandom(buf, n, 0);
|
||||
#else
|
||||
|
||||
#elif defined(SYS_getrandom)
|
||||
|
||||
// Replace with the syscall
|
||||
int read = syscall(SYS_getrandom, buf, n, 0);
|
||||
|
@ -51,8 +54,8 @@ int uvgrtp::random::generate(void *buf, size_t n)
|
|||
}
|
||||
|
||||
return read;
|
||||
#endif // HAVE_GETRANDOM
|
||||
#else
|
||||
|
||||
#elif defined(_WIN32)
|
||||
|
||||
if (n > UINT32_MAX)
|
||||
{
|
||||
|
@ -69,7 +72,17 @@ int uvgrtp::random::generate(void *buf, size_t n)
|
|||
return res ? 0 : -1;
|
||||
}
|
||||
return -1;
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
int status = SecRandomCopyBytes(kSecRandomDefault, n, buf);
|
||||
if (status == errSecSuccess)
|
||||
return n;
|
||||
return -1;
|
||||
|
||||
#endif
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t uvgrtp::random::generate_32()
|
||||
|
|
Loading…
Reference in New Issue