Making things bootstrap, partial fix for client
parent
44f4aa4c69
commit
08a3d0ba12
|
@ -24,7 +24,7 @@ HOOK: normalize-pathname io-backend ( str -- newstr )
|
||||||
M: object normalize-pathname ;
|
M: object normalize-pathname ;
|
||||||
|
|
||||||
: set-io-backend ( io-backend -- )
|
: 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 ]
|
[ init-io embedded? [ init-stdio ] unless ]
|
||||||
"io.backend" add-init-hook
|
"io.backend" add-init-hook
|
||||||
|
|
|
@ -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 }
|
||||||
|
;
|
|
@ -8,7 +8,7 @@ IN: temporary
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
: <resource-reader> ( resource -- stream )
|
: <resource-reader> ( resource -- stream )
|
||||||
resource-path ascii <file-reader> ;
|
resource-path binary <file-reader> ;
|
||||||
|
|
||||||
[
|
[
|
||||||
"This is a line.\rThis is another line.\r"
|
"This is a line.\rThis is another line.\r"
|
||||||
|
|
|
@ -30,7 +30,7 @@ LOG: accepted-connection NOTICE
|
||||||
{ log-service servers } "Client" spawn-vars
|
{ log-service servers } "Client" spawn-vars
|
||||||
] 2keep accept-loop ; inline
|
] 2keep accept-loop ; inline
|
||||||
|
|
||||||
: server-loop ( addrspec quot -- )
|
: server-loop ( addrspec encoding quot -- )
|
||||||
>r <server> dup servers get push r>
|
>r <server> dup servers get push r>
|
||||||
[ accept-loop ] curry with-disposal ; inline
|
[ accept-loop ] curry with-disposal ; inline
|
||||||
|
|
||||||
|
|
|
@ -29,11 +29,11 @@ TUPLE: client-stream addr ;
|
||||||
HOOK: (client) io-backend ( addrspec -- client-in client-out )
|
HOOK: (client) io-backend ( addrspec -- client-in client-out )
|
||||||
|
|
||||||
GENERIC: client* ( 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) ;
|
M: object client* (client) ;
|
||||||
|
|
||||||
: <client> ( addrspec encoding -- stream )
|
: <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 )
|
HOOK: (server) io-backend ( addrspec -- handle )
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,12 @@ IN: temporary
|
||||||
] ignore-errors
|
] ignore-errors
|
||||||
|
|
||||||
"unix-domain-socket-test" resource-path <local>
|
"unix-domain-socket-test" resource-path <local>
|
||||||
<server> [
|
ascii <server> [
|
||||||
stdio get accept [
|
accept [
|
||||||
"Hello world" print flush
|
"Hello world" print flush
|
||||||
readln "XYZ" = "FOO" "BAR" ? print flush
|
readln "XYZ" = "FOO" "BAR" ? print flush
|
||||||
] with-stream
|
] with-stream
|
||||||
] with-stream
|
] with-disposal
|
||||||
|
|
||||||
"unix-domain-socket-test" resource-path delete-file
|
"unix-domain-socket-test" resource-path delete-file
|
||||||
] "Test" spawn drop
|
] "Test" spawn drop
|
||||||
|
@ -24,8 +24,8 @@ yield
|
||||||
|
|
||||||
[ { "Hello world" "FOO" } ] [
|
[ { "Hello world" "FOO" } ] [
|
||||||
[
|
[
|
||||||
"unix-domain-socket-test" resource-path <local> ascii <client>
|
"unix-domain-socket-test" resource-path <local>
|
||||||
[
|
ascii <client> [
|
||||||
readln ,
|
readln ,
|
||||||
"XYZ" print flush
|
"XYZ" print flush
|
||||||
readln ,
|
readln ,
|
||||||
|
|
Loading…
Reference in New Issue