durusmail: quixote-users: Solution for Mac OS/NetBSD FastCGI detection problem
Solution for Mac OS/NetBSD FastCGI detection problem
2003-11-25
Solution for Mac OS/NetBSD FastCGI detection problem
Phillip J. Eby
2003-11-25
FYI, the following code has been reported by Mac OS X and NetBSD users to
correctly detect the absence of FastCGI on those platforms:

     def isFastCGI(self):

         import socket, sys

         for family in (socket.AF_UNIX, socket.AF_INET):
             try:
                 s=socket.fromfd(sys.stdin.fileno(),family,socket.SOCK_STREAM)
                 if not s.getsockname():
                     # Socket doesn't have an address; it might be a BSD-style
                     # socketpair() pipe, as used on Mac OS/X and others
                     continue
             except:
                 pass
             else:
                 return True

         return False

BSD-style socketpairs appear to return None (on OS/X) or '' (on NetBSD)
when their 'sockname()' method is called.  Thus, the above code only
returns True if sys.stdin is a socket, but not a socketpair() pipe.

This code also correctly detects the presence of FastCGI on Linux.  It has
not been tested on any other operating systems, to my knowledge.

I'm not a subscriber to this list, as I don't use Quixote.  I'm posting
here because in my Googling to find a solution to the above problem,
earlier discussions on this list pointed me in the right direction to solve
the problem.  So, I thought I'd return the favor.  Hope this is helpful.



reply