From c83f3bca47b1538ce469fc4463d6165156735675 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 18 Oct 2016 10:39:18 -0700 Subject: 3519 - reading lots of data from a socket In the process I've also altered the API of $read-from-socket to return a boolean (eof?) rather than the number of bytes read (which is implicit in the length of the returned array). --- 092socket.mu | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to '092socket.mu') diff --git a/092socket.mu b/092socket.mu index 43e98f22..fed6d927 100644 --- a/092socket.mu +++ b/092socket.mu @@ -120,17 +120,20 @@ def receive-from-socket session:num, sink:&:sink:char -> sink:&:sink:char [ local-scope load-ingredients { - req:text, bytes-read:num <- $read-from-socket session, 4096/bytes - $print [read ], bytes-read, [ bytes from socket], 10/newline + req:text, eof?:bool <- $read-from-socket session, 4096/bytes + bytes-read:num <- length *req +#? $print [read ], bytes-read, [ bytes from socket], 10/newline i:num <- copy 0 { +#? $print [ write ], i, 10/newline done?:bool <- greater-or-equal i, bytes-read break-if done? - c:char <- index *req, i + c:char <- index *req, i # todo: unicode sink <- write sink, c i <- add i, 1 loop } + loop-unless eof? } sink <- close sink ] -- cgit 1.4.1-2-gfad0