This chapter focuses on managing I/O in a Windows sockets application. Winsock features socket modes and socket I/O models to control how I/O is processed on a socket. A socket mode simply determines how Winsock functions behave when called with a socket. A socket model, on the other hand, describes how an application manages and processes I/O on a socket. Socket I/O models are independent of socket modes. You will find that socket models are available to overcome the limitations of socket modes.
Winsock features two socket modes: blocking and nonblocking. The first part of this chapter describes these modes in detail and demonstrates how an application can use them to manage I/O. As you'll see later in the chapter, Winsock offers some interesting I/O models that help applications manage communication on one or more sockets at a time in an asynchronous fashion: select, WSAAsyncSelect, WSAEventSelect, overlapped I/O, and completion port. By the chapter's end, we'll review the pros and cons of the various socket modes and I/O models and help you decide which one best meets your application's needs.
All Windows platforms offer blocking and nonblocking socket operating modes. However, not every I/O model is available for every platform. As you can see in Table 8-1, only one of the I/O models is available under current versions of Windows CE. Windows 98 and Windows 95 (depending on whether you have Winsock version 1 or 2) support most of the I/O models with the exception of I/O completion ports. Every I/O model is available on Windows NT and Windows 2000.
Table 8-1. Available socket I/O models
Platform | select | WSAAsync Select | WSAEvent Select | Overlapped | Completion Port |
---|---|---|---|---|---|
Windows CE | Yes | No | No | No | No |
Windows 95 (Winsock 1) | Yes | Yes | No | No | No |
Windows 95 (Winsock 2) | Yes | Yes | Yes | Yes | No |
Windows 98 | Yes | Yes | Yes | Yes | No |
Windows NT | Yes | Yes | Yes | Yes | Yes |
Windows 2000 | Yes | Yes | Yes | Yes | Yes |