home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 9 / IOPROG_9.ISO / contrib / iis4 / iis4_07.cab / KeepAlive.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-05  |  1.8 KB  |  64 lines

  1. // KeepAlive.c  -> Sample ISAPI Extension demonstrating Keep-Alive
  2.  
  3.  
  4. #define _WIN32_WINNT 0x0400
  5.  
  6.  
  7. #include <windows.h>
  8. #include <httpext.h>
  9. #include <stdio.h>
  10.  
  11.  
  12. BOOL WINAPI GetExtensionVersion(HSE_VERSION_INFO *pVer)
  13. {
  14.     pVer->dwExtensionVersion = MAKELONG(HSE_VERSION_MINOR, HSE_VERSION_MAJOR);
  15.     
  16.     lstrcpyn( pVer->lpszExtensionDesc, 
  17.               "ISAPI Keep-Alive Extension Sample", 
  18.               HSE_MAX_EXT_DLL_NAME_LEN );
  19.  
  20.     return TRUE;
  21. }
  22.  
  23.  
  24. DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK *pECB)
  25. {
  26.     DWORD dwSize;
  27.  
  28.     // Use the "Connection: Keep-Alive" header to keep the connection open;
  29.     // also, the "Content-Length:" header is required, so that the client knows when
  30.     // the server has finished. 
  31.  
  32.     char szHeader[] =   "Connection: Keep-Alive\r\nContent-Length: %lu\r\nContent-type: text/html\r\n\r\n";
  33.     char szContent[] =  "<html> <form method=get action=KeepAlive.dll> <h1>Keep-Alive Sample</h1><hr>" 
  34.                         "<input type=submit value=\"Send Request\"> </form></html>";
  35.     char szBuffer[4096];
  36.  
  37.  
  38.     // Send outgoing header with exact content length
  39.     
  40.     sprintf(szBuffer, szHeader, strlen(szContent));
  41.     dwSize = strlen(szBuffer);
  42.     
  43.     pECB->ServerSupportFunction( pECB, 
  44.                                  HSE_REQ_SEND_RESPONSE_HEADER,
  45.                                  NULL, 
  46.                                  &dwSize, 
  47.                                  (unsigned long *) szBuffer );
  48.     
  49.  
  50.     // Send content
  51.     
  52.     dwSize = strlen(szContent);
  53.  
  54.     pECB->WriteClient( pECB, 
  55.                        szContent, 
  56.                        &dwSize, 
  57.                        0 );
  58.  
  59.  
  60.     // This return code tells IIS not to close the socket connection.
  61.  
  62.     return HSE_STATUS_SUCCESS_AND_KEEP_CONN;
  63. }
  64.