diff options
author | sotech117 <michael_foiani@brown.edu> | 2023-09-25 19:02:19 -0400 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2023-09-25 19:02:19 -0400 |
commit | 8c6ae1ecde9faa0af5dacaf7ecf0f9cf47b69159 (patch) | |
tree | 87671ddc40b678e0ec6592015d0e5d26e0df1864 /protocol.c | |
parent | c534d8e28a00c9762fcb4ef2bdeb9a735ae26b75 (diff) |
more refactoring and commenting
Diffstat (limited to 'protocol.c')
-rw-r--r-- | protocol.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -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; |