Skip to content

Commit edabb55

Browse files
committed
Simplify to not call Transport::init from LANAPI::init.
1 parent 6005fbe commit edabb55

File tree

10 files changed

+42
-96
lines changed

10 files changed

+42
-96
lines changed

Generals/Code/GameEngine/Include/GameNetwork/Transport.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class Transport //: public MemoryPoolObject
5050

5151
Bool init( AsciiString ip, UnsignedShort port );
5252
Bool init( UnsignedInt ip, UnsignedShort port );
53-
Bool bind( void );
5453
void reset( void );
5554
Bool update( void ); ///< Call this once a GameEngine tick, regardless of whether the frame advances.
5655

@@ -81,14 +80,10 @@ class Transport //: public MemoryPoolObject
8180
DelayedTransportMessage m_delayedInBuffer[MAX_MESSAGES];
8281
#endif
8382

83+
UnsignedShort m_port;
8484
private:
85-
86-
void clearBuffers( void );
87-
8885
Bool m_winsockInit;
8986
UDP *m_udpsock;
90-
UnsignedInt m_ip;
91-
UnsignedShort m_port;
9287

9388
// Latency insertion and packet loss
9489
Bool m_useLatency;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,6 @@ void ConnectionManager::initTransport() {
14511451
m_transport = new Transport;
14521452
m_transport->reset();
14531453
m_transport->init(m_localAddr, m_localPort);
1454-
m_transport->bind();
14551454
}
14561455

