diff --git a/netio.c b/netio.c
index 0837e06ac2d1858b43d2306c5c2cb3ba0f6ceaf0..2741de2794d27418c10eac93f15e6baa59d5315f 100644
--- a/netio.c
+++ b/netio.c
@@ -273,7 +273,7 @@ void packet_queue_to_iovec(struct Queue *queue, struct iovec *iov, unsigned int
 
 	*iov_count = MIN(MIN(queue->count, IOV_MAX), *iov_count);
 
-	for (l = queue->head, i = 0; l; l = l->link, i++)
+	for (l = queue->head, i = 0; i < *iov_count; l = l->link, i++)
 	{
 		writebuf = (buffer*)l->item;
 		len = writebuf->len - 1 - writebuf->pos;