From 08a3d0ba12b44b136d56291bf6b07195daf8a03e Mon Sep 17 00:00:00 2001
From: Daniel Ehrenberg <ehrenbed@carleton.edu>
Date: Mon, 25 Feb 2008 13:54:35 -0600
Subject: [PATCH] Making things bootstrap, partial fix for client

---
 core/io/backend/backend.factor          |  2 +-
 core/io/encodings/encodings-docs.factor | 13 +++++++++++++
 core/io/io-tests.factor                 |  2 +-
 extra/io/server/server.factor           |  2 +-
 extra/io/sockets/sockets.factor         |  4 ++--
 extra/io/unix/unix-tests.factor         | 10 +++++-----
 6 files changed, 23 insertions(+), 10 deletions(-)
 create mode 100644 core/io/encodings/encodings-docs.factor

diff --git a/core/io/backend/backend.factor b/core/io/backend/backend.factor
index 6f41814ce9..1595ecd576 100755
--- a/core/io/backend/backend.factor
+++ b/core/io/backend/backend.factor
@@ -24,7 +24,7 @@ HOOK: normalize-pathname io-backend ( str -- newstr )
 M: object normalize-pathname ;
 
 : set-io-backend ( io-backend -- )
-    io-backend set-global init-io init-stdio die ;
+    io-backend set-global init-io init-stdio ;
 
 [ init-io embedded? [ init-stdio ] unless ]
 "io.backend" add-init-hook
diff --git a/core/io/encodings/encodings-docs.factor b/core/io/encodings/encodings-docs.factor
new file mode 100644
index 0000000000..bb1a991903
--- /dev/null
+++ b/core/io/encodings/encodings-docs.factor
@@ -0,0 +1,13 @@
+USING: help.markup help.syntax ;
+IN: io.encodings
+
+ARTICLE: "encodings" "I/O encodings"
+"Many streams deal with bytes, rather than Unicode code points, at some level. The translation between these two things is specified by an encoding. To abstract this away from the programmer, Factor provides a system where these streams are associated with an encoding which is always used when the stream is read from or written to. For most purposes, an encoding descriptor consisting of a symbol is all that is needed when initializing a stream."
+"To make an encoded stream directly (something which is normally handled by the appropriate stream constructor), use the following words:"
+{ $subsection <encoder> }
+{ $subsection <decoder> }
+{ $subsection <encoder-duplex> }
+"To encode or decode a string, use"
+{ $subsection encode-string }
+! { $subsection decode-string }
+;
diff --git a/core/io/io-tests.factor b/core/io/io-tests.factor
index 74b6b5034f..2ac55a33fa 100644
--- a/core/io/io-tests.factor
+++ b/core/io/io-tests.factor
@@ -8,7 +8,7 @@ IN: temporary
 ] unit-test
 
 : <resource-reader> ( resource -- stream )
-    resource-path ascii <file-reader> ;
+    resource-path binary <file-reader> ;
 
 [
     "This is a line.\rThis is another line.\r"
diff --git a/extra/io/server/server.factor b/extra/io/server/server.factor
index 6cc11ea6b6..2c1cac1467 100755
--- a/extra/io/server/server.factor
+++ b/extra/io/server/server.factor
@@ -30,7 +30,7 @@ LOG: accepted-connection NOTICE
         { log-service servers } "Client" spawn-vars
     ] 2keep accept-loop ; inline
 
-: server-loop ( addrspec quot -- )
+: server-loop ( addrspec encoding quot -- )
     >r <server> dup servers get push r>
     [ accept-loop ] curry with-disposal ; inline
 
diff --git a/extra/io/sockets/sockets.factor b/extra/io/sockets/sockets.factor
index 8de43bfd20..c10d7e963c 100755
--- a/extra/io/sockets/sockets.factor
+++ b/extra/io/sockets/sockets.factor
@@ -29,11 +29,11 @@ TUPLE: client-stream addr ;
 HOOK: (client) io-backend ( addrspec -- client-in client-out )
 
 GENERIC: client* ( addrspec -- client-in client-out )
-M: array client* [ (client) ] attempt-all ;
+M: array client* [ (client) 2array ] attempt-all first2 ;
 M: object client* (client) ;
 
 : <client> ( addrspec encoding -- stream )
-    [ >r client* r> <encoder-duplex> ] keep <client-stream> ;
+    over client* rot <encoder-duplex> <client-stream> ;
 
 HOOK: (server) io-backend ( addrspec -- handle )
 
diff --git a/extra/io/unix/unix-tests.factor b/extra/io/unix/unix-tests.factor
index 6e61786d9b..ede8e745c5 100755
--- a/extra/io/unix/unix-tests.factor
+++ b/extra/io/unix/unix-tests.factor
@@ -10,12 +10,12 @@ IN: temporary
     ] ignore-errors
 
     "unix-domain-socket-test" resource-path <local>
-    <server> [
-        stdio get accept [
+    ascii <server> [
+        accept [
             "Hello world" print flush
             readln "XYZ" = "FOO" "BAR" ? print flush
         ] with-stream
-    ] with-stream
+    ] with-disposal
 
     "unix-domain-socket-test" resource-path delete-file
 ] "Test" spawn drop
@@ -24,8 +24,8 @@ yield
 
 [ { "Hello world" "FOO" } ] [
     [
-        "unix-domain-socket-test" resource-path <local> ascii <client>
-        [
+        "unix-domain-socket-test" resource-path <local>
+        ascii <client> [
             readln ,
             "XYZ" print flush
             readln ,