Split off formatted-output-stream-protocol from output-stream-protocol, and clean up io.streams.duplex
parent
1221fb7d55
commit
27daa4b1d4
|
@ -1,27 +1,25 @@
|
||||||
! Copyright (C) 2007 Daniel Ehrenberg
|
! Copyright (C) 2007 Daniel Ehrenberg
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: delegate sequences.private sequences assocs
|
USING: delegate sequences.private sequences assocs
|
||||||
io io.styles definitions kernel continuations ;
|
io definitions kernel continuations ;
|
||||||
IN: delegate.protocols
|
IN: delegate.protocols
|
||||||
|
|
||||||
PROTOCOL: sequence-protocol
|
PROTOCOL: sequence-protocol
|
||||||
clone clone-like like new-sequence new-resizable nth
|
like new-sequence new-resizable nth nth-unsafe
|
||||||
nth-unsafe set-nth set-nth-unsafe length set-length
|
set-nth set-nth-unsafe length set-length
|
||||||
lengthen ;
|
lengthen ;
|
||||||
|
|
||||||
PROTOCOL: assoc-protocol
|
PROTOCOL: assoc-protocol
|
||||||
at* assoc-size >alist set-at assoc-clone-like
|
at* assoc-size >alist set-at assoc-clone-like
|
||||||
delete-at clear-assoc new-assoc assoc-like ;
|
delete-at clear-assoc new-assoc assoc-like ;
|
||||||
|
|
||||||
PROTOCOL: input-stream-protocol
|
PROTOCOL: input-stream-protocol
|
||||||
stream-read1 stream-read stream-read-partial stream-readln
|
stream-read1 stream-read stream-read-partial stream-readln
|
||||||
stream-read-until ;
|
stream-read-until ;
|
||||||
|
|
||||||
PROTOCOL: output-stream-protocol
|
PROTOCOL: output-stream-protocol
|
||||||
stream-flush stream-write1 stream-write stream-format
|
stream-flush stream-write1 stream-write stream-nl ;
|
||||||
stream-nl make-span-stream make-block-stream
|
|
||||||
make-cell-stream stream-write-table ;
|
|
||||||
|
|
||||||
PROTOCOL: definition-protocol
|
PROTOCOL: definition-protocol
|
||||||
where set-where forget uses
|
where set-where forget uses
|
||||||
synopsis* definer definition ;
|
synopsis* definer definition ;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2005, 2008 Slava Pestov.
|
! Copyright (C) 2005, 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel continuations destructors io io.encodings
|
USING: kernel continuations destructors io io.encodings
|
||||||
io.encodings.private io.timeouts io.ports summary
|
io.encodings.private io.timeouts io.ports io.styles summary
|
||||||
accessors delegate delegate.protocols ;
|
accessors delegate delegate.protocols ;
|
||||||
IN: io.streams.duplex
|
IN: io.streams.duplex
|
||||||
|
|
||||||
|
@ -10,35 +10,33 @@ TUPLE: duplex-stream in out ;
|
||||||
C: <duplex-stream> duplex-stream
|
C: <duplex-stream> duplex-stream
|
||||||
|
|
||||||
CONSULT: input-stream-protocol duplex-stream in>> ;
|
CONSULT: input-stream-protocol duplex-stream in>> ;
|
||||||
|
|
||||||
CONSULT: output-stream-protocol duplex-stream out>> ;
|
CONSULT: output-stream-protocol duplex-stream out>> ;
|
||||||
|
CONSULT: formatted-output-stream-protocol duplex-stream out>> ;
|
||||||
|
|
||||||
|
: >duplex-stream< ( stream -- in out ) [ in>> ] [ out>> ] bi ; inline
|
||||||
|
|
||||||
M: duplex-stream set-timeout
|
M: duplex-stream set-timeout
|
||||||
[ in>> set-timeout ] [ out>> set-timeout ] 2bi ;
|
>duplex-stream< [ set-timeout ] bi-curry@ bi ;
|
||||||
|
|
||||||
M: duplex-stream dispose
|
M: duplex-stream dispose
|
||||||
#! The output stream is closed first, in case both streams
|
#! The output stream is closed first, in case both streams
|
||||||
#! are attached to the same file descriptor, the output
|
#! are attached to the same file descriptor, the output
|
||||||
#! buffer needs to be flushed before we close the fd.
|
#! buffer needs to be flushed before we close the fd.
|
||||||
[
|
[ >duplex-stream< [ &dispose drop ] bi@ ] with-destructors ;
|
||||||
[ in>> &dispose drop ]
|
|
||||||
[ out>> &dispose drop ]
|
|
||||||
bi
|
|
||||||
] with-destructors ;
|
|
||||||
|
|
||||||
: <encoder-duplex> ( stream-in stream-out encoding -- duplex )
|
: <encoder-duplex> ( stream-in stream-out encoding -- duplex )
|
||||||
[ re-decode ] [ re-encode ] bi-curry bi* <duplex-stream> ;
|
[ re-decode ] [ re-encode ] bi-curry bi* <duplex-stream> ;
|
||||||
|
|
||||||
: with-stream* ( stream quot -- )
|
: with-stream* ( stream quot -- )
|
||||||
[ [ in>> ] [ out>> ] bi ] dip with-streams* ; inline
|
[ >duplex-stream< ] dip with-streams* ; inline
|
||||||
|
|
||||||
: with-stream ( stream quot -- )
|
: with-stream ( stream quot -- )
|
||||||
[ [ in>> ] [ out>> ] bi ] dip with-streams ; inline
|
[ >duplex-stream< ] dip with-streams ; inline
|
||||||
|
|
||||||
ERROR: invalid-duplex-stream ;
|
ERROR: invalid-duplex-stream ;
|
||||||
|
|
||||||
M: duplex-stream underlying-handle
|
M: duplex-stream underlying-handle
|
||||||
[ in>> underlying-handle ]
|
>duplex-stream<
|
||||||
[ out>> underlying-handle ] bi
|
[ underlying-handle ] bi@
|
||||||
[ = [ invalid-duplex-stream ] when ] keep ;
|
[ = [ invalid-duplex-stream ] when ] keep ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue