Fixing bugs

db4
Slava Pestov 2008-05-05 02:32:35 -05:00
parent 75fb15ee4c
commit 8397b45110
3 changed files with 28 additions and 31 deletions

View File

@ -4,7 +4,7 @@ USING: io io.backend io.timeouts io.pipes system kernel
namespaces strings hashtables sequences assocs combinators namespaces strings hashtables sequences assocs combinators
vocabs.loader init threads continuations math io.encodings vocabs.loader init threads continuations math io.encodings
io.streams.duplex io.nonblocking io.streams.duplex accessors io.streams.duplex io.nonblocking io.streams.duplex accessors
concurrency.flags locals destructors ; concurrency.flags destructors ;
IN: io.launcher IN: io.launcher
TUPLE: process < identity-tuple TUPLE: process < identity-tuple
@ -146,56 +146,53 @@ M: process set-timeout set-process-timeout ;
M: process timed-out kill-process ; M: process timed-out kill-process ;
:: <process-reader*> ( process encoding -- process stream ) : <process-reader*> ( process encoding -- process stream )
[ [
(pipe) { >r (pipe) {
[ add-error-destructor ] [ add-error-destructor ]
[ [
process >process swap >process
[ swap out>> or ] change-stdout [ swap out>> or ] change-stdout
run-detached run-detached
] ]
[ out>> close-handle ] [ out>> close-handle ]
[ in>> <reader> encoding <decoder> ] [ in>> <reader> ]
} cleave } cleave r> <decoder>
] with-destructors ; ] with-destructors ;
: <process-reader> ( desc encoding -- stream ) : <process-reader> ( desc encoding -- stream )
<process-reader*> nip ; inline <process-reader*> nip ; inline
:: <process-writer*> ( process encoding -- process stream ) : <process-writer*> ( process encoding -- process stream )
[ [
(pipe) { >r (pipe) {
[ add-error-destructor ] [ add-error-destructor ]
[ [
process >process swap >process
[ swap in>> or ] change-stdout [ swap in>> or ] change-stdout
run-detached run-detached
] ]
[ in>> close-handle ] [ in>> close-handle ]
[ out>> <writer> encoding <encoder> ] [ out>> <writer> ]
} cleave } cleave r> <encoder>
] with-destructors ; ] with-destructors ;
: <process-writer> ( desc encoding -- stream ) : <process-writer> ( desc encoding -- stream )
<process-writer*> nip ; inline <process-writer*> nip ; inline
:: <process-stream*> ( process encoding -- process stream ) : <process-stream*> ( process encoding -- process stream )
[ [
(pipe) (pipe) { >r (pipe) (pipe) {
[ [ add-error-destructor ] bi@ ] [ [ add-error-destructor ] bi@ ]
[ [
process >process rot >process
[ swap out>> or ] change-stdout [ swap out>> or ] change-stdout
[ swap in>> or ] change-stdin [ swap in>> or ] change-stdin
run-detached run-detached
] ]
[ [ in>> close-handle ] [ out>> close-handle ] bi* ] [ [ in>> close-handle ] [ out>> close-handle ] bi* ]
[ [ [ in>> <reader> ] [ out>> <writer> ] bi* ]
[ in>> <reader> ] [ out>> <writer> ] bi* } 2cleave r> <encoder-duplex>
encoding <encoder-duplex>
]
} 2cleave
] with-destructors ; ] with-destructors ;
: <process-stream> ( desc encoding -- stream ) : <process-stream> ( desc encoding -- stream )

View File

@ -8,30 +8,29 @@ IN: io.pipes
TUPLE: pipe in out ; TUPLE: pipe in out ;
: close-pipe ( pipe -- ) M: pipe dispose ( pipe -- )
[ in>> ] [ out>> ] bi 2array dispose-each ; [ in>> close-handle ] [ out>> close-handle ] bi ;
HOOK: (pipe) io-backend ( -- pipe ) HOOK: (pipe) io-backend ( -- pipe )
:: <pipe> ( encoding -- input-stream output-stream ) :: <pipe> ( encoding -- input-stream output-stream )
[ [
(pipe) (pipe)
[ [ close-later ] each ] [ add-error-destructor ]
[
[ in>> <reader> encoding <decoder> ] [ in>> <reader> encoding <decoder> ]
[ out>> <writer> encoding <encoder> ] bi [ out>> <writer> encoding <encoder> ]
] bi tri
] with-destructors ; ] with-destructors ;
:: with-fds ( input-fd output-fd quot encoding -- ) :: with-fds ( input-fd output-fd quot encoding -- )
input-fd [ <reader> encoding <decoder> dup add-always-destructor ] [ input-stream get ] if* [ input-fd [ <reader> encoding <decoder> dup add-always-destructor ] [ input-stream get ] if* [
output-fd [ <writer> encoding <encoder> dup add-always-destructor ] [ output-stream get ] if* output-fd [ <writer> encoding <encoder> dup add-always-destructor ] [ output-stream get ] if*
quot with-output-stream quot with-output-stream*
] with-input-stream ; inline ] with-input-stream* ; inline
: <pipes> ( n -- pipes ) : <pipes> ( n -- pipes )
[ (pipe) dup [ close-later ] each ] replicate [ (pipe) dup add-error-destructor ] replicate
{ f f } [ prefix ] [ suffix ] bi f f pipe boa [ prefix ] [ suffix ] bi
2 <sliding-groups> ; 2 <sliding-groups> ;
: with-pipe-fds ( seq -- results ) : with-pipe-fds ( seq -- results )

View File

@ -1,6 +1,7 @@
USING: io.files io.sockets io kernel threads USING: io.files io.sockets io kernel threads
namespaces tools.test continuations strings byte-arrays namespaces tools.test continuations strings byte-arrays
sequences prettyprint system io.encodings.binary io.encodings.ascii ; sequences prettyprint system io.encodings.binary io.encodings.ascii
io.streams.duplex ;
IN: io.unix.tests IN: io.unix.tests
! Unix domain stream sockets ! Unix domain stream sockets