MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / ReceiveData

Method ReceiveData

src/openrct2/network/Socket.cpp:584–623  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

582 }
583
584 ReadPacket ReceiveData(void* buffer, size_t size, size_t* sizeReceived) override
585 {
586 if (_status != SocketStatus::connected)
587 {
588 throw std::runtime_error("Socket not connected.");
589 }
590
591 int32_t readBytes = recv(_socket, static_cast<char*>(buffer), static_cast<int32_t>(size), 0);
592 if (readBytes == 0)
593 {
594 *sizeReceived = 0;
595 return ReadPacket::disconnected;
596 }
597
598 if (readBytes == SOCKET_ERROR)
599 {
600 *sizeReceived = 0;
601 #ifndef _WIN32
602 // Removing the check for EAGAIN and instead relying on the values being the same allows turning on of
603 // -Wlogical-op warning.
604 // This is not true on Windows, see:
605 // * https://msdn.microsoft.com/en-us/library/windows/desktop/ms737828(v=vs.85).aspx
606 // * https://msdn.microsoft.com/en-us/library/windows/desktop/ms741580(v=vs.85).aspx
607 // * https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx
608 static_assert(
609 EWOULDBLOCK == EAGAIN,
610 "Portability note: your system has different values for EWOULDBLOCK "
611 "and EAGAIN, please extend the condition below");
612 #endif // _WIN32
613 if (LAST_SOCKET_ERROR() != EWOULDBLOCK)
614 {
615 return ReadPacket::disconnected;
616 }
617
618 return ReadPacket::noData;
619 }
620
621 *sizeReceived = readBytes;
622 return ReadPacket::success;
623 }
624
625 void Close() override
626 {

Callers 4

receiveDataMethod · 0.45
updateLANMethod · 0.45
UpdateMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected