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
|
USING: io io.pipes io.streams.string io.encodings.utf8
|
||||||
io.streams.duplex io.encodings io.timeouts namespaces
|
io.encodings.binary io.streams.duplex io.encodings io.timeouts
|
||||||
continuations tools.test kernel calendar destructors
|
namespaces continuations tools.test kernel calendar destructors
|
||||||
accessors debugger math ;
|
accessors debugger math sequences ;
|
||||||
IN: io.pipes.tests
|
IN: io.pipes.tests
|
||||||
|
|
||||||
[ "Hello" ] [
|
[ "Hello" ] [
|
||||||
|
@ -28,7 +28,7 @@ IN: io.pipes.tests
|
||||||
|
|
||||||
[
|
[
|
||||||
utf8 <pipe> [
|
utf8 <pipe> [
|
||||||
5 seconds over set-timeout
|
1 seconds over set-timeout
|
||||||
stream-readln
|
stream-readln
|
||||||
] with-disposal
|
] with-disposal
|
||||||
] must-fail
|
] must-fail
|
||||||
|
@ -42,3 +42,12 @@ IN: io.pipes.tests
|
||||||
] curry ignore-errors
|
] curry ignore-errors
|
||||||
] times
|
] times
|
||||||
] unit-test
|
] 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
|
dup wait-to-read [ drop f ] [ buffer>> buffer-pop ] if ; inline
|
||||||
|
|
||||||
: read-step ( count port -- byte-array/f )
|
: 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 )
|
M: input-port stream-read-partial ( max stream -- byte-array/f )
|
||||||
dup check-disposed
|
prepare-read read-step ;
|
||||||
[ 0 max >integer ] dip read-step ;
|
|
||||||
|
|
||||||
: read-loop ( count port accum -- )
|
: read-loop ( count port accum -- )
|
||||||
pick over length - dup 0 > [
|
pick over length - dup 0 > [
|
||||||
|
@ -64,8 +70,7 @@ M: input-port stream-read-partial ( max stream -- byte-array/f )
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
M: input-port stream-read
|
M: input-port stream-read
|
||||||
dup check-disposed
|
prepare-read
|
||||||
[ 0 max >fixnum ] dip
|
|
||||||
2dup read-step dup [
|
2dup read-step dup [
|
||||||
pick over length > [
|
pick over length > [
|
||||||
pick <byte-vector>
|
pick <byte-vector>
|
||||||
|
|
Loading…
Reference in New Issue