]> gitweb.factorcode.org Git - factor.git/blob - basis/io/streams/duplex/duplex.factor
Fix permission bits
[factor.git] / basis / io / streams / duplex / duplex.factor
1 ! Copyright (C) 2005, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel continuations destructors io io.encodings
4 io.encodings.private io.timeouts debugger summary listener
5 accessors delegate delegate.protocols ;
6 IN: io.streams.duplex
7
8 TUPLE: duplex-stream in out ;
9
10 C: <duplex-stream> duplex-stream
11
12 CONSULT: input-stream-protocol duplex-stream in>> ;
13
14 CONSULT: output-stream-protocol duplex-stream out>> ;
15
16 M: duplex-stream set-timeout
17     [ in>> set-timeout ] [ out>> set-timeout ] 2bi ;
18
19 M: duplex-stream dispose
20     #! The output stream is closed first, in case both streams
21     #! are attached to the same file descriptor, the output
22     #! buffer needs to be flushed before we close the fd.
23     [
24         [ in>> &dispose drop ]
25         [ out>> &dispose drop ]
26         bi
27     ] with-destructors ;
28
29 : <encoder-duplex> ( stream-in stream-out encoding -- duplex )
30     tuck re-encode >r re-decode r> <duplex-stream> ;
31
32 : with-stream* ( stream quot -- )
33     >r [ in>> ] [ out>> ] bi r> with-streams* ; inline
34
35 : with-stream ( stream quot -- )
36     >r [ in>> ] [ out>> ] bi r> with-streams ; inline