diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-10-27 11:26:42 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-10-27 11:26:42 -0700 |
commit | fcf35c1315773edb2061b6bbd87b0963eecbd097 (patch) | |
tree | cfeb566d121df94c0d77fd451ef29e28571f9eef /html/092socket.mu.html | |
parent | d4fd180fa051b03ff32cf74dfc5874eef4bdbdeb (diff) | |
download | mu-fcf35c1315773edb2061b6bbd87b0963eecbd097.tar.gz |
3604
Diffstat (limited to 'html/092socket.mu.html')
-rw-r--r-- | html/092socket.mu.html | 38 |
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"><-</span> <span class="Constant">[abc]</span> ] + socket <span class="Special"><-</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"> -> </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"> -> </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"> -> </span>socket:num [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> session:num <span class="Special"><-</span> $accept socket assert session, <span class="Constant">[ </span> <span class="Constant">F - example-server-test: $accept failed]</span> contents:&:source:char, sink:&:sink:char <span class="Special"><-</span> new-channel<span class="Constant"> 30</span> - sink <span class="Special"><-</span> start-running receive-from-socket session, sink + start-running receive-from-socket session, sink query:text <span class="Special"><-</span> drain contents response:text <span class="Special"><-</span> call request-handler, query write-to-socket session, response - $close-socket session + session <span class="Special"><-</span> $close-socket session ] <span class="muRecipe">def</span> start-reading-from-network resources:&:resources, uri:text<span class="muRecipe"> -> </span>contents:&:source:char [ @@ -120,7 +121,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color req:text <span class="Special"><-</span> interpolate <span class="Constant">[GET _ HTTP/1.1]</span>, path request-socket socket, req contents:&:source:char, sink:&:sink:char <span class="Special"><-</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"> -> </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:&:sink:char<span class="muRecipe"> -> </span>sink:&:sink:char [ +<span class="muRecipe">def</span> receive-from-socket socket:num, sink:&:sink:char<span class="muRecipe"> -> </span>sink:&: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"><-</span> $read-from-socket socket, <span class="Constant">4096/bytes</span> + c:char, found?:bool, eof?:bool, error:num <span class="Special"><-</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"><-</span> write sink, c <span class="Delimiter">}</span> - bytes-read:num <span class="Special"><-</span> length *req - i:num <span class="Special"><-</span> copy<span class="Constant"> 0</span> <span class="Delimiter">{</span> - done?:bool <span class="Special"><-</span> greater-or-equal i, bytes-read - <span class="muControl">break-if</span> done? - c:char <span class="Special"><-</span> index *req, i <span class="Comment"># todo: unicode</span> - sink <span class="Special"><-</span> write sink, c - i <span class="Special"><-</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"><-</span> close sink ] +<span class="muRecipe">def</span> receive-from-client-socket-and-close socket:num, sink:&:sink:char<span class="muRecipe"> -> </span>sink:&:sink:char, socket:num [ + <span class="Constant">local-scope</span> + <span class="Constant">load-ingredients</span> + sink <span class="Special"><-</span> receive-from-socket socket, sink + socket <span class="Special"><-</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> |