asked on
#COMPILE EXE
#INCLUDE "FCGX_Header.inc"
FUNCTION PBMAIN
LOCAL sReply AS STRING
LOCAL FCGXReq AS FCGX_REQUEST '// FCGX Structure
'// Create the STDIN/STDOUT/STDERR buffers, Connect with the Web Server via FCGI Library
CALL FCGX_InitRequest(VARPTR(FCGXReq) , 0, 0)
DO '// Main Request processing loop
'// Execution blocked here until an HTTP request arrives
IF FCGX_Accept_r(VARPTR(FCGXReq) ) < 0 THEN EXIT LOOP '// SIGTERM/Error recieved - jump out and cleanup
'// The reply must begin with a valid HTTP header
sReply = "Content-Type: text/html"+$CRLF+$CRLF
sReply = sReply + "ReqCount=" + STR$(FCGXReq.ReqCount)
'// Add the Reply string to the STDOUT buffer
IF FCGX_PutStr( STRPTR(sReply), LEN(sReply), FCGXReq.pOut ) < 0 THEN EXIT LOOP '// Error Occured
LOOP '// STDOUT is sent when FCGX_Accept_r is called again
END FUNCTION
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils, libfcgi2;
var
FCGXReq :FCGX_Request;
sReply :WideString;
begin
FCGX_InitRequest(FCGXReq, 0, 0);
while True do // Main Request processing loop
begin
// Execution blocked here until an HTTP request arrives
if FCGX_Accept_r(FCGXReq) < 0 then break; // SIGTERM/Error recieved - jump out and cleanup
// The reply must begin with a valid HTTP header
sReply := 'Content-Type: text/html' + #13#10 +#13#10;
sReply := sReply + 'ReqCount=' + IntToStr(FCGXReq.ReqCount);
// Add the Reply string to the STDOUT buffer
IF FCGX_PutStr(PWideChar(sReply), Length(sReply), FCGXReq.pOut ) < 0 then break // Error Occured
end;
end.