From 09db0b350b359926c3c5c83eadd251c8d8bdfa39 Mon Sep 17 00:00:00 2001 From: IBN SEDDIK Mohamed Saad Date: Fri, 30 Aug 2013 14:55:18 +0200 Subject: [PATCH] Adding Windows Compatibility TODO: Check other OSes compatibility after adding necessary cast for setsockopt for Windows --- Essentials/pShare/Listener.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Essentials/pShare/Listener.cpp b/Essentials/pShare/Listener.cpp index a9c2e92..d84153f 100644 --- a/Essentials/pShare/Listener.cpp +++ b/Essentials/pShare/Listener.cpp @@ -5,12 +5,18 @@ * Author: pnewman */ #ifndef _WIN32 -#include "unistd.h" + #include "unistd.h" + #include + #include + #include +#else + #include + #include //for ip_mreq + #include "winbase.h" + #include "winnt.h" + #include "windows.h" #endif -#include -#include -#include #include #include #include @@ -52,7 +58,7 @@ bool Listener::ListenLoop() //we want to be able to resuse it (multiple folk are interested) int reuse = 1; - if (setsockopt(socket_fd, SOL_SOCKET,SO_REUSEADDR/* SO_REUSEPORT*/, &reuse, sizeof(reuse)) == -1) + if (setsockopt(socket_fd, SOL_SOCKET,SO_REUSEADDR/* SO_REUSEPORT*/, (const char*)&reuse, sizeof(reuse)) == -1) throw std::runtime_error("Listener::ListenLoop::setsockopt::reuse"); /* if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEPORT, @@ -63,7 +69,7 @@ bool Listener::ListenLoop() //give ourselves plenty of receive space //set aside some space for receiving - just a few multiples of 64K int rx_buffer_size = 64*1024*28; - if (setsockopt(socket_fd, SOL_SOCKET, SO_RCVBUF, &rx_buffer_size, sizeof(rx_buffer_size)) == -1) + if (setsockopt(socket_fd, SOL_SOCKET, SO_RCVBUF, (const char*)&rx_buffer_size, sizeof(rx_buffer_size)) == -1) throw std::runtime_error("Listener::ListenLoop()::setsockopt::rcvbuf"); @@ -91,7 +97,7 @@ bool Listener::ListenLoop() struct ip_mreq mreq; mreq.imr_multiaddr.s_addr = inet_addr(address_.host().c_str()); mreq.imr_interface.s_addr = INADDR_ANY; - if(setsockopt(socket_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq))==-1) + if(setsockopt(socket_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const char*)&mreq, sizeof(mreq))==-1) throw std::runtime_error("Listener::ListenLoop()::setsockopt::ADD_MEMBERSHIP"); }