Clean up init-stdio implementations and move io.streams.null to basis

db4
Slava Pestov 2009-05-12 03:35:48 -05:00
parent 6e08e29a3a
commit 96b1ae86a4
8 changed files with 23 additions and 29 deletions

View File

@ -173,10 +173,11 @@ M: stdin refill
size-read-fd <fd> init-fd <input-port> >>size size-read-fd <fd> init-fd <input-port> >>size
data-read-fd <fd> >>data ; data-read-fd <fd> >>data ;
M: unix (init-stdio) M: unix init-stdio
<stdin> <input-port> <stdin> <input-port>
1 <fd> <output-port> 1 <fd> <output-port>
2 <fd> <output-port> t ; 2 <fd> <output-port>
set-stdio ;
! mx io-task for embedding an fd-based mx inside another mx ! mx io-task for embedding an fd-based mx inside another mx
TUPLE: mx-port < port mx ; TUPLE: mx-port < port mx ;

View File

@ -1,9 +1,9 @@
USING: alien alien.c-types arrays assocs combinators USING: alien alien.c-types arrays assocs combinators continuations
continuations destructors io io.backend io.ports io.timeouts destructors io io.backend io.ports io.timeouts io.backend.windows
io.backend.windows io.files.windows io.files.windows.nt io.files io.files.windows io.files.windows.nt io.files io.pathnames io.buffers
io.pathnames io.buffers io.streams.c libc kernel math namespaces io.streams.c io.streams.null libc kernel math namespaces sequences
sequences threads windows windows.errors windows.kernel32 threads windows windows.errors windows.kernel32 strings splitting
strings splitting ascii system accessors locals ; ascii system accessors locals ;
QUALIFIED: windows.winsock QUALIFIED: windows.winsock
IN: io.backend.windows.nt IN: io.backend.windows.nt
@ -140,7 +140,9 @@ M: winnt (wait-to-read) ( port -- )
: console-app? ( -- ? ) GetConsoleWindow >boolean ; : console-app? ( -- ? ) GetConsoleWindow >boolean ;
M: winnt (init-stdio) M: winnt init-stdio
console-app? [ init-c-stdio t ] [ f f f f ] if ; console-app?
[ init-c-stdio ]
[ null-reader null-writer null-writer init-stdio ] if ;
winnt set-io-backend winnt set-io-backend

View File

@ -1,7 +1,7 @@
! Copyright (C) 2007, 2009 Slava Pestov. ! Copyright (C) 2007, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: init kernel system namespaces io io.encodings USING: init kernel system namespaces io io.encodings
io.encodings.utf8 init assocs splitting alien io.streams.null ; io.encodings.utf8 init assocs splitting alien ;
IN: io.backend IN: io.backend
SYMBOL: io-backend SYMBOL: io-backend
@ -12,22 +12,12 @@ io-backend [ c-io-backend ] initialize
HOOK: init-io io-backend ( -- ) HOOK: init-io io-backend ( -- )
HOOK: (init-stdio) io-backend ( -- stdin stdout stderr ? ) HOOK: init-stdio io-backend ( -- )
: set-stdio ( input-handle output-handle error-handle -- ) : set-stdio ( input output error -- )
[ input-stream set-global ] [ utf8 <decoder> input-stream set-global ]
[ output-stream set-global ] [ utf8 <encoder> output-stream set-global ]
[ error-stream set-global ] tri* ; [ utf8 <encoder> error-stream set-global ] tri* ;
: init-stdio ( -- )
(init-stdio) [
[ utf8 <decoder> ]
[ utf8 <encoder> ]
[ utf8 <encoder> ] tri*
] [
3drop
null-reader null-writer null-writer
] if set-stdio ;
HOOK: io-multiplex io-backend ( us -- ) HOOK: io-multiplex io-backend ( us -- )

View File

@ -60,12 +60,13 @@ M: c-io-backend init-io ;
: stdout-handle ( -- alien ) 12 getenv ; : stdout-handle ( -- alien ) 12 getenv ;
: stderr-handle ( -- alien ) 61 getenv ; : stderr-handle ( -- alien ) 61 getenv ;
: init-c-stdio ( -- stdin stdout stderr ) : init-c-stdio ( -- )
stdin-handle <c-reader> stdin-handle <c-reader>
stdout-handle <c-writer> stdout-handle <c-writer>
stderr-handle <c-writer> ; stderr-handle <c-writer>
set-stdio ;
M: c-io-backend (init-stdio) init-c-stdio t ; M: c-io-backend init-stdio init-c-stdio ;
M: c-io-backend io-multiplex 60 60 * 1000 * 1000 * or (sleep) ; M: c-io-backend io-multiplex 60 60 * 1000 * 1000 * or (sleep) ;