Skip to content

Commit 9b8aaa6

Browse files
authored
[core] Fix some warnings when compiling with MinGW (#2868).
Removed duplicate declaration of SRT_API. Moved around variables to avoid set but not used warnings. Removed SRT_API attribute of SysStrError.
1 parent 618ddfe commit 9b8aaa6

File tree

5 files changed

+41
-80
lines changed

5 files changed

+41
-80
lines changed

srtcore/channel.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ modified by
5151
*****************************************************************************/
5252

5353
#include "platform_sys.h"
54-
5554
#include <iostream>
5655
#include <iomanip> // Logging
5756
#include <srt_compat.h>
@@ -189,6 +188,7 @@ void srt::CChannel::createSocket(int family)
189188
m_iSocket = ::socket(family, SOCK_DGRAM, IPPROTO_UDP);
190189
cloexec_flag = true;
191190
#endif
191+
192192
#else // ENABLE_SOCK_CLOEXEC
193193
m_iSocket = ::socket(family, SOCK_DGRAM, IPPROTO_UDP);
194194
#endif // ENABLE_SOCK_CLOEXEC
@@ -197,17 +197,18 @@ void srt::CChannel::createSocket(int family)
197197
throw CUDTException(MJ_SETUP, MN_NONE, NET_ERROR);
198198

199199
#if ENABLE_SOCK_CLOEXEC
200-
#ifdef _WIN32
201-
// XXX ::SetHandleInformation(hInputWrite, HANDLE_FLAG_INHERIT, 0)
202-
#else
200+
203201
if (cloexec_flag)
204202
{
203+
#ifdef _WIN32
204+
// XXX ::SetHandleInformation(hInputWrite, HANDLE_FLAG_INHERIT, 0)
205+
#else
205206
if (0 != set_cloexec(m_iSocket, 1))
206207
{
207208
throw CUDTException(MJ_SETUP, MN_NONE, NET_ERROR);
208209
}
210+
#endif //_WIN32
209211
}
210-
#endif
211212
#endif // ENABLE_SOCK_CLOEXEC
212213

213214
if ((m_mcfg.iIpV6Only != -1) && (family == AF_INET6)) // (not an error if it fails)
@@ -795,8 +796,8 @@ int srt::CChannel::sendto(const sockaddr_any& addr, CPacket& packet, const socka
795796
{
796797
if (NET_ERROR == WSA_IO_PENDING)
797798
{
798-
res = WSAWaitForMultipleEvents(1, &m_SendOverlapped.hEvent, TRUE, 100 /*ms*/, FALSE);
799-
if (res == WAIT_FAILED)
799+
DWORD res_wait = WSAWaitForMultipleEvents(1, &m_SendOverlapped.hEvent, TRUE, 100 /*ms*/, FALSE);
800+
if (res_wait == WAIT_FAILED)
800801
{
801802
LOGC(kslog.Warn, log << "CChannel::WSAWaitForMultipleEvents: failed with " << NET_ERROR);
802803
res = -1;

srtcore/platform_sys.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@
2121
//
2222
// SRT_IMPORT_TIME (mach time on Mac, portability gettimeofday on WIN32)
2323
// SRT_IMPORT_EVENT (includes kevent on Mac)
24+
#ifdef _WIN32
25+
#ifndef __MINGW32__
26+
// Explicitly define 32-bit and 64-bit numbers
27+
typedef __int32 int32_t;
28+
typedef __int64 int64_t;
29+
typedef unsigned __int32 uint32_t;
30+
#ifndef LEGACY_WIN32
31+
typedef unsigned __int64 uint64_t;
32+
#else
33+
// VC 6.0 does not support unsigned __int64: may cause potential problems.
34+
typedef __int64 uint64_t;
35+
#endif
36+
#endif
37+
#endif
2438

2539

2640
#ifdef _WIN32

srtcore/srt.h

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,28 @@ written by
1616
#ifndef INC_SRTC_H
1717
#define INC_SRTC_H
1818

19+
#ifndef SRT_API
20+
#ifdef _WIN32
21+
#ifdef SRT_DYNAMIC
22+
#ifdef SRT_EXPORTS
23+
#define SRT_API __declspec(dllexport)
24+
#else
25+
#define SRT_API __declspec(dllimport)
26+
#endif
27+
#else // !SRT_DYNAMIC
28+
#define SRT_API
29+
#endif
30+
#else
31+
#define SRT_API __attribute__ ((visibility("default")))
32+
#endif
33+
#endif
34+
1935
#include "version.h"
2036

2137
#include "platform_sys.h"
2238

39+
#include "srt_compat.h"
40+
2341
#include <string.h>
2442
#include <stdlib.h>
2543

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

36-
37-
#ifdef _WIN32
38-
#ifndef __MINGW32__
39-
// Explicitly define 32-bit and 64-bit numbers
40-
typedef __int32 int32_t;
41-
typedef __int64 int64_t;
42-
typedef unsigned __int32 uint32_t;
43-
#ifndef LEGACY_WIN32
44-
typedef unsigned __int64 uint64_t;
45-
#else
46-
// VC 6.0 does not support unsigned __int64: may cause potential problems.
47-
typedef __int64 uint64_t;
48-
#endif
49-
#endif
50-
#ifdef SRT_DYNAMIC
51-
#ifdef SRT_EXPORTS
52-
#define SRT_API __declspec(dllexport)
53-
#else
54-
#define SRT_API __declspec(dllimport)
55-
#endif
56-
#else // !SRT_DYNAMIC
57-
#define SRT_API
58-
#endif
59-
#else
60-
#define SRT_API __attribute__ ((visibility("default")))
61-
#endif
62-
63-
6454
// For feature tests if you need.
6555
// You can use these constants with SRTO_MINVERSION option.
6656
#define SRT_VERSION_FEAT_HSv5 0x010300

srtcore/srt_compat.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ written by
1717
// Prevents from misconfiguration through preprocessor.
1818

1919
#include "platform_sys.h"
20-
2120
#include <srt_compat.h>
2221

2322
#include <string.h>

srtcore/srt_compat.h

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,55 +20,12 @@ written by
2020
#include <stddef.h>
2121
#include <time.h>
2222

23-
#ifndef SRT_API
24-
#ifdef _WIN32
25-
#ifndef __MINGW32__
26-
#ifdef SRT_DYNAMIC
27-
#ifdef SRT_EXPORTS
28-
#define SRT_API __declspec(dllexport)
29-
#else
30-
#define SRT_API __declspec(dllimport)
31-
#endif
32-
#else
33-
#define SRT_API
34-
#endif
35-
#else
36-
#define SRT_API
37-
#endif
38-
#else
39-
#define SRT_API __attribute__ ((visibility("default")))
40-
#endif
41-
#endif
42-
43-
#ifdef _WIN32
44-
// https://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx
45-
// printf() Format for ssize_t
46-
#if !defined(PRIzd)
47-
#define PRIzd "Id"
48-
#endif
49-
// printf() Format for size_t
50-
#if !defined(PRIzu)
51-
#define PRIzu "Iu"
52-
#endif
53-
#else
54-
// http://www.gnu.org/software/libc/manual/html_node/Integer-Conversions.html
55-
// printf() Format for ssize_t
56-
#if !defined(PRIzd)
57-
#define PRIzd "zd"
58-
#endif
59-
// printf() Format for size_t
60-
#if !defined(PRIzu)
61-
#define PRIzu "zu"
62-
#endif
63-
#endif
64-
65-
6623
#ifdef __cplusplus
6724
extern "C" {
6825
#endif
6926

7027
/* Ensures that we store the error in the buffer and return the bufer. */
71-
SRT_API const char * SysStrError(int errnum, char * buf, size_t buflen);
28+
const char * SysStrError(int errnum, char * buf, size_t buflen);
7229

7330
#ifdef __cplusplus
7431
} // extern C

0 commit comments

Comments
 (0)