Summary
Windows has three methods for performing asynchronous I/O. Using threads is the most general and simplest technique and, unlike the other two, works with Windows 9x. Each thread is responsible for a sequence of one or more sequential, blocking I/O operations. Furthermore, each thread should have its own file or pipe handle.Overlapped I/O allows a single thread to perform asynchronous operations on a single file handle, but there must be an event handle, rather than a thread and file handle pair, for each operation. Wait specifically for each I/O operation to complete and then perform any required cleanup or sequencing operations.Extended I/O, on the other hand, automatically invokes the completion code, and it does not require additional events.The one indispensable advantage provided by overlapped I/O is the ability to create I/O completion ports, but, as mentioned previously and illustrated by a program, atouMTCP.c, on the book's Web site, even that advantage is somewhat constrained by the ability to use semaphores to limit the number of active threads in a worker thread pool. The inability to remove handles from a completion port is an additional limitation.
UNIX supports threads through Pthreads, as discussed previously.System V UNIX limits asynchronous I/O to streams and cannot be used for file or pipe operations.BSD Version 4.3 uses a combination of signals (SIGIO) to indicate an event on a file descriptor and select a function to determine the ready state of file descriptors. The file descriptors must be set in the O_ASYNC mode. This approach works only with terminals and network communication. |
Looking Ahead
Chapter 15 completes our discussion of the Windows API by showing how to secure Windows objects. The emphasis is on securing files, but the same techniques are applied to other objects, such as named pipes and processes.