io.ports: calling '0 read' now returns an empty sequence without blocking (reported by Brennan Cheung)
parent
723d780703
commit
6e3dee43d4
|
@ -1,7 +1,7 @@
|
|||
USING: io io.pipes io.streams.string io.encodings.utf8
|
||||
io.streams.duplex io.encodings io.timeouts namespaces
|
||||
continuations tools.test kernel calendar destructors
|
||||
accessors debugger math ;
|
||||
io.encodings.binary io.streams.duplex io.encodings io.timeouts
|
||||
namespaces continuations tools.test kernel calendar destructors
|
||||
accessors debugger math sequences ;
|
||||
IN: io.pipes.tests
|
||||
|
||||
[ "Hello" ] [
|
||||
|
@ -28,7 +28,7 @@ IN: io.pipes.tests
|
|||
|
||||
[
|
||||
utf8 <pipe> [
|
||||
5 seconds over set-timeout
|
||||
1 seconds over set-timeout
|
||||
stream-readln
|
||||
] with-disposal
|
||||
] must-fail
|
||||
|
@ -42,3 +42,12 @@ IN: io.pipes.tests
|
|||
] curry ignore-errors
|
||||
] times
|
||||
] unit-test
|
||||
|
||||
! 0 read should not block
|
||||
[ f ] [
|
||||
[
|
||||
binary <pipe> &dispose
|
||||
in>>
|
||||
[ 0 read ] with-input-stream
|
||||
] with-destructors
|
||||
] unit-test
|
||||
|
|
|
@ -46,11 +46,17 @@ M: input-port stream-read1
|
|||
dup wait-to-read [ drop f ] [ buffer>> buffer-pop ] if ; inline
|
||||
|
||||
: read-step ( count port -- byte-array/f )
|
||||
dup wait-to-read [ 2drop f ] [ buffer>> buffer-read ] if ;
|
||||
{
|
||||
{ [ over 0 = ] [ 2drop f ] }
|
||||
{ [ dup wait-to-read ] [ 2drop f ] }
|
||||
[ buffer>> buffer-read ]
|
||||
} cond ;
|
||||
|
||||
: prepare-read ( count stream -- count stream )
|
||||
dup check-disposed [ 0 max >fixnum ] dip ; inline
|
||||
|
||||
M: input-port stream-read-partial ( max stream -- byte-array/f )
|
||||
dup check-disposed
|
||||
[ 0 max >integer ] dip read-step ;
|
||||
prepare-read read-step ;
|
||||
|
||||
: read-loop ( count port accum -- )
|
||||
pick over length - dup 0 > [
|
||||
|
@ -64,8 +70,7 @@ M: input-port stream-read-partial ( max stream -- byte-array/f )
|
|||
] if ;
|
||||
|
||||
M: input-port stream-read
|
||||
dup check-disposed
|
||||
[ 0 max >fixnum ] dip
|
||||
prepare-read
|
||||
2dup read-step dup [
|
||||
pick over length > [
|
||||
pick <byte-vector>
|
||||
|
|
Loading…
Reference in New Issue