Skip to content

Commit

Permalink
Fix non blocking socket write
Browse files Browse the repository at this point in the history
  • Loading branch information
UnidenifiedUser committed Nov 30, 2023
1 parent 105669c commit db9ecc4
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/sv2_template_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,19 +304,27 @@ class Sv2TemplateProvider
*/
[[nodiscard]] bool SendBuf(const Sv2Client& client, Span<std::byte> buffer) {
try {
ssize_t sent = client.m_sock->Send(buffer.data(), buffer.size(), MSG_NOSIGNAL | MSG_DONTWAIT);
LogPrintf("DEBUG: Sent buf byte size sent: %d\n", sent);
/* if (sent != static_cast<ssize_t>(buffer.size())) { */
/* LogPrintf("") */
/* return false; */
/* } */
size_t total_sent = 0;
LogPrintf("Try to send: %d\n", buffer.size());
while (total_sent < buffer.size()) {
ssize_t sent = client.m_sock->Send(buffer.data() + total_sent, buffer.size() - total_sent, MSG_NOSIGNAL | MSG_DONTWAIT);
if (sent > 0) {
total_sent += sent;
} else if (sent == 0) {
usleep(10);
} else {
usleep(100);
}
}
LogPrintf("sent: %d\d", buffer.size());
} catch (const std::exception& e) {
LogPrintf("Error sending Sv2NetMsg: %s\n", e.what());
return false;
}

return true;
}

};


Expand Down

0 comments on commit db9ecc4

Please sign in to comment.