[FASTCGI] A new newbie -> use a pure socket for communictaion
Maurus Frey
m.frey at avelon-cetex.com
Tue Sep 8 16:46:28 EDT 2009
Hi,
I try to connect a C++ application on a embedded device to the web
through fastcgi.
For the first test I reused the code by E. Bareev already published on
this list during August. (Thanks)
Instead of using a port, I want to use a unix Socket.
...........code............
#include <string>
#include "fcgi_stdio.h"
#include <stdlib.h>
#include <iostream>
void handle(FCGX_Request request){
FCGX_FPrintF(request.out,
"Content-type:text/html\r\n\r\n<TITLE>fastcgi</TITLE>\n<H1>Fastcgi:
Hello world!</H1>\n");
}
int main(int argc, char* const argv[] )
{
std::string port = "/var/run/fastcgitest.socket";
int listenQueueBacklog = 400;
FCGX_Stream *in, *out, *err;
FCGX_ParamArray envp;
if(FCGX_Init()) exit(1);
int listen_socket = FCGX_OpenSocket(port.c_str(), listenQueueBacklog);
if(listen_socket < 0) exit(1);
FCGX_Request request;
if(FCGX_InitRequest(&request, listen_socket, 0)) exit(1);
int reqCounter = 0;
while(FCGX_Accept_r(&request) == 0)
{
handle(request);
reqCounter++;
FCGX_FPrintF(request.out, "\n\r\n\r counter: %d", reqCounter);
FCGX_Finish_r(&request);
}
return 0;
}
...........code............
I got a 500 internal Server Error. Since this is my first fastcgi
project using a socket, I don't really know the problem.
The lighttpd.error log says:
2009-09-08 22:34:45: (mod_fastcgi.c.1761) connect failed: Permission
denied on unix:/var/run/lighttpd/fastcgitest.socket
2009-09-08 22:34:45: (mod_fastcgi.c.2930) backend died; we'll disable it
for 5 seconds and send the request to another backend instead:
reconnects: 0 load: 1
2009-09-08 22:34:51: (mod_fastcgi.c.2743) fcgi-server re-enabled:
unix:/var/run/lighttpd/fastcgitest.socket
The lighttpd.conf looks like this:
fastcgi.debug = 1
fastcgi.server = (
"/test.fcgi" =>
((
"socket" => "/var/run/lighttpd/fastcgitest.socket",
"check-local" => "disable"
))
)
If I start the fcgi-app the socket file
(/var/run/lighttpd/fastcgitest.socket) will be created.
The access rights are: srwxr-xr-x 1 root root 0 2009-09-08 22:34
fastcgitest.socket
Lighttpd runs as root, it should be able to access the socket.
What could be the problem?
Thanks for your support.
Maurus
More information about the FastCGI-developers
mailing list