factor/library/io/io-internals.factor

49 lines
1.3 KiB
Factor
Raw Normal View History

! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
2004-11-25 21:53:27 -05:00
IN: io-internals
USING: kernel kernel-internals strings threads ;
2004-11-25 21:53:27 -05:00
BUILTIN: port 14 ;
2004-11-25 21:53:27 -05:00
: stdin 0 getenv ;
: stdout 1 getenv ;
: blocking-flush ( port -- )
2005-04-22 00:22:36 -04:00
[ add-write-io-task stop ] callcc0 drop ;
2004-11-25 21:53:27 -05:00
: wait-to-write ( len port -- )
tuck can-write? [ drop ] [ blocking-flush ] ifte ;
: blocking-write ( str port -- )
over
dup string? [ string-length ] [ drop 1 ] ifte
2004-11-25 21:53:27 -05:00
over wait-to-write write-fd-8 ;
: blocking-fill ( port -- )
2005-04-22 00:22:36 -04:00
[ add-read-line-io-task stop ] callcc0 drop ;
2004-11-25 21:53:27 -05:00
: wait-to-read-line ( port -- )
dup can-read-line? [ drop ] [ blocking-fill ] ifte ;
: blocking-read-line ( port -- line )
dup wait-to-read-line read-line-fd-8 dup [ sbuf>string ] when ;
2004-11-25 21:53:27 -05:00
2005-02-14 22:15:02 -05:00
: fill-fd ( count port -- )
2005-04-22 00:22:36 -04:00
[ add-read-count-io-task stop ] callcc0 2drop ;
2004-11-25 21:53:27 -05:00
2005-02-14 22:15:02 -05:00
: wait-to-read ( count port -- )
2dup can-read-count? [ 2drop ] [ fill-fd ] ifte ;
2004-11-25 21:53:27 -05:00
2005-02-14 22:15:02 -05:00
: blocking-read ( count port -- str )
2dup wait-to-read read-count-fd-8 dup [ sbuf>string ] when ;
2004-11-25 21:53:27 -05:00
: wait-to-accept ( socket -- )
2005-04-22 00:22:36 -04:00
[ add-accept-io-task stop ] callcc0 drop ;
2004-11-25 21:53:27 -05:00
: blocking-accept ( socket -- host port in out )
dup wait-to-accept accept-fd ;
: blocking-copy ( in out -- )
2005-04-22 00:22:36 -04:00
[ add-copy-io-task stop ] callcc0
2004-11-25 21:53:27 -05:00
pending-io-error pending-io-error ;