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-27 11:08:50 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-10-27 11:08:50 -0700
commitb07576d26fb69821cfe55284d5cde0f31a2788eb (patch)
treeaa2e61bda9847660abc274f63bdf20c0b7591c32 /092socket.mu
parent8047005cc508443d66bcd51d63764542d39047a4 (diff)
downloadmu-b07576d26fb69821cfe55284d5cde0f31a2788eb.tar.gz
3602
Simplify primitive interface to read from a socket: now returns just a
single character.
Diffstat (limited to '092socket.mu')
-rw-r--r--092socket.mu20
1 files changed, 7 insertions, 13 deletions
diff --git a/092socket.mu b/092socket.mu
index 202f84a1..5a16a367 100644
--- a/092socket.mu
+++ b/092socket.mu
@@ -106,24 +106,18 @@ def receive-from-socket socket:num, sink:&:sink:char -> sink:&:sink:char, socket
   load-ingredients
   {
     +next-attempt
-    req:text, found?:bool, eof?:bool, error:num <- $read-from-socket socket, 1/byte
+    c:char, found?:bool, eof?:bool, error:num <- $read-from-socket socket
+    break-if eof?
     break-if error
     {
-      break-if found?
-      switch
-      loop +next-attempt
+      break-unless found?
+      sink <- write sink, c
     }
-    bytes-read:num <- length *req
-    i:num <- copy 0
     {
-      done?:bool <- greater-or-equal i, bytes-read
-      break-if done?
-      c:char <- index *req, i  # todo: unicode
-      sink <- write sink, c
-      i <- add i, 1
-      loop
+      break-if found?
+      switch
     }
-    loop-unless eof?
+    loop
   }
   sink <- close sink
 ]