Skip to content

Commit

Permalink
if partial TCP packet was sent, keep sending the rest of the packet u…
Browse files Browse the repository at this point in the history
…ntil complete or failure
  • Loading branch information
Suriya Kandaswamy committed Sep 13, 2022
1 parent d84f6ac commit 3685fcc
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions protocol/whist/network/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -832,15 +832,22 @@ int multithreaded_tcp_send(void* opaque) {
LOG_INFO("Sending a WhistPacket of size %d (Total %d bytes), over TCP", queue_item.packet_size,
tcp_packet_size);

// Send the packet
int ret = send(context->socket, (const char*)network_packet, tcp_packet_size, 0);
if (ret < 0) {
int error = get_last_network_error();
if (error == WHIST_ECONNRESET) {
LOG_WARNING("TCP Connection reset by peer");
context->connection_lost = true;
// Send the packet. If a partial packet is sent, keep sending until full packet has been sent.
int total_sent = 0;
while (total_sent < tcp_packet_size) {
int ret = send(context->socket, (const char*)(network_packet + total_sent), tcp_packet_size, 0);
if (ret < 0) {
int error = get_last_network_error();
if (error == WHIST_ECONNRESET) {
LOG_WARNING("TCP Connection reset by peer");
context->connection_lost = true;
} else {
LOG_WARNING("Unexpected TCP Packet Error: %d", error);
}
// Don't attempt to send the rest of the packet if there was a failure
break;
} else {
LOG_WARNING("Unexpected TCP Packet Error: %d", error);
total_sent += ret;
}
}

Expand Down

0 comments on commit 3685fcc

Please sign in to comment.