From 8c6ae1ecde9faa0af5dacaf7ecf0f9cf47b69159 Mon Sep 17 00:00:00 2001 From: sotech117 Date: Mon, 25 Sep 2023 19:02:19 -0400 Subject: more refactoring and commenting --- protocol.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'protocol.c') diff --git a/protocol.c b/protocol.c index 5c8127f..9c8c65b 100644 --- a/protocol.c +++ b/protocol.c @@ -4,6 +4,7 @@ #include "protocol.h" #define TCP_TIMEOUT 100000 // 100ms in microseconds +#define MAX_PACKET_SIZE 512 int send_all(int sock, char *buf, int *len) { @@ -18,8 +19,10 @@ int send_all(int sock, char *buf, int *len) int bytesleft = *len; // how many we have left to send int n; + // ensure we don't send more than MAX_PACKET_SIZE bytes + size_t max_send = bytesleft >= MAX_PACKET_SIZE ? MAX_PACKET_SIZE : bytesleft; while(total < *len) { - n = send(sock, buf+total, bytesleft, 0); + n = send(sock, buf+total, max_send, 0); if (n == -1) { break; } total += n; bytesleft -= n; -- cgit v1.2.3-70-g09d2