Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Now compiles on Windows w/ MINGW 4.8 #3

Open
wants to merge 13 commits into
base: devel
Choose a base branch
from
2 changes: 1 addition & 1 deletion Essentials/pAntler/CMakeLists.txt
Expand Up @@ -4,7 +4,7 @@ set(EXECNAME pAntler)
find_package(MOOS 10)

#what files are needed?
SET(SRCS AntlerMain.cpp Antler.cpp)
SET(SRCS AntlerMain.cpp Antler.cpp XPCProcess.cpp XPCProcessAttrib.cpp)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the pull request! You saved me duplicating half the effort (half, until I realized someone else already did it!).

Just a comment: on this CMakeLists.txt file, I would rather add conditionally to be in WIN32, just in case it breaks UNIXes builds which seem to work as is...

IF (WIN32)
    SET(SRCS ${SRCS} XPCProcess.cpp XPCProcessAttrib.cpp)
ENDIF(WIN32)


include_directories( ${${EXECNAME}_INCLUDE_DIRS} ${MOOS_INCLUDE_DIRS} ${MOOS_DEPEND_INCLUDE_DIRS})
add_executable(${EXECNAME} ${SRCS} )
Expand Down
4 changes: 2 additions & 2 deletions Essentials/pLogger/MOOSLogger.cpp
Expand Up @@ -1031,7 +1031,7 @@ bool CMOOSLogger::CreateDirectory(const std::string & sDirectory)
{

#if _WIN32
int bOK = ::CreateDirectory(sDirectory.c_str(),NULL);
int bOK = ::CreateDirectoryA(sDirectory.c_str(),NULL);

if(!bOK)
{
Expand All @@ -1041,7 +1041,7 @@ bool CMOOSLogger::CreateDirectory(const std::string & sDirectory)
{

LPVOID lpMsgBuf;
FormatMessage(
FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
Expand Down
5 changes: 5 additions & 0 deletions Essentials/pLogger/MOOSLogger.h
Expand Up @@ -39,6 +39,11 @@
#include <string>
#include "Zipper.h"

#if _WIN32
#include <windows.h>
#include <winbase.h>
#endif // windows

typedef std::vector<std::string> STRING_VECTOR;

class CMOOSLogger : public CMOOSApp
Expand Down
19 changes: 13 additions & 6 deletions Essentials/pShare/Listener.cpp
Expand Up @@ -7,10 +7,17 @@
#ifndef _WIN32
#include "unistd.h"
#endif
#ifdef UNIX
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#elif _WIN32
#define _WIN32_WINNT 0x0600 //will only work with vista and above as XP does not support IPv6
#include <io.h>
#include <winsock2.h>
#include <Ws2tcpip.h>
#endif

#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string>
#include <cstring>
#include <stdexcept>
Expand Down Expand Up @@ -52,7 +59,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*/, (char *)&reuse, sizeof(reuse)) == -1)
throw std::runtime_error("Listener::ListenLoop::setsockopt::reuse");

/* if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEPORT,
Expand All @@ -63,7 +70,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, (char *)&rx_buffer_size, sizeof(rx_buffer_size)) == -1)
throw std::runtime_error("Listener::ListenLoop()::setsockopt::rcvbuf");


Expand Down Expand Up @@ -91,7 +98,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, (char *)&mreq, sizeof(mreq))==-1)
throw std::runtime_error("Listener::ListenLoop()::setsockopt::ADD_MEMBERSHIP");
}

Expand Down
37 changes: 26 additions & 11 deletions Essentials/pShare/Share.cpp
Expand Up @@ -4,9 +4,15 @@
* Created on: Aug 26, 2012
* Author: pnewman
*/
#include <ifaddrs.h>
#include <arpa/inet.h>
#include <netdb.h>
#ifdef UNIX
#include <ifaddrs.h>
#include <arpa/inet.h>
#include <netdb.h>
#elif _WIN32
// #define _WIN32_WINNT 0x0600 //will only work with vista and above as XP does not support IPv6
#include <winsock2.h>
#include <Ws2tcpip.h>
#endif

#include <map>
#include <stdexcept>
Expand Down Expand Up @@ -1021,7 +1027,7 @@ bool Share::Impl::ApplyRoutes(CMOOSMsg & msg)
}

//send here
if (sendto(relevant_socket.socket_fd, buffer.data(), buffer.size(), 0,
if (sendto(relevant_socket.socket_fd, (const char*)buffer.data(), buffer.size(), 0,
(struct sockaddr*) (&relevant_socket.sock_addr),
sizeof(relevant_socket.sock_addr)) < 0)
{
Expand Down Expand Up @@ -1066,7 +1072,7 @@ bool Share::Impl::AddOutputRoute(MOOS::IPV4Address address, bool multicast)

int reuse = 1;
if (setsockopt(new_socket.socket_fd, SOL_SOCKET, SO_REUSEADDR,
&reuse, sizeof(reuse)) == -1)
(char *)&reuse, sizeof(reuse)) == -1)
throw std::runtime_error("failed to set resuse socket option");
/*
if (setsockopt(new_socket.socket_fd, SOL_SOCKET, SO_REUSEPORT,
Expand All @@ -1076,7 +1082,7 @@ bool Share::Impl::AddOutputRoute(MOOS::IPV4Address address, bool multicast)
int send_buffer_size = 4 * 64 * 1024;
if (setsockopt(new_socket.socket_fd,
SOL_SOCKET, SO_SNDBUF,
&send_buffer_size,
(char *)&send_buffer_size,
sizeof(send_buffer_size)) == -1)
{
throw std::runtime_error("failed to set size of socket send buffer");
Expand All @@ -1101,11 +1107,20 @@ bool Share::Impl::AddOutputRoute(MOOS::IPV4Address address, bool multicast)

std::string dotted_ip = MOOS::IPV4Address::GetNumericAddress(new_socket.address.host());

if(inet_aton(dotted_ip.c_str(), &new_socket.sock_addr.sin_addr)==0)
{
throw std::runtime_error("failed to intepret "
+dotted_ip+" as an ip address");
}
#ifdef UNIX
if(inet_aton(dotted_ip.c_str(), &new_socket.sock_addr.sin_addr)==0)
{
throw std::runtime_error("failed to intepret "
+dotted_ip+" as an ip address");
}
#elif _WIN32
if( inet_pton(AF_INET,dotted_ip.c_str(), &new_socket.sock_addr.sin_addr)==0)
{
throw std::runtime_error("failed to intepret "
+dotted_ip+" as an ip address");
}
#endif


//new_socket.sock_addr.sin_addr.s_addr = inet_addr(new_socket.address.ip_num.c_str());
new_socket.sock_addr.sin_port = htons(new_socket.address.port());
Expand Down