Skip to content

Commit e1e4709

Browse files
committed
Fix compile errors when NTDDI_VERSION not defined in mingw
1 parent c2919e4 commit e1e4709

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

yasio/compiler/feature_test.hpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,16 @@ SOFTWARE.
119119
# define YASIO__OS_BSD_LIKE 0
120120
#endif
121121

122+
#if !defined(_WIN32) || (defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_VISTA) || (defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0600)
123+
# define YASIO__OS_NT6 1
124+
#else
125+
# define YASIO__OS_NT6 0
126+
#endif
127+
122128
/// Tests multiplex io model of current OS
123129

124130
// poll
125-
#if !defined(_WIN32) || NTDDI_VERSION >= NTDDI_VISTA
131+
#if YASIO__OS_NT6
126132
# define YASIO__HAS_POLL 1
127133
#else
128134
# define YASIO__HAS_POLL 0
@@ -177,12 +183,18 @@ SOFTWARE.
177183
# define YASIO__HAS_SA_LEN 0
178184
#endif
179185

180-
#if !defined(_WIN32) || NTDDI_VERSION >= NTDDI_VISTA
186+
#if YASIO__OS_NT6
181187
# define YASIO__HAS_NTOP 1
182188
#else
183189
# define YASIO__HAS_NTOP 0
184190
#endif
185191

192+
#if defined(NTDDI_WIN10_RS2) && NTDDI_VERSION >= NTDDI_WIN10_RS2
193+
# define YASIO__OS_NT10_RS2 1
194+
#else
195+
# define YASIO__OS_NT10_RS2 0
196+
#endif
197+
186198
#if defined(_WIN32) && (!defined(WINAPI_FAMILY) || (WINAPI_FAMILY != WINAPI_FAMILY_APP)) && !defined(__MINGW64__) && !defined(__MINGW32__)
187199
# define YASIO__HAS_WIN32_TIMEAPI 1
188200
#else

yasio/xxsocket.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ unsigned int xxsocket::tcp_rtt() const { return xxsocket::tcp_rtt(this->fd); }
944944
unsigned int xxsocket::tcp_rtt(socket_native_type s)
945945
{
946946
#if defined(_WIN32)
947-
# if defined(NTDDI_WIN10_RS2) && NTDDI_VERSION >= NTDDI_WIN10_RS2
947+
# if YASIO__OS_NT10_RS2
948948
TCP_INFO_v0 info;
949949
DWORD tcpi_ver = 0, bytes_transferred = 0;
950950
int status = WSAIoctl(s, SIO_TCP_INFO,
@@ -1035,6 +1035,21 @@ const char* xxsocket::strerror_r(int error, char* buf, size_t buflen)
10351035
return buf;
10361036
}
10371037

1038+
void xxsocket::update_connect_context(socket_native_type s, std::error_code& ec)
1039+
{
1040+
#if defined(_WIN32)
1041+
if (!ec)
1042+
{
1043+
// Need to set the SO_UPDATE_CONNECT_CONTEXT option so that getsockname
1044+
// and getpeername will work on the connected socket.
1045+
// socket_ops::state_type state = 0;
1046+
const int so_update_connect_context = 0x7010;
1047+
if (xxsocket::set_optval(s, SOL_SOCKET, so_update_connect_context, nullptr, 0) < 0)
1048+
ec = std::error_code(::WSAGetLastError(), std::system_category());
1049+
}
1050+
#endif
1051+
}
1052+
10381053
const char* xxsocket::gai_strerror(int error)
10391054
{
10401055
#if defined(_WIN32)

yasio/xxsocket.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,8 @@ class YASIO_API xxsocket {
10661066
YASIO__DECL static const char* strerror_r(int error, char* buf, size_t buflen);
10671067
YASIO__DECL static const char* gai_strerror(int error);
10681068

1069+
YASIO__DECL static void update_connect_context(socket_native_type s, std::error_code& ec);
1070+
10691071
/// <summary>
10701072
/// Resolve both ipv4 and ipv6 address as-is
10711073
/// </summary>

0 commit comments

Comments
 (0)