FastCGI with protocol = Tcp on IIS 7
I have tried to use IIS 7 (as included in Windows 7) to test a FastCGI library 开发者_运维技巧I am currently developing.
According to the original FastCGI spec, when an application is called, its stdin
handle is replaced with a socket. By default, IIS uses a named pipe instead, but it is possible to configure it to use TCP, i.e. a socket.
When I try to use this socket in my test application, I get an WSAENOTSOCK
error.
When I try to use a named pipe instead (after reconfiguring IIS), I run into similar problems. For example, I get a ERROR_INVALID_HANDLE
when I try to use PeekNamedPipe
. ReadFile
and WriteFile
however work correctly.
I guess the problem is that this handle is inherited from the parent process and the current process does not really know its exact type. It seems to assume that the handle represents a simple file.
Has anyone run into similar problems and knows a solution/workaround? Can I somehow update the in-process status of my handle such that the WIN32 API function will accept it as a socket/named pipe?
In case anyone else ever stumbles upon this: DuplicateHandle
does the trick.
In fact, the function OS_LibInit
of the libfcgi implementation shows how to start an FastCGI app that got its socket through stdin.
精彩评论