home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / iis4_07.cab / KeepAlive.c < prev    next >
C/C++ Source or Header  |  1997-10-25  |  3KB  |  154 lines

  1. /*++
  2.  
  3. Copyright (c) 1997  Microsoft Corporation
  4.  
  5. Module Name:    KeepAlive.c
  6.  
  7. Abstract:
  8.  
  9.    Sample ISAPI Extension demonstrating Keep-Alive.
  10.  
  11. --*/
  12.  
  13. #define WIN32_LEAN_AND_MEAN
  14. #include <windows.h>
  15. #include <httpext.h>
  16. #include <stdio.h>
  17.  
  18.  
  19. BOOL WINAPI 
  20. GetExtensionVersion(
  21.     OUT HSE_VERSION_INFO * pVer
  22.     )
  23. /*++
  24.  
  25. Purpose:
  26.  
  27.     This is required ISAPI Extension DLL entry point.
  28.  
  29. Arguments:
  30.  
  31.     pVer - poins to extension version info structure 
  32.  
  33. Returns:
  34.  
  35.     always returns TRUE
  36.  
  37. --*/
  38. {
  39.     pVer->dwExtensionVersion = MAKELONG(HSE_VERSION_MINOR, HSE_VERSION_MAJOR);
  40.  
  41.     strncpy( 
  42.         pVer->lpszExtensionDesc,
  43.         "ISAPI Keep-Alive Extension Sample",
  44.         HSE_MAX_EXT_DLL_NAME_LEN 
  45.         );
  46.  
  47.     return TRUE;
  48. }
  49.  
  50.  
  51. DWORD WINAPI 
  52. HttpExtensionProc(
  53.     IN EXTENSION_CONTROL_BLOCK * pECB
  54.     )
  55. /*++
  56.  
  57. Purpose:
  58.     Demonstrate persistent connection from ISAPI extension DLL.
  59.  
  60. Arguments:
  61.  
  62.     pECB - pointer to the extenstion control block 
  63.  
  64. Returns:
  65.  
  66.     HSE_STATUS_SUCCESS_AND_KEEP_CONN
  67.  
  68. --*/
  69. {
  70.     //
  71.     // Use the "Connection: Keep-Alive" header to keep the connection open;
  72.     // also, the "Content-Length:" header is required, so that the client knows when
  73.     // the server has finished. 
  74.     //
  75.  
  76.     char szHeader[] = 
  77.         "Connection: Keep-Alive\r\n"
  78.         "Content-Length: %lu\r\n"
  79.         "Content-type: text/html\r\n\r\n";
  80.  
  81.     char szContent[] = 
  82.         "<html> <form method=get action=\\scripts\\KeepAlive.dll>"
  83.         "<h1>Keep-Alive Sample</h1><hr>"
  84.         "<input type=submit value=\"Send Request\"></form></html>";
  85.  
  86.     char szBuffer[4096];
  87.     HSE_SEND_HEADER_EX_INFO HeaderExInfo;
  88.     DWORD dwSize;
  89.  
  90.     //
  91.     // Send outgoing header with exact content length
  92.     //
  93.     
  94.     sprintf( szBuffer, szHeader, strlen( szContent ) );
  95.     HeaderExInfo.pszHeader = szBuffer;
  96.     HeaderExInfo.cchHeader = strlen( szBuffer );
  97.     HeaderExInfo.pszStatus = "200 OK";
  98.     HeaderExInfo.cchStatus = strlen( HeaderExInfo.pszStatus );
  99.     HeaderExInfo.fKeepConn = TRUE;
  100.  
  101.     pECB->ServerSupportFunction( 
  102.         pECB,
  103.         HSE_REQ_SEND_RESPONSE_HEADER_EX,
  104.         &HeaderExInfo,
  105.         NULL,
  106.         NULL
  107.         );
  108.  
  109.  
  110.     //
  111.     // Send content
  112.     //
  113.  
  114.     dwSize = strlen( szContent );
  115.  
  116.     pECB->WriteClient( pECB, szContent, &dwSize, HSE_IO_SYNC );
  117.  
  118.  
  119.     //
  120.     // This return code tells IIS not to close the socket connection.
  121.     //
  122.  
  123.     return HSE_STATUS_SUCCESS_AND_KEEP_CONN;
  124. }
  125.  
  126.  
  127. BOOL WINAPI
  128. TerminateExtension(
  129.     IN DWORD dwFlags
  130.     )
  131. /*++
  132.  
  133. Purpose:
  134.  
  135.     This is optional ISAPI extension DLL entry point.
  136.     If present, it will be called before unloading the DLL,
  137.     giving it a chance to perform any shutdown procedures.
  138.     
  139. Arguments:
  140.     
  141.     dwFlags - HSE_TERM_ADVISORY_UNLOAD or HSE_TERM_MUST_UNLOAD
  142.  
  143. Return Value:
  144.  
  145.     TRUE if extension is ready to be unloaded,
  146.     FALSE otherwise
  147.     
  148. --*/
  149. {
  150.     return TRUE;
  151. }
  152.  
  153.  
  154.