OS.IO
structure
signature OS_IO
structure IO
: OS_IO
The OS.IO
structure provides a general interface for polling I/O devices. This interface has been modeled after the Unix SVR4 poll interface. A poll_desc
, created from an I/O descriptor, can be used to test for various polling conditions.
eqtype iodesc
val hash : iodesc -> word
val compare : iodesc * iodesc -> order
eqtype iodesc_kind
val kind : iodesc -> iodesc_kind
structure Kind : sig
val file : iodesc_kind
val dir : iodesc_kind
val symlink : iodesc_kind
val tty : iodesc_kind
val pipe : iodesc_kind
val socket : iodesc_kind
val device : iodesc_kind
end
eqtype poll_desc
type poll_info
val pollDesc : iodesc -> poll_desc option
val pollToIODesc : poll_desc -> iodesc
exception Poll
val pollIn : poll_desc -> poll_desc
val pollOut : poll_desc -> poll_desc
val pollPri : poll_desc -> poll_desc
val poll : poll_desc list * Time.time option
-> poll_info list
val isIn : poll_info -> bool
val isOut : poll_info -> bool
val isPri : poll_info -> bool
val infoToPollDesc : poll_info -> poll_desc
eqtype iodesc
iodesc
is an abstraction for an opened OS object that supports I/O (e.g., a file, console, or socket). In Unix, an iodesc
corresponds to a file descriptor, while in Microsoft Windows it corresponds to a file handle.
Since iodesc
values correspond to low-level, OS-specific objects, they are not typically created explicitly by the user, but are generated as a side-effect of the creation of a more high-level abstraction. For example, TextIO.openIn
creates an instream
value, from which the underlying PrimIO.reader
can be accessed. This latter value may contain the corresponding iodesc
value.
If the underlying operating system is known, there will usually be mechanisms for converting between iodesc
values and the type of value used by the operating system. For example, the functions Posix.FileSys.fdToIOD
and Posix.FileSys.iodToFD
provide this service for POSIX implementations, translating between iodesc
s and open file descriptors.
hash iod
Implementation note:
hash
must have the property that values produced are well distributed when taken modulo 2(n) for any n.
compare (iod, iod')
LESS
, EQUAL
, or GREATER
when iod is less than, equal to, or greater than iod', respectively, in some underlying linear ordering on iodesc
values.
eqtype iodesc_kind
iodesc
represents. The possible values are defined in the Kind
substructure.
kind iod
OS.SysErr
if, for example, iod refers to a closed file.
structure Kind
val file : iodesc_kind
val dir : iodesc_kind
val symlink : iodesc_kind
val tty : iodesc_kind
val pipe : iodesc_kind
val socket : iodesc_kind
val device : iodesc_kind
file
BinIO
or TextIO
file opening operations will always have this kind.
dir
OS.FileSys.isDir
returns true
will have this kind.
symlink
OS.FileSys.isLink
returns true
will have this kind.
tty
pipe
socket
device
iodesc
values not covered by these definitions.
eqtype poll_desc
type poll_info
poll
operation.
pollDesc iod
NONE
is returned when no polling is supported by the I/O device.
pollToIODesc pd
pollIn pd
pollOut pd
pollPri pd
Poll
if input (respectively, output, high-priority events) is not appropriate for the underlying I/O device.
poll (l, timeout)
NONE
means wait indefinitely.
SOME
(Time.zeroTime)
means do not block.
SOME
(t)
means timeout after time t
.
poll_info
values corresponding to those descriptors in l whose conditions are enabled. The returned list respects the order of the argument list, and a value in the returned list will reflect a (nonempty) subset of the conditions specified in the corresponding argument descriptor. The poll
function will raise OS.SysErr
if, for example, one of the file descriptors refers to a closed file.
isIn info
isOut info
isPri info
true
if input (respectively, output, priority information) is present in info.
infoToPollDesc pi
PRIM_IO
,OS
Question:
Why are the file attributes only available for open files?
Generated October 02, 2003
Last Modified July 1, 2002
Comments to John Reppy.
This document may be distributed freely over the internet as long as the copyright notice and license terms below are prominently displayed within every machine-readable copy.
Copyright © 2003 AT&T and Lucent Technologies. All rights reserved.
Permission is granted for internet users to make one paper copy for their
own personal use. Further hardcopy reproduction is strictly prohibited.
Permission to distribute the HTML document electronically on any medium
other than the internet must be requested from the copyright holders by
contacting the editors.
Printed versions of the SML Basis Manual are available from Cambridge
University Press.
To order, please visit
www.cup.org (North America) or
www.cup.cam.ac.uk (outside North America). |