Search code examples
c++socketsassemblyfastcgi

FastCGI application - how to get the listening socket handle?


All examples for the subject are based on some C/C++ libraries like fcgi_stdio and similar. But I want to make a FastCGI script, using assembly language and there is no such libraries.

Almost everything about the protocol and communication is clear, but I still can't understand how the program gets the handle to the listening socket, passed by the web server?

My findings:

I installed the lighttpd server and tried to configure it in order to get fastCGI to work with my programs.

But I was confused, that the configuration file needs "host" and "port" - Is this means the FastCGI should create the listening socket by itself? I mean using socket/bind/listen/accept functions? Then how my application will know these host and port parameters. They are in the web server config file?

The other way lighttpd allows is to specify some named socket path - for example "/tmp/myapp.socket". How my application have to handle this? And how it will know this path?

I tried to make some small program using accept(0, ...) as @user58697 specified in his answer (and this answer is in accordance with the official FastCGI specification!) Unfortunately nothing happened - the call to accept fails miserably!

So, is the communication is server specific?


Solution

  • According to the spec, from the application point of view FCGI_LISTENSOCK_FILENO equals to STDIN_FILENO, which is defined as 0. That means that you shall accept(STDIN_FILENO, ...) or even accept(0, ...).