Created
August 3, 2011 12:34
-
-
Save tochiz/1122530 to your computer and use it in GitHub Desktop.
C++ fastcgi sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <fcgi_stdio.h> | |
#include <unistd.h> | |
int main( int argc , char * argv[] ) | |
{ | |
int result; | |
unsigned long long cnt = 0; | |
const char* output = NULL; | |
while((result = getopt(argc, (char**)argv, "o:")) != -1){ | |
switch(result){ | |
case 'o': | |
if(optarg) output = optarg; | |
break; | |
} | |
} | |
if(output){ | |
// reading counter. | |
std::ifstream fin( output, std::ios::in | std::ios::binary ); | |
if (fin){ | |
fin >> cnt; | |
} | |
fin.close(); | |
} | |
while (FCGI_Accept () >= 0) | |
{ | |
printf( "Content-Type: text/plain\n\n" ); | |
printf( "%d\n", ++cnt); | |
if(output){ | |
// writing counter. | |
std::ofstream fout; | |
fout.open( output, std::ios::out | std::ios::binary | std::ios::trunc); | |
if (fout) { | |
fout << cnt; | |
} | |
fout.close(); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment