diff options
-rw-r--r-- | 092socket.mu | 37 | ||||
-rw-r--r-- | http-server.mu | 37 |
2 files changed, 37 insertions, 37 deletions
diff --git a/092socket.mu b/092socket.mu index 250afcf6..c60852be 100644 --- a/092socket.mu +++ b/092socket.mu @@ -115,3 +115,40 @@ def transmit-to-fake-socket network:&:local-network, port:num, source:&:source:c } put-index *new-port-connections, len, *new-port-connection ] + +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 + i:num <- copy 0 + { + done?:bool <- greater-or-equal i, bytes-read + break-if done? + c:char <- index *req, i + end-of-request?:bool <- equal c, 10/newline + break-if end-of-request? # To be safe, for now. + sink <- write sink, c + i <- add i, 1 + loop + } + } + sink <- close sink +] + +def write-to-socket session-socket:num, s:text [ + local-scope + load-ingredients + len:num <- length *s + i:num <- copy 0 + { + done?:bool <- greater-or-equal i, len + break-if done? + c:char <- index *s, i + $print [writing to socket: ], i, [ ], c, 10/newline + $write-to-socket session-socket, c + i <- add i, 1 + loop + } +] diff --git a/http-server.mu b/http-server.mu index c415b094..8f34725d 100644 --- a/http-server.mu +++ b/http-server.mu @@ -33,40 +33,3 @@ SUCCESS! $close-socket session $close-socket socket ] - -def write-to-socket session-socket:num, s:text [ - local-scope - load-ingredients - len:num <- length *s - i:num <- copy 0 - { - done?:bool <- greater-or-equal i, len - break-if done? - c:char <- index *s, i - $print [writing to socket: ], i, [ ], c, 10/newline - $write-to-socket session-socket, c - i <- add i, 1 - loop - } -] - -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 - i:num <- copy 0 - { - done?:bool <- greater-or-equal i, bytes-read - break-if done? - c:char <- index *req, i - end-of-request?:bool <- equal c, 10/newline - break-if end-of-request? # To be safe, for now. - sink <- write sink, c - i <- add i, 1 - loop - } - } - sink <- close sink -] |