From 29778d2efb390bab32d24e653c20088fef0aa730 Mon Sep 17 00:00:00 2001 From: vaguue Date: Sun, 18 Aug 2024 20:53:32 +0300 Subject: [PATCH] windows fixes --- CMakeLists.txt | 6 ++++++ cxx/transports/socket/Enums/Windows.cpp | 10 +++++----- cxx/transports/socket/InputPackets.cpp | 16 +++++++++------- cxx/transports/socket/Packets.cpp | 12 ++++++++---- cxx/transports/socket/Socket.cpp | 2 ++ 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index db03add..0b7e5fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,12 @@ include_directories(${CMAKE_JS_INC}) project (over-the-wire) +if (WIN32) + add_compile_options(/WX-) + add_definitions(-D_SILENCE_ALL_MS_EXT_DEPRECATION_WARNINGS=1) + message("Silencing MS warnings") +endif() + add_library(${PROJECT_NAME} SHARED ${CMAKE_JS_SRC}) target_include_directories(${PROJECT_NAME} PRIVATE "${NODE_ADDON_API_DIR}") target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/cxx") diff --git a/cxx/transports/socket/Enums/Windows.cpp b/cxx/transports/socket/Enums/Windows.cpp index 131859e..b1ca2f0 100644 --- a/cxx/transports/socket/Enums/Windows.cpp +++ b/cxx/transports/socket/Enums/Windows.cpp @@ -6,21 +6,21 @@ Napi::Object InitSystemLocal(Napi::Env env, Napi::Object exports) { ENUM_VALUE(AF_NETBIOS); ENUM_VALUE(AF_INET6); ENUM_VALUE(AF_IRDA); - ENUM_VALUE(AF_BTH) + ENUM_VALUE(AF_BTH); - ENUM_VALUE(SOCK_STREAM) + ENUM_VALUE(SOCK_STREAM); ENUM_VALUE(SOCK_DGRAM); - ENUM_VALUE(SOCK_RAW) + ENUM_VALUE(SOCK_RAW); ENUM_VALUE(SOCK_RDM); ENUM_VALUE(SOCK_SEQPACKET); ENUM_VALUE(IPPROTO_ICMP); ENUM_VALUE(IPPROTO_IGMP); - ENUM_VALUE(BTHPROTO_RFCOMM); + //ENUM_VALUE(BTHPROTO_RFCOMM); ENUM_VALUE(IPPROTO_TCP); ENUM_VALUE(IPPROTO_UDP); ENUM_VALUE(IPPROTO_ICMPV6); - ENUM_VALUE(IPPROTO_RM); + //ENUM_VALUE(IPPROTO_RM); ENUM_VALUE(IPPROTO_IP); ENUM_VALUE(IPPROTO_GGP); ENUM_VALUE(IPPROTO_IPV4); diff --git a/cxx/transports/socket/InputPackets.cpp b/cxx/transports/socket/InputPackets.cpp index d314cb3..7727d9a 100644 --- a/cxx/transports/socket/InputPackets.cpp +++ b/cxx/transports/socket/InputPackets.cpp @@ -23,16 +23,18 @@ void InputPacketsIterator::read() { #ifdef _WIN32 //TODO WSAOVERLAPPED ioOverlapped = { 0 }; - int bytes, result, flags = 0; + DWORD bytes = 0; + DWORD flags = 0; + int result; WSABUF buf; - buf.buf = new uint8_t[parent.bufSize]; + buf.buf = (char*)new uint8_t[parent.bufSize]; buf.len = parent.bufSize; if (parent.queryAddr) { - fromPtr = sockaddr_ptr_t{new sockaddr_storage}; + sockaddr_ptr_t fromPtr {(sockaddr*)(new sockaddr_storage)}; int from_len; memset(fromPtr.get(), 0, sizeof sockaddr_storage); - from_len = sizeof from; + from_len = sizeof sockaddr_storage; result = WSARecvFrom(parent.fd, (WSABUF*)&buf, 1, @@ -50,15 +52,15 @@ void InputPacketsIterator::read() { 1, &bytes, &flags, - ioOverlapped, - NULL) + &ioOverlapped, + NULL); } if (result == -1) { value.pErr = getSystemError(); isNull = true; delete buf.buf; } - value.pData.pBuf = std::make_pair(decltype(value.second.first.first){buf.buf}, result); + value.pData.pBuf = std::make_pair(decltype(value.second.first.first){(uint8_t*)buf.buf}, result); //TODO recvmmsg is way too hard to implenet here, so I save it for later #else msghdr h{}; diff --git a/cxx/transports/socket/Packets.cpp b/cxx/transports/socket/Packets.cpp index 008213c..7c74017 100644 --- a/cxx/transports/socket/Packets.cpp +++ b/cxx/transports/socket/Packets.cpp @@ -37,7 +37,10 @@ bool Packets::add(uint8_t* buf, size_t size, SockAddr* target) { addrs.push_back(std::move(addr)); } #ifdef _WIN32 - packets.emplace_back(size, buf); + WSABUF pkt; + pkt.len = size; + pkt.buf = (char*)buf; + packets.push_back(pkt); #else iovecs.emplace_back(); iovec* iovec = &iovecs.back(); @@ -58,7 +61,8 @@ bool Packets::add(uint8_t* buf, size_t size, SockAddr* target) { SendStatus Packets::send(SOCKET fd) { #ifdef _WIN32 - int bytes, result; + int result; + DWORD bytes; WSAOVERLAPPED ioOverlapped = { 0 }; if (connected) { assert(packets.size() == addrs.size()); @@ -73,7 +77,7 @@ SendStatus Packets::send(SOCKET fd) { &bytes, 0, &ioOverlapped, - flags); + NULL); } else { @@ -86,7 +90,7 @@ SendStatus Packets::send(SOCKET fd) { addr.first.get(), addr.second, &ioOverlapped, - flags); + NULL); } if (result == 0) { diff --git a/cxx/transports/socket/Socket.cpp b/cxx/transports/socket/Socket.cpp index 20f0738..ca9c226 100644 --- a/cxx/transports/socket/Socket.cpp +++ b/cxx/transports/socket/Socket.cpp @@ -209,6 +209,7 @@ Napi::Value Socket::getsockopt(const Napi::CallbackInfo& info) { Napi::Value Socket::ioctl(const Napi::CallbackInfo& info) { //TODO +/* checkLength(info, 2); int name = info[0].As().Int32Value(); int value = info[1].As().Int32Value(); @@ -222,6 +223,7 @@ Napi::Value Socket::ioctl(const Napi::CallbackInfo& info) { #else #endif +*/ return info.Env().Undefined(); }