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 } +{ $subsection } +{ $subsection } +"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 -- stream ) - resource-path ascii ; + resource-path binary ; [ "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 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) ; : ( addrspec encoding -- stream ) - [ >r client* r> ] keep ; + over client* rot ; 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 - [ - stdio get accept [ + ascii [ + 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 ascii - [ + "unix-domain-socket-test" resource-path + ascii [ readln , "XYZ" print flush readln ,