Making things bootstrap, partial fix for client

db4
Daniel Ehrenberg 2008-02-25 13:54:35 -06:00
parent 44f4aa4c69
commit 08a3d0ba12
6 changed files with 23 additions and 10 deletions

View File

@ -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

View File

@ -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 }
;

View File

@ -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"

View File

@ -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

View File

@ -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 )

View File

@ -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 ,