Change the send message size

This commit is contained in:
Angelos Katharopoulos 2024-08-29 02:26:15 -07:00
parent e5354fcddb
commit e94f0028c3

View File

@ -170,10 +170,17 @@ struct GroupImpl {
} }
void send(const char* buf, size_t len, int dst) { void send(const char* buf, size_t len, int dst) {
ssize_t r = sendto( while (len > 0) {
socket_fd_, buf, len, 0, peers_[dst].sockaddr(), peers_[dst].len); size_t l = std::min(len, 8192ul);
if (r < 0) { ssize_t r = sendto(
throw std::runtime_error("Send failed."); socket_fd_, buf, l, 0, peers_[dst].sockaddr(), peers_[dst].len);
if (r <= 0) {
std::ostringstream msg;
msg << "Send of " << l << " bytes failed (errno: " << errno << ")";
throw std::runtime_error(msg.str());
}
len -= l;
buf += l;
} }
} }