Skip to content

Commit

Permalink
windows fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vaguue committed Aug 18, 2024
1 parent 2e8691a commit 29778d2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions cxx/transports/socket/Enums/Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 9 additions & 7 deletions cxx/transports/socket/InputPackets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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{};
Expand Down
12 changes: 8 additions & 4 deletions cxx/transports/socket/Packets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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());
Expand All @@ -73,7 +77,7 @@ SendStatus Packets::send(SOCKET fd) {
&bytes,
0,
&ioOverlapped,
flags);
NULL);

}
else {
Expand All @@ -86,7 +90,7 @@ SendStatus Packets::send(SOCKET fd) {
addr.first.get(),
addr.second,
&ioOverlapped,
flags);
NULL);
}

if (result == 0) {
Expand Down
2 changes: 2 additions & 0 deletions cxx/transports/socket/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Napi::Number>().Int32Value();
int value = info[1].As<Napi::Number>().Int32Value();
Expand All @@ -222,6 +223,7 @@ Napi::Value Socket::ioctl(const Napi::CallbackInfo& info) {
#else
#endif
*/
return info.Env().Undefined();
}

Expand Down

0 comments on commit 29778d2

Please sign in to comment.