about summary refs log tree commit diff stats
path: root/092socket.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-10-18 10:39:18 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-10-18 10:39:18 -0700
commitc83f3bca47b1538ce469fc4463d6165156735675 (patch)
tree2575be098fb10f8373750f7905a5c06ab3c46c79 /092socket.mu
parent9c78e58e686e23aecfe1b229fc5abc8e0b4f8e3b (diff)
downloadmu-c83f3bca47b1538ce469fc4463d6165156735675.tar.gz
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).
Diffstat (limited to '092socket.mu')
-rw-r--r--092socket.mu9
1 files changed, 6 insertions, 3 deletions
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
 ]