diff options
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; |