Skip to content

Commit bc8d52e

Browse files
committed
Set SO_REUSEADDR for network socket in multi-instance.
1 parent 0c2375e commit bc8d52e

File tree

2 files changed

+26
-0
lines changed
  • GeneralsMD/Code/GameEngine/Source/GameNetwork
  • Generals/Code/GameEngine/Source/GameNetwork

2 files changed

+26
-0
lines changed

Generals/Code/GameEngine/Source/GameNetwork/udp.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "Common/GameEngine.h"
3535
//#include "GameNetwork/NetworkInterface.h"
3636
#include "GameNetwork/udp.h"
37+
#include "GameClient/ClientInstance.h"
3738

3839

3940
//-------------------------------------------------------------------------
@@ -164,6 +165,18 @@ Int UDP::Bind(UnsignedInt IP,UnsignedShort Port)
164165
if (fd==-1)
165166
return(UNKNOWN);
166167

168+
#if defined (RTS_MULTI_INSTANCE)
169+
// set SO_REUSEADDR so multiple instances can bind to the same port
170+
const Int val = TRUE;
171+
retval = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&val, sizeof(Int));
172+
if (retval == SOCKET_ERROR)
173+
{
174+
m_lastError = WSAGetLastError();
175+
status = GetStatus();
176+
return status;
177+
}
178+
#endif
179+
167180
retval=bind(fd,(struct sockaddr *)&addr,sizeof(addr));
168181

169182
#ifdef _WINDOWS

GeneralsMD/Code/GameEngine/Source/GameNetwork/udp.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "Common/GameEngine.h"
3535
//#include "GameNetwork/NetworkInterface.h"
3636
#include "GameNetwork/udp.h"
37+
#include "GameClient/ClientInstance.h"
3738

3839

3940
//-------------------------------------------------------------------------
@@ -164,6 +165,18 @@ Int UDP::Bind(UnsignedInt IP,UnsignedShort Port)
164165
if (fd==-1)
165166
return(UNKNOWN);
166167

168+
#if defined (RTS_MULTI_INSTANCE)
169+
// set SO_REUSEADDR so multiple instances can bind to the same port
170+
const Int val = TRUE;
171+
retval = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&val, sizeof(Int));
172+
if (retval == SOCKET_ERROR)
173+
{
174+
m_lastError = WSAGetLastError();
175+
status = GetStatus();
176+
return status;
177+
}
178+
#endif
179+
167180
retval=bind(fd,(struct sockaddr *)&addr,sizeof(addr));
168181

169182
#ifdef _WINDOWS

0 commit comments

Comments
 (0)