MCPcopy Create free account
hub / github.com/OpenHD/OpenHD / loopUntilError

Method loopUntilError

OpenHD/ohd_common/src/openhd_udp.cpp:125–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123openhd::UDPReceiver::~UDPReceiver() { stopBackground(); }
124
125void openhd::UDPReceiver::loopUntilError() {
126 const auto buff =
127 std::make_unique<std::array<uint8_t, UDP_PACKET_MAX_SIZE>>();
128 // sockaddr_in source;
129 // socklen_t sourceLen= sizeof(sockaddr_in);
130 while (receiving) {
131 // const ssize_t message_length =
132 // recvfrom(mSocket,buff->data(),UDP_PACKET_MAX_SIZE,
133 // MSG_WAITALL,(sockaddr*)&source,&sourceLen);
134 const ssize_t message_length =
135 recv(mSocket, buff->data(), buff->size(), MSG_WAITALL);
136 if (message_length > 0) {
137 mCb(buff->data(), (size_t)message_length);
138 } else {
139 // this can also come from the shutdown, in which case it is not an error.
140 // But this way we break out of the loop.
141 if (receiving) {
142 if (std::chrono::steady_clock::now() - m_last_receive_error_log >=
143 std::chrono::seconds(3)) {
144 get_console()->warn("Got message length of: {} log_skip_count:{}",
145 message_length,
146 m_last_receive_error_log_skip_count);
147 m_last_receive_error_log = std::chrono::steady_clock::now();
148 m_last_receive_error_log_skip_count = 0;
149 } else {
150 m_last_receive_error_log_skip_count++;
151 }
152 }
153 }
154 }
155 get_console()->debug("UDP end");
156}
157
158void openhd::UDPReceiver::forwardPacketViaUDP(
159 const std::string &destIp, const int destPort, const uint8_t *packet,

Callers

nothing calls this directly

Calls 3

sizeMethod · 0.80
debugMethod · 0.80
get_consoleFunction · 0.70

Tested by

no test coverage detected