Next Previous Contents

1. ISAPI: Build a client extension DLL to read large data

Take good care of reading exact the pECB.cbTotalBytes of data. If you read less bytes than indicated in pECB.cbTotalBytes a 'Connection reset by peer' error occurs in the browser.

1.1 Delphi 3 example


function HttpExtensionProc (var pECB: EXTENSION_CONTROL_BLOCK) : DWORD; export; stdcall;
var
    Data  : Array[0..4096] of Char;
    Response : Array[0..8] of Char;
    dwLen, ToRead : DWord;
 begin
    ...
    // Do something with the pECB.cbAvailable Bytes in pECB.lpbData
    ...
    // How many bytes left to read?
   ToRead:=pECB.cbTotalBytes - pECB.cbAvailable;

    // Our data buffer is limited to 4kByte - dwLen is set to it or the rest
    if ToRead > 4096 then dwLen := 4096 else dwLen := ToRead;

    // Call ReadClient until all Bytes are read
    while (ToRead > 0) and pECB.ReadClient(pECB.ConnID, @Data, @dwLen) do begin
        ... 
       // Do something with the dwLen Bytes in Data
        ...
        // dwLen now contains the read count
        Dec(ToRead, dwLen);
        // Set dwLen again for the next read request
        if ToRead > 4096 then dwLen := 4096 else dwLen := ToRead;
    end;
 
    // Initialize the response header
    StrPCopy(Response, '200 OK');
    pECB.ServerSupportFunction(pECB.ConnID, HSE_REQ_SEND_RESPONSE_HEADER, @Response, nil, nil);

    // We've done it
    result := HSE_STATUS_SUCCESS;
end;

1.2 Debugging a client extension DLL from Delphi

You can easily use the integrated debugger of Delphi/C++ builder when you follow this instructions:

  1. Stop the server. We'll run it as host application for the DLL.
  2. Open Menu 'Start|Parameters':
    1. host application = C:\Pi3Web\bin\enhpi3.exe
    2. command line = /START C:\Pi3Web\Conf\Config.pi3

1.3 Related flags in the ISAPI handler object of the server configuration file

Some options are new in the ISAPI handler since server version 1.1:


Next Previous Contents