about summary refs log tree commit diff stats
path: root/html/092socket.mu.html
diff options
context:
space:
mode:
Diffstat (limited to 'html/092socket.mu.html')
-rw-r--r--html/092socket.mu.html38
1 files changed, 20 insertions, 18 deletions
diff --git a/html/092socket.mu.html b/html/092socket.mu.html
index 78321183..e3c179eb 100644
--- a/html/092socket.mu.html
+++ b/html/092socket.mu.html
@@ -54,6 +54,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
   memory-should-contain [
     10:array:character <span class="Special">&lt;-</span> <span class="Constant">[abc]</span>
   ]
+  socket <span class="Special">&lt;-</span> $close-socket socket
 ]
 <span class="Comment"># helper just for this scenario</span>
 <span class="muRecipe">def</span> example-handler query:text<span class="muRecipe"> -&gt; </span>response:text [
@@ -85,18 +86,18 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
 
 <span class="muData">type</span> request-handler = (recipe text<span class="muRecipe"> -&gt; </span>text)
 
-<span class="muRecipe">def</span> serve-one-request socket:num, request-handler:request-handler [
+<span class="muRecipe">def</span> serve-one-request socket:num, request-handler:request-handler<span class="muRecipe"> -&gt; </span>socket:num [
   <span class="Constant">local-scope</span>
   <span class="Constant">load-ingredients</span>
   session:num <span class="Special">&lt;-</span> $accept socket
   assert session, <span class="Constant">[ </span>
 <span class="Constant">F - example-server-test: $accept failed]</span>
   contents:&amp;:source:char, sink:&amp;:sink:char <span class="Special">&lt;-</span> new-channel<span class="Constant"> 30</span>
-  sink <span class="Special">&lt;-</span> start-running receive-from-socket session, sink
+  start-running receive-from-socket session, sink
   query:text <span class="Special">&lt;-</span> drain contents
   response:text <span class="Special">&lt;-</span> call request-handler, query
   write-to-socket session, response
-  $close-socket session
+  session <span class="Special">&lt;-</span> $close-socket session
 ]
 
 <span class="muRecipe">def</span> start-reading-from-network resources:&amp;:resources, uri:text<span class="muRecipe"> -&gt; </span>contents:&amp;:source:char [
@@ -120,7 +121,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
   req:text <span class="Special">&lt;-</span> interpolate <span class="Constant">[GET _ HTTP/1.1]</span>, path
   request-socket socket, req
   contents:&amp;:source:char, sink:&amp;:sink:char <span class="Special">&lt;-</span> new-channel<span class="Constant"> 10000</span>
-  start-running receive-from-socket socket, sink
+  start-running receive-from-client-socket-and-close socket, sink
 ]
 
 <span class="muRecipe">def</span> request-socket socket:num, s:text<span class="muRecipe"> -&gt; </span>socket:num [
@@ -134,33 +135,34 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
   $write-to-socket socket, <span class="Constant">10/lf</span>
 ]
 
-<span class="muRecipe">def</span> receive-from-socket socket:num, sink:&amp;:sink:char<span class="muRecipe"> -&gt; </span>sink:&amp;:sink:char [
+<span class="muRecipe">def</span> receive-from-socket socket:num, sink:&amp;:sink:char<span class="muRecipe"> -&gt; </span>sink:&amp;:sink:char, socket:num [
   <span class="Constant">local-scope</span>
   <span class="Constant">load-ingredients</span>
   <span class="Delimiter">{</span>
 <span class="Constant">    +next-attempt</span>
-    req:text, found?:bool, eof?:bool, error:num <span class="Special">&lt;-</span> $read-from-socket socket, <span class="Constant">4096/bytes</span>
+    c:char, found?:bool, eof?:bool, error:num <span class="Special">&lt;-</span> $read-from-socket socket
+    <span class="muControl">break-if</span> eof?
     <span class="muControl">break-if</span> error
     <span class="Delimiter">{</span>
-      <span class="muControl">break-if</span> found?
-      switch
-      <span class="muControl">loop</span> <span class="Constant">+next-attempt</span>
+      <span class="muControl">break-unless</span> found?
+      sink <span class="Special">&lt;-</span> write sink, c
     <span class="Delimiter">}</span>
-    bytes-read:num <span class="Special">&lt;-</span> length *req
-    i:num <span class="Special">&lt;-</span> copy<span class="Constant"> 0</span>
     <span class="Delimiter">{</span>
-      done?:bool <span class="Special">&lt;-</span> greater-or-equal i, bytes-read
-      <span class="muControl">break-if</span> done?
-      c:char <span class="Special">&lt;-</span> index *req, i  <span class="Comment"># todo: unicode</span>
-      sink <span class="Special">&lt;-</span> write sink, c
-      i <span class="Special">&lt;-</span> add i,<span class="Constant"> 1</span>
-      <span class="muControl">loop</span>
+      <span class="muControl">break-if</span> found?
+      switch
     <span class="Delimiter">}</span>
-    <span class="muControl">loop-unless</span> eof?
+    <span class="muControl">loop</span>
   <span class="Delimiter">}</span>
   sink <span class="Special">&lt;-</span> close sink
 ]
 
+<span class="muRecipe">def</span> receive-from-client-socket-and-close socket:num, sink:&amp;:sink:char<span class="muRecipe"> -&gt; </span>sink:&amp;:sink:char, socket:num [
+  <span class="Constant">local-scope</span>
+  <span class="Constant">load-ingredients</span>
+  sink <span class="Special">&lt;-</span> receive-from-socket socket, sink
+  socket <span class="Special">&lt;-</span> $close-socket socket
+]
+
 <span class="muRecipe">def</span> write-to-socket socket:num, s:text [
   <span class="Constant">local-scope</span>
   <span class="Constant">load-ingredients</span>