Chapter 5
Winsock I/O Methods
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.
Winsock features two socket modes: blocking and non-blocking. 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: blocking, 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 non-blocking socket operating modes. However, not every I/O model is available for every platform. As you can see in Table 5-1, only one of the I/O models is available under current versions of Windows CE. Windows 95, Windows 98, and Windows Me (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 later versions.
Platform | Block-ing | Non-blocking Select | WSAAsync Select | WSAEvent Select | Over-lapped | Completion Port |
Windows CE | Yes | Yes | No | No | No | No |
Windows 95 (Winsock 1) | Yes | Yes | Yes | No | No | No |
Windows 95 (Winsock 2) | Yes | Yes | Yes | Yes | Yes | No |
Windows 98 | Yes | Yes | Yes | Yes | Yes | No |
Windows Me | Yes | Yes | Yes | Yes | Yes | No |
Windows NT | Yes | Yes | Yes | Yes | Yes | Yes |
Windows 2000 | Yes | Yes | Yes | Yes | Yes | Yes |
Windows XP | Yes | Yes | Yes | Yes | Yes | Yes |