Skip to content

Commit

Permalink
Fix setsockopt error and NOMINMAX define warning
Browse files Browse the repository at this point in the history
  • Loading branch information
AnHeuermann authored and AnHeuermann committed Dec 1, 2021
1 parent e803cec commit 07d5353
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
10 changes: 8 additions & 2 deletions common/Communication/TLMClientComm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ using std::string;
#include <arpa/inet.h>
#else
#include <winsock2.h>
#define NOMINMAX
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#include <cassert>
#include <io.h>
Expand Down Expand Up @@ -210,8 +212,12 @@ int TLMClientComm::ConnectManager(string& callname, int portnr) {
TLMErrorLog::Info("TLM manager host found, trying to connect...");
}

#ifdef WIN32
const char val = 1;
#else
int val = 1;
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(int));
#endif
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));

count = 0;

Expand Down
2 changes: 1 addition & 1 deletion common/Communication/TLMCommUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#if defined(WIN32) || defined(__MINGW32__)
#include <winsock2.h>
#if !defined(NOMINMAX)
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
Expand Down
10 changes: 8 additions & 2 deletions common/Communication/TLMManagerComm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ using std::string;
#define BCloseSocket close
#else
#include <winsock2.h>
#define NOMINMAX
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#include <cassert>
#include <io.h>
Expand Down Expand Up @@ -71,8 +73,12 @@ int TLMManagerComm::CreateServerSocket() {
return -1;
}

#ifdef WIN32
const char val = 1;
#else
int val = 1;
setsockopt(theSckt, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(int));
#endif
setsockopt(theSckt, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));

int bindCount = 0;
int maxIterations = 1000; // BUG: should be calculated from a max. port range!
Expand Down
10 changes: 8 additions & 2 deletions common/OMTLMSimulatorLib/OMTLMSimulatorLib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
#define BCloseSocket close
#else
#include <winsock2.h>
#define NOMINMAX
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#include <cassert>
#include <io.h>
Expand Down Expand Up @@ -1315,8 +1317,12 @@ void omtlm_checkPortAvailability(int *port) {
return;
}

#ifdef WIN32
const char val = 1;
#else
int val = 1;
setsockopt(theSckt, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(int));
#endif
setsockopt(theSckt, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));

int bindCount = 0;
int maxIterations = 1000; // BUG: should be calculated from a max. port range!
Expand Down
4 changes: 3 additions & 1 deletion common/OMTLMSimulatorMain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include <fstream>
#include <sstream>
#ifdef _WIN32
#define NOMINMAX
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#endif

Expand Down

0 comments on commit 07d5353

Please sign in to comment.