14571456
/**

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ void LANAPI::init( void )
100100
{
101101
m_gameStartTime = 0;
102102
m_gameStartSeconds = 0;
103-
m_transport->reset();
104-
m_transport->init(m_localIP, lobbyPort);
105103

106104
m_pendingAction = ACT_NONE;
107105
m_expiration = 0;
@@ -1252,18 +1250,15 @@ void LANAPI::addPlayer( LANPlayer *player )
12521250

12531251
Bool LANAPI::SetLocalIP( UnsignedInt localIP )
12541252
{
1255-
Bool success = TRUE;
1253+
DEBUG_ASSERTCRASH(m_currentGame == NULL && m_gameStartTime == 0, ("LANAPI::SetLocalIP called while in a game, should be called right after LANAPI::init"));
1254+
Bool retval = TRUE;
12561255
m_localIP = localIP;
12571256

12581257
m_transport->reset();
1259-
success = m_transport->init(m_localIP, lobbyPort);
1260-
if (success)
1261-
{
1262-
success = m_transport->bind();
1263-
}
1258+
retval = m_transport->init(m_localIP, lobbyPort);
12641259
m_transport->allowBroadcasts(true);
12651260

1266-
return success;
1261+
return retval;
12671262
}
12681263

12691264
void LANAPI::SetLocalIP( AsciiString localIP )

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,10 +620,7 @@ void NAT::attachSlotList(GameSlot *slotList[], Int localSlot, UnsignedInt localI
620620
m_startingPortNumber = NETWORK_BASE_PORT_NUMBER + ((timeGetTime() / 1000) % 20000);
621621
DEBUG_LOG(("NAT::attachSlotList - using %d as the starting port number", m_startingPortNumber));
622622
generatePortNumbers(slotList, localSlot);
623-
if (m_transport->init(m_localIP, getSlotPort(localSlot)))
624-
{
625-
m_transport->bind();
626-
}
623+
m_transport->init(m_localIP, getSlotPort(localSlot));
627624
}
628625

629626
Int NAT::getSlotPort(Int slot) {

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

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,6 @@ Bool Transport::init( UnsignedInt ip, UnsignedShort port )
103103
m_winsockInit = true;
104104
}
105105

106-
m_ip = ip;
107-
m_port = port;
108-
clearBuffers();
109-
110-
#if defined(RTS_DEBUG)
111-
if (TheGlobalData->m_latencyAverage > 0 || TheGlobalData->m_latencyNoise)
112-
m_useLatency = true;
113-
114-
if (TheGlobalData->m_packetLoss)
115-
m_usePacketLoss = true;
116-
#endif
117-
118-
return true;
119-
}
120-
121-
Bool Transport::bind( void )
122-
{
123-
DEBUG_ASSERTCRASH(m_winsockInit, ("Transport::bind called before Transport::init"));
124-
125106
// ------- Bind our port --------
126107
if (m_udpsock)
127108
delete m_udpsock;
@@ -133,23 +114,17 @@ Bool Transport::bind( void )
133114
int retval = -1;
134115
time_t now = timeGetTime();
135116
while ((retval != 0) && ((timeGetTime() - now) < 1000)) {
136-
retval = m_udpsock->Bind(m_ip, m_port);
117+
retval = m_udpsock->Bind(ip, port);
137118
}
138119

139120
if (retval != 0) {
140-
DEBUG_CRASH(("Could not bind to 0x%8.8X:%d", m_ip, m_port));
141-
DEBUG_LOG(("Transport::bind - Failure to bind socket with error code %x", retval));
121+
DEBUG_CRASH(("Could not bind to 0x%8.8X:%d", ip, port));
122+
DEBUG_LOG(("Transport::init - Failure to bind socket with error code %x", retval));
142123
delete m_udpsock;
143124
m_udpsock = NULL;
144125
return false;
145126
}
146127

147-
clearBuffers();
148-
return retval;
149-
}
150-
151-
void Transport::clearBuffers(void)
152-
{
153128
// ------- Clear buffers --------
154129
int i=0;
155130
for (; i<MAX_MESSAGES; ++i)
@@ -171,6 +146,18 @@ void Transport::clearBuffers(void)
171146
}
172147
m_statisticsSlot = 0;
173148
m_lastSecond = timeGetTime();
149+
150+
m_port = port;
151+
152+
#if defined(RTS_DEBUG)
153+
if (TheGlobalData->m_latencyAverage > 0 || TheGlobalData->m_latencyNoise)
154+
m_useLatency = true;
155+
156+
if (TheGlobalData->m_packetLoss)
157+
m_usePacketLoss = true;
158+
#endif
159+
160+
return true;
174161
}
175162

176163
void Transport::reset( void )

GeneralsMD/Code/GameEngine/Include/GameNetwork/Transport.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class Transport //: public MemoryPoolObject
5050

5151
Bool init( AsciiString ip, UnsignedShort port );
5252
Bool init( UnsignedInt ip, UnsignedShort port );
53-
Bool bind( void );
5453
void reset( void );
5554
Bool update( void ); ///< Call this once a GameEngine tick, regardless of whether the frame advances.
5655

@@ -81,14 +80,10 @@ class Transport //: public MemoryPoolObject
8180
DelayedTransportMessage m_delayedInBuffer[MAX_MESSAGES];
8281
#endif
8382

83+
UnsignedShort m_port;
8484
private:
85-
86-
void clearBuffers( void );
87-
8885
Bool m_winsockInit;
8986
UDP *m_udpsock;
90-
UnsignedInt m_ip;
91-
UnsignedShort m_port;
9287

9388
// Latency insertion and packet loss
9489
Bool m_useLatency;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,6 @@ void ConnectionManager::initTransport() {
14511451
m_transport = new Transport;
14521452
m_transport->reset();
14531453
m_transport->init(m_localAddr, m_localPort);
1454-
m_transport->bind();
14551454
}
14561455

14571456
/**

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ void LANAPI::init( void )
100100
{
101101
m_gameStartTime = 0;
102102
m_gameStartSeconds = 0;
103-
m_transport->reset();
104-
m_transport->init(m_localIP, lobbyPort);
105103

106104
m_pendingAction = ACT_NONE;
107105
m_expiration = 0;
@@ -1252,18 +1250,15 @@ void LANAPI::addPlayer( LANPlayer *player )
12521250

12531251
Bool LANAPI::SetLocalIP( UnsignedInt localIP )
12541252
{
1255-
Bool success = TRUE;
1253+
DEBUG_ASSERTCRASH(m_currentGame == NULL && m_gameStartTime == 0, ("LANAPI::SetLocalIP called while in a game, should be called right after LANAPI::init"));
1254+
Bool retval = TRUE;
12561255
m_localIP = localIP;
12571256

12581257
m_transport->reset();
1259-
success = m_transport->init(m_localIP, lobbyPort);
1260-
if (success)
1261-
{
1262-
success = m_transport->bind();
1263-
}
1258+
retval = m_transport->init(m_localIP, lobbyPort);
12641259
m_transport->allowBroadcasts(true);
12651260

1266-
return success;
1261+
return retval;
12671262
}
12681263

12691264
void LANAPI::SetLocalIP( AsciiString localIP )

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,10 +620,7 @@ void NAT::attachSlotList(GameSlot *slotList[], Int localSlot, UnsignedInt localI
620620
m_startingPortNumber = NETWORK_BASE_PORT_NUMBER + ((timeGetTime() / 1000) % 20000);
621621
DEBUG_LOG(("NAT::attachSlotList - using %d as the starting port number", m_startingPortNumber));
622622
generatePortNumbers(slotList, localSlot);
623-
if (m_transport->init(m_localIP, getSlotPort(localSlot)))
624-
{
625-
m_transport->bind();
626-
}
623+
m_transport->init(m_localIP, getSlotPort(localSlot));
627624
}
628625

629626
Int NAT::getSlotPort(Int slot) {

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

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,6 @@ Bool Transport::init( UnsignedInt ip, UnsignedShort port )
103103
m_winsockInit = true;
104104
}
105105

106-
m_ip = ip;
107-
m_port = port;
108-
clearBuffers();
109-
110-
#if defined(RTS_DEBUG)
111-
if (TheGlobalData->m_latencyAverage > 0 || TheGlobalData->m_latencyNoise)
112-
m_useLatency = true;
113-
114-
if (TheGlobalData->m_packetLoss)
115-
m_usePacketLoss = true;
116-
#endif
117-
118-
return true;
119-
}
120-
121-
Bool Transport::bind( void )
122-
{
123-
DEBUG_ASSERTCRASH(m_winsockInit, ("Transport::bind called before Transport::init"));
124-
125106
// ------- Bind our port --------
126107
if (m_udpsock)
127108
delete m_udpsock;
@@ -133,23 +114,17 @@ Bool Transport::bind( void )
133114
int retval = -1;
134115
time_t now = timeGetTime();
135116
while ((retval != 0) && ((timeGetTime() - now) < 1000)) {
136-
retval = m_udpsock->Bind(m_ip, m_port);
117+
retval = m_udpsock->Bind(ip, port);
137118
}
138119

139120
if (retval != 0) {
140-
DEBUG_CRASH(("Could not bind to 0x%8.8X:%d", m_ip, m_port));
141-
DEBUG_LOG(("Transport::bind - Failure to bind socket with error code %x", retval));
121+
DEBUG_CRASH(("Could not bind to 0x%8.8X:%d", ip, port));
122+
DEBUG_LOG(("Transport::init - Failure to bind socket with error code %x", retval));
142123
delete m_udpsock;
143124
m_udpsock = NULL;
144125
return false;
145126
}
146127

147-
clearBuffers();
148-
return retval;
149-
}
150-
151-
void Transport::clearBuffers( void )
152-
{
153128
// ------- Clear buffers --------
154129
int i=0;
155130
for (; i<MAX_MESSAGES; ++i)
@@ -171,6 +146,18 @@ void Transport::clearBuffers( void )
171146
}
172147
m_statisticsSlot = 0;
173148
m_lastSecond = timeGetTime();
149+
150+
m_port = port;
151+
152+
#if defined(RTS_DEBUG)
153+
if (TheGlobalData->m_latencyAverage > 0 || TheGlobalData->m_latencyNoise)
154+
m_useLatency = true;
155+
156+
if (TheGlobalData->m_packetLoss)
157+
m_usePacketLoss = true;
158+
#endif
159+
160+
return true;
174161
}
175162

176163
void Transport::reset( void )

0 commit comments

Comments
 (0)