MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / receivePacketLoop

Method receivePacketLoop

src/OpenLoco/src/Network/NetworkBase.cpp:23–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21};
22
23void NetworkBase::receivePacketLoop()
24{
25 while (!_endReceivePacketLoop)
26 {
27 bool receivedPacket{};
28 for (auto& socket : _sockets)
29 {
30 Packet packet;
31 size_t packetSize{};
32
33 std::unique_ptr<INetworkEndpoint> endpoint;
34 auto result = socket->receiveData(&packet, sizeof(Packet), &packetSize, &endpoint);
35 if (result == NetworkReadPacket::success)
36 {
37 // Validate packet
38 if (packet.header.dataSize <= packetSize - sizeof(PacketHeader))
39 {
40 onReceivePacket(*socket, std::move(endpoint), packet);
41 }
42 receivedPacket = true;
43 }
44 }
45 if (!receivedPacket)
46 {
47 std::this_thread::sleep_for(std::chrono::milliseconds(1));
48 }
49 }
50}
51
52void NetworkBase::beginReceivePacketLoop()
53{

Callers

nothing calls this directly

Calls 1

receiveDataMethod · 0.80

Tested by

no test coverage detected