Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Fix some warnings when compiling with mingw #2868

Merged
merged 8 commits into from
Mar 7, 2024
16 changes: 9 additions & 7 deletions srtcore/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ modified by
*****************************************************************************/

#include "platform_sys.h"

#include <srt.h>
maxsharabayko marked this conversation as resolved.
Show resolved Hide resolved
#include <iostream>
#include <iomanip> // Logging
#include <srt_compat.h>
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -795,8 +797,8 @@ 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 = 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;
Expand Down
14 changes: 14 additions & 0 deletions srtcore/platform_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@
//
// SRT_IMPORT_TIME (mach time on Mac, portability gettimeofday on WIN32)
// SRT_IMPORT_EVENT (includes kevent on Mac)
#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
#endif


#ifdef _WIN32
Expand Down
46 changes: 18 additions & 28 deletions srtcore/srt.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,28 @@ written by
#ifndef INC_SRTC_H
#define INC_SRTC_H

#ifndef SRT_API
yomnes0 marked this conversation as resolved.
Show resolved Hide resolved
#ifdef _WIN32
#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

#include "version.h"

#include "platform_sys.h"

#include "srt_compat.h"

#include <string.h>
#include <stdlib.h>

Expand All @@ -33,34 +51,6 @@ written by
//if compiling with MinGW, it only works on XP or above
//use -D_WIN32_WINNT=0x0501


#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


// For feature tests if you need.
// You can use these constants with SRTO_MINVERSION option.
#define SRT_VERSION_FEAT_HSv5 0x010300
Expand Down
1 change: 0 additions & 1 deletion srtcore/srt_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ written by
// Prevents from misconfiguration through preprocessor.

#include "platform_sys.h"

#include <srt_compat.h>

#include <string.h>
Expand Down
45 changes: 1 addition & 44 deletions srtcore/srt_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,55 +20,12 @@ written by
#include <stddef.h>
#include <time.h>

#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
maxsharabayko marked this conversation as resolved.
Show resolved Hide resolved


#ifdef __cplusplus
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
Expand Down
Loading