aboutsummaryrefslogtreecommitdiff
path: root/protocol.c
diff options
context:
space:
mode:
Diffstat (limited to 'protocol.c')
-rw-r--r--protocol.c5
1 files changed, 4 insertions, 1 deletions
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;