From Vincent Mahnke, 11 Years ago, written in C++.
Embed
  1. // HttpdDemo.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5.  
  6. volatile bool g_bQuit = false;
  7. volatile long g_iThreadCount = 0;
  8. char g_sContentPath[512];
  9.  
  10. void MainThread(void*);
  11. void ConnectionThread(void*);
  12.  
  13.  
  14. int _tmain(int argc, _TCHAR* argv[])
  15. {
  16.         ::GetModuleFileNameA(NULL, g_sContentPath, 512);
  17.  
  18.         {
  19.                 int i = strlen(g_sContentPath) - 1;
  20.                
  21.                 while ((i >= 0) && (g_sContentPath[i] != '\\')) {
  22.                         i--;
  23.                 }
  24.                
  25.                 i--;
  26.                
  27.                 while ((i >= 0) && (g_sContentPath[i] != '\\')) {
  28.                         i--;
  29.                 }
  30.  
  31.                 g_sContentPath[i + 1] = 0;
  32.                 strcat(g_sContentPath, "content");
  33.  
  34.         };
  35.  
  36.         {
  37.                 WSADATA WSAData;
  38.                 WSAStartup(MAKEWORD(2, 1), &WSAData);
  39.         }
  40.  
  41.         printf("Starting in path %s\r\n", g_sContentPath);
  42.  
  43.         while (!g_bQuit) {
  44.                 if (kbhit()) {
  45.                         char c = getch();
  46.                         if (c == 27) {
  47.                                 g_bQuit = true;
  48.                         }
  49.                 }
  50.                 ::Sleep(50);
  51.         }
  52.  
  53.         printf("Waiting for threads to finish...\r\n");
  54.         while (g_iThreadCount > 0) {
  55.                 ::Sleep(50);
  56.         }
  57.         printf("Finished.\r\n");
  58.         ::WSACleanup();
  59.  
  60.         return 0;
  61. }