Browse Source

Improve MSVC 2015 compatibility

pull/1892/head
Vort 1 year ago
parent
commit
64f0a545fd
  1. 18
      libi2pd/I2PEndian.h
  2. 2
      libi2pd/Streaming.cpp
  3. 31
      libi2pd/util.cpp
  4. 2
      libi2pd_client/HTTPProxy.cpp

18
libi2pd/I2PEndian.h

@ -36,6 +36,23 @@ @@ -36,6 +36,23 @@
#define le64toh(x) OSSwapLittleToHostInt64(x)
#elif defined(_WIN32)
#if defined(_MSC_VER)
#include <stdlib.h>
#define htobe16(x) _byteswap_ushort(x)
#define htole16(x) (x)
#define be16toh(x) _byteswap_ushort(x)
#define le16toh(x) (x)
#define htobe32(x) _byteswap_ulong(x)
#define htole32(x) (x)
#define be32toh(x) _byteswap_ulong(x)
#define le32toh(x) (x)
#define htobe64(x) _byteswap_uint64(x)
#define htole64(x) (x)
#define be64toh(x) _byteswap_uint64(x)
#define le64toh(x) (x)
#else
#define htobe16(x) __builtin_bswap16(x)
#define htole16(x) (x)
#define be16toh(x) __builtin_bswap16(x)
@ -50,6 +67,7 @@ @@ -50,6 +67,7 @@
#define htole64(x) (x)
#define be64toh(x) __builtin_bswap64(x)
#define le64toh(x) (x)
#endif
#else
#define NEEDS_LOCAL_ENDIAN

2
libi2pd/Streaming.cpp

@ -384,7 +384,7 @@ namespace stream @@ -384,7 +384,7 @@ namespace stream
memset (p.buf, 0, 22); // minimal header all zeroes
memcpy (p.buf + 4, packet->buf, 4); // but receiveStreamID is the sendStreamID from the ping
htobe16buf (p.buf + 18, PACKET_FLAG_ECHO); // and echo flag
ssize_t payloadLen = packet->len - (packet->GetPayload () - packet->buf);
auto payloadLen = int(packet->len) - (packet->GetPayload () - packet->buf);
if (payloadLen > 0)
memcpy (p.buf + 22, packet->GetPayload (), payloadLen);
else

31
libi2pd/util.cpp

@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
#include "Log.h"
#include "I2PEndian.h"
#if not defined (__FreeBSD__)
#if !defined (__FreeBSD__) && !defined(_MSC_VER)
#include <pthread.h>
#endif
@ -37,6 +37,19 @@ @@ -37,6 +37,19 @@
#include <iphlpapi.h>
#include <shlobj.h>
#if defined(_MSC_VER)
const DWORD MS_VC_EXCEPTION = 0x406D1388;
#pragma pack(push,8)
typedef struct tagTHREADNAME_INFO
{
DWORD dwType;
LPCSTR szName;
DWORD dwThreadID;
DWORD dwFlags;
} THREADNAME_INFO;
#pragma pack(pop)
#endif
#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
@ -162,7 +175,23 @@ namespace util @@ -162,7 +175,23 @@ namespace util
#elif defined(__NetBSD__)
pthread_setname_np(pthread_self(), "%s", (void *)name);
#elif !defined(__gnu_hurd__)
#if defined(_MSC_VER)
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = name;
info.dwThreadID = -1;
info.dwFlags = 0;
#pragma warning(push)
#pragma warning(disable: 6320 6322)
__try {
RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR*)&info);
}
__except (EXCEPTION_EXECUTE_HANDLER) {
}
#pragma warning(pop)
#else
pthread_setname_np(pthread_self(), name);
#endif
#endif
}

2
libi2pd_client/HTTPProxy.cpp

@ -113,7 +113,7 @@ namespace proxy { @@ -113,7 +113,7 @@ namespace proxy {
i2p::http::URL m_ProxyURL;
i2p::http::URL m_RequestURL;
uint8_t m_socks_buf[255+8]; // for socks request/response
ssize_t m_req_len;
int m_req_len;
i2p::http::URL m_ClientRequestURL;
i2p::http::HTTPReq m_ClientRequest;
i2p::http::HTTPRes m_ClientResponse;

Loading…
Cancel
Save