Fix UDP simulation bug with duplicate ports
Occasionally, a second UDP socket would be created with a randomly generated port equal to the randomly generated port of an earlier socket.
This commit is contained in:
parent
a1f7c74ac4
commit
7ac5aa48ed
|
@ -1796,6 +1796,7 @@ public:
|
|||
: id(deterministicRandom()->randomUniqueID()), process(g_simulator.getCurrentProcess()), peerAddress(peerAddress),
|
||||
actors(false), _localAddress(localAddress) {
|
||||
g_sim2.addressMap.emplace(_localAddress, process);
|
||||
ASSERT(process->boundUDPSockets.find(localAddress) == process->boundUDPSockets.end());
|
||||
process->boundUDPSockets.emplace(localAddress, this);
|
||||
}
|
||||
~UDPSimSocket() {
|
||||
|
@ -1909,6 +1910,9 @@ Future<Reference<IUDPSocket>> Sim2::createUDPSocket(NetworkAddress toAddr) {
|
|||
localAddress.ip = IPAddress(process->address.ip.toV4() + deterministicRandom()->randomInt(0, 256));
|
||||
}
|
||||
localAddress.port = deterministicRandom()->randomInt(40000, 60000);
|
||||
while (process->boundUDPSockets.find(localAddress) != process->boundUDPSockets.end()) {
|
||||
localAddress.port = deterministicRandom()->randomInt(40000, 60000);
|
||||
}
|
||||
return Reference<IUDPSocket>(new UDPSimSocket(localAddress, toAddr));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue