From 0dbaa019d1b51518af694584c9617587740a0940 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 29 Mar 2011 17:13:19 -0700 Subject: [PATCH] iocp-links: Simplify function example --- iocp-links.html | 66 +++++++++++-------------------------------------- 1 file changed, 14 insertions(+), 52 deletions(-) diff --git a/iocp-links.html b/iocp-links.html index da2b8c27b..3a6beb822 100644 --- a/iocp-links.html +++ b/iocp-links.html @@ -24,12 +24,12 @@ table th { text-align: left; - padding: 0.5em; + padding: 0.2em; white-space: nowrap; } table td { - padding: 0.5em; + padding: 0.2em; text-align: left; white-space: nowrap; } @@ -120,70 +120,28 @@ Common practice for accessing the disk asynchronously is still done using custom userland thread pools—not POSIX AIO.

Windows IOCPs does support both sockets and regular file I/O which -greatly simplifies the handling of disks. Although the function names are -not exactly the same in Windows for sockets and regular files, the -they act similar. - - - - - - - - - - - - - - - - - - - - - - - -
Regular File ReadRegular File WriteSocket ReadSocket Write
WindowsReadFile()WriteFile()WSARecv()WSASend()
POSIXread()write()read() or recv()write() or send()
- -

ReadFile() and WSARecv() operate on regular -files and sockets, respectively. They both are for sending data. Both take a -OVERLAPPED -argument. +greatly simplifies the handling of disks. For example, +ReadFileEx() +operates on both. +As a first example let's look at how ReadFile() works.

 typedef void* HANDLE;
-typedef HANDLE SOCKET;
 
 BOOL ReadFile(HANDLE file,
               void* buffer,
               DWORD numberOfBytesToRead,
               DWORD* numberOfBytesRead,
               OVERLAPPED* overlapped);
-
-int WSARecv(SOCKET s,
-            WSABUF* buffers,
-            DWORD bufferCount,
-            DWORD* numberOfBytesRecvd,
-            DWORD* flags,
-            OVERLAPPED* overlapped,
-            OVERLAPPED_COMPLETION_ROUTINE completionRoutine);
 
-For now ignore the completionRoutine parameter in -WSARecv. -

-Both functions have the possibility of executing the read synchronously +The function has the possibility of executing the read synchronously or asynchronously. A synchronous operation is indicated by returning 0 and WSAGetLastError() returning WSA_IO_PENDING. - -

-When either function operates asynchronously the +When ReadFile() operates asynchronously the the user-supplied OVERLAPPED* is a handle to the incomplete operation. @@ -327,13 +285,17 @@ hard limit of 2048 open file descriptors—see

send(2), write(2)
-
Windows: WSASend() +
Windows: +WSASend(), +WriteFileEx()
recv(2), read(2)
-Windows: WSARecv() +Windows: +WSARecv(), +ReadFileEx()