ISAPI supports asynchronous I/O operations in three ways. First, your extension can write to the client asynchronously by calling the WriteClient callback function with the dwReserved parameter set to HSE_IO_ASYNC. Your extension can read from the client asynchronously by calling the ServerSupportFunction callback function with the dwHSERequest parameter set to HSE_REQ_ASYNC_READ_CLIENT. Finally, your extension can utilize the Win32® TransmitFile function to transmit a file quickly using the Winsock socket handle. To use TransmitFile, your extension calls the ServerSupportFunction with the dwHSERequest parameter set to HSE_REQ_TRANSMIT_FILE.
The following code establishes an asynchronous reading from a client.
DWORD
DoAsyncRC(
LPEXTENSION_CONTROL_BLOCK pecb
)
{
char szHeader[256] = "";
BOOL fReturn = TRUE;
DWORD dwFlags;
DWORD cbTotalToRead = MAX_BUF_SIZE;
DWORD hseStatus = HSE_STATUS_PENDING;
//
// Initialize the context for ReadClient
//
pByteReadSoFar = &(pecb->cbAvailable);
fReturn =
pecb->ServerSupportFunction(
pecb->ConnID,
HSE_REQ_IO_COMPLETION,
AsyncReadClientIoCompletion,
0,
pByteReadSoFar);
if (!fReturn) {
hseStatus = HSE_STATUS_ERROR;
}
dwFlags = HSE_IO_ASYNC;
fReturn =
pecb->ServerSupportFunction(
pecb->ConnID,
HSE_REQ_ASYNC_READ_CLIENT,
g_ReadBuffer,
&cbTotalToRead,
&dwFlags);
if (!fReturn) {
hseStatus = HSE_STATUS_ERROR;
}
return (hseStatus);
}
For a complete working sample that performs an asynchronous read from a client, see Developer Samples.