I am trying to convert some FastCGI sample code provided by Coast Research & Development (http://www.coastrd.com
) from PowerBasic to Delphi.
First off, Coast R&D have provided a free FastCGI API (libfcgi2.dll) which includes a SIGTERM handler for IIS. Coast R&D also provide headers for PowerBasic, and Delphi (among others). They have also written some sample applications in PowerBasic, but no examples for Delphi. So I have tried to convert the PowerBasic example (Which I have compiled and tested successfully in Powerbasic), unfortunately I am having no luck with the Delphi code.
The PowerBasic code is as follows,
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
Now my failed conversion attempt...
FCGX_InitRequest(FCGXReq, 0, 0);
while True do // Main Request processing loop
// 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
From what I can make out IIS fails with an Error 500 on the first line of code 'FCGX_InitRequest(FCGXReq,
0, 0);' I have tried passing in a pointer to the structure but the compiler rejects it.
Any ideas will much appreciated.