1 USING: io io.buffers io.backend help.markup help.syntax kernel
2 byte-arrays sbufs words continuations destructors
6 ARTICLE: "io.ports" "Non-blocking I/O implementation"
7 "On Windows and Unix, Factor implements blocking file and network streams on top of a non-blocking I/O substrate, ensuring that Factor threads will yield when performing I/O. This substrate is implemented in the " { $vocab-link "io.ports" } " vocabulary."
9 "A " { $emphasis "port" } " is a stream using non-blocking I/O substrate:"
11 { $subsection <port> }
12 { $subsection <buffered-port> }
14 { $subsection input-port }
15 { $subsection <input-port> }
17 { $subsection output-port }
18 { $subsection <output-port> }
19 "Global native I/O protocol:"
20 { $subsection io-backend }
21 { $subsection init-io }
22 { $subsection init-stdio }
23 { $subsection io-multiplex }
24 "Per-port native I/O protocol:"
25 { $subsection (wait-to-read) }
26 { $subsection (wait-to-write) }
27 "Additionally, the I/O backend must provide an implementation of the " { $link dispose } " generic word." ;
32 { $class-description "Instances of this class present a blocking stream interface on top of an underlying non-blocking I/O system, giving the illusion of blocking by yielding the thread which is waiting for input or output." } ;
35 { $class-description "The class of ports implementing the input stream protocol." } ;
38 { $class-description "The class of ports implementing the output stream protocol." } ;
41 { $values { "handle" "a native handle identifying an I/O resource" } { "class" class } { "port" "a new " { $link port } } }
42 { $description "Creates a new " { $link port } " with no buffer." }
46 { $values { "handle" "a native handle identifying an I/O resource" } { "class" class } { "port" "a new " { $link port } } }
47 { $description "Creates a new " { $link port } " using the specified native handle and a default-sized I/O buffer." }
51 { $values { "handle" "a native handle identifying an I/O resource" } { "input-port" "a new " { $link input-port } } }
52 { $description "Creates a new " { $link input-port } " using the specified native handle and a default-sized input buffer." }
56 { $values { "handle" "a native handle identifying an I/O resource" } { "output-port" "a new " { $link output-port } } }
57 { $description "Creates a new " { $link output-port } " using the specified native handle and a default-sized input buffer." }
61 { $values { "port" input-port } }
62 { $contract "Suspends the current thread until the port's buffer has data available for reading." } ;
65 { $values { "port" input-port } { "eof?" "a boolean" } }
66 { $description "If the port's buffer has unread data, returns immediately, otherwise suspends the current thread until some data is available for reading. If the buffer was empty and no more data could be read, outputs " { $link t } " to indicate end-of-file; otherwise outputs " { $link f } "." } ;