Changeset 45:ca72a5901070

Show
Ignore:
Timestamp:
11/24/06 18:00:02 (2 years ago)
Author:
Allan Saddi <allan@saddi.com>
branch:
default
convert_revision:
svn:46762da8-4eb7-0310-94e9-d918b60927c8/flup/trunk@2111
Message:

Experimental support for SCGI over UNIX domain sockets.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • flup/client/scgi_app.py

    r44 r45  
    137137 
    138138    def _getConnection(self): 
    139         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
     139        if type(self._connect) is str: 
     140            sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) 
     141        else: 
     142            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
    140143        sock.connect(self._connect) 
    141144        return sock 
  • flup/server/scgi.py

    r32 r45  
    9090    def __init__(self, application, scriptName='', environ=None, 
    9191                 multithreaded=True, multiprocess=False, 
    92                  bindAddress=('localhost', 4000), allowedServers=None, 
     92                 bindAddress=('localhost', 4000), umask=None, 
     93                 allowedServers=None, 
    9394                 loggingLevel=logging.INFO, debug=True, **kw): 
    9495        """ 
     
    101102        environment variables you want to pass to your application. 
    102103 
    103         bindAddress is the address to bind to, which must be a tuple of 
    104         length 2. The first element is a string, which is the host name 
    105         or IPv4 address of a local interface. The 2nd element is the port 
    106         number. 
     104        bindAddress is the address to bind to, which must be a string or 
     105        a tuple of length 2. If a tuple, the first element must be a string, 
     106        which is the host name or IPv4 address of a local interface. The 
     107        2nd element of the tuple is the port number. If a string, it will 
     108        be interpreted as a filename and a UNIX socket will be opened. 
    107109 
     110        If binding to a UNIX socket, umask may be set to specify what 
     111        the umask is to be changed to before the socket is created in the 
     112        filesystem. After the socket is created, the previous umask is 
     113        restored. 
     114         
    108115        allowedServers must be None or a list of strings representing the 
    109116        IPv4 addresses of servers allowed to connect. None means accept 
     
    118125                                multiprocess=multiprocess, 
    119126                                bindAddress=bindAddress, 
     127                                umask=umask, 
    120128                                allowedServers=allowedServers, 
    121129                                loggingLevel=loggingLevel, 
  • flup/server/scgi_base.py

    r37 r45  
    3636import signal 
    3737import datetime 
     38import os 
    3839 
    3940# Threads are required. If you want a non-threaded (forking) version, look at 
     
    273274    def __init__(self, application, scriptName='', environ=None, 
    274275                 multithreaded=True, multiprocess=False, 
    275                  bindAddress=('localhost', 4000), allowedServers=NoDefault, 
     276                 bindAddress=('localhost', 4000), umask=None, 
     277                 allowedServers=NoDefault, 
    276278                 loggingLevel=logging.INFO, debug=True): 
    277279        """ 
     
    289291        True. (Only makes sense with threaded servers.) 
    290292 
    291         bindAddress is the address to bind to, which must be a tuple of 
    292         length 2. The first element is a string, which is the host name 
    293         or IPv4 address of a local interface. The 2nd element is the port 
    294         number. 
    295  
     293        bindAddress is the address to bind to, which must be a string or 
     294        a tuple of length 2. If a tuple, the first element must be a string, 
     295        which is the host name or IPv4 address of a local interface. The 
     296        2nd element of the tuple is the port number. If a string, it will 
     297        be interpreted as a filename and a UNIX socket will be opened. 
     298 
     299        If binding to a UNIX socket, umask may be set to specify what 
     300        the umask is to be changed to before the socket is created in the 
     301        filesystem. After the socket is created, the previous umask is 
     302        restored. 
     303         
    296304        allowedServers must be None or a list of strings representing the 
    297305        IPv4 addresses of servers allowed to connect. None means accept 
     
    311319        self.debug = debug 
    312320        self._bindAddress = bindAddress 
     321        self._umask = umask 
    313322        if allowedServers is NoDefault: 
    314323            allowedServers = ['127.0.0.1'] 
     
    323332    def _setupSocket(self): 
    324333        """Creates and binds the socket for communication with the server.""" 
    325         sock = socket.socket() 
    326         sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 
     334        oldUmask = None 
     335        if type(self._bindAddress) is str: 
     336            # Unix socket 
     337            sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) 
     338            try: 
     339                os.unlink(self._bindAddress) 
     340            except OSError: 
     341                pass 
     342            if self._umask is not None: 
     343                oldUmask = os.umask(self._umask) 
     344        else: 
     345            # INET socket 
     346            assert type(self._bindAddress) is tuple 
     347            assert len(self._bindAddress) == 2 
     348            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
     349            sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 
     350 
    327351        sock.bind(self._bindAddress) 
    328352        sock.listen(socket.SOMAXCONN) 
     353 
     354        if oldUmask is not None: 
     355            os.umask(oldUmask) 
     356 
    329357        return sock 
    330358 
     
    334362 
    335363    def _isClientAllowed(self, addr): 
    336         ret = self._allowedServers is None or addr[0] in self._allowedServers 
     364        ret = self._allowedServers is None or \ 
     365              len(addr) != 2 or \ 
     366              (len(addr) == 2 and addr[0] in self._allowedServers) 
    337367        if not ret: 
    338368            self.logger.warning('Server connection from %s disallowed', 
  • flup/server/scgi_fork.py

    r32 r45  
    8989    """ 
    9090    def __init__(self, application, scriptName='', environ=None, 
    91                  bindAddress=('localhost', 4000), allowedServers=None, 
     91                 bindAddress=('localhost', 4000), umask=None, 
     92                 allowedServers=None, 
    9293                 loggingLevel=logging.INFO, debug=True, **kw): 
    9394        """ 
     
    100101        environment variables you want to pass to your application. 
    101102 
    102         bindAddress is the address to bind to, which must be a tuple of 
    103         length 2. The first element is a string, which is the host name 
    104         or IPv4 address of a local interface. The 2nd element is the port 
    105         number. 
     103        bindAddress is the address to bind to, which must be a string or 
     104        a tuple of length 2. If a tuple, the first element must be a string, 
     105        which is the host name or IPv4 address of a local interface. The 
     106        2nd element of the tuple is the port number. If a string, it will 
     107        be interpreted as a filename and a UNIX socket will be opened. 
    106108 
     109        If binding to a UNIX socket, umask may be set to specify what 
     110        the umask is to be changed to before the socket is created in the 
     111        filesystem. After the socket is created, the previous umask is 
     112        restored. 
     113         
    107114        allowedServers must be None or a list of strings representing the 
    108115        IPv4 addresses of servers allowed to connect. None means accept 
     
    117124                                multiprocess=True, 
    118125                                bindAddress=bindAddress, 
     126                                umask=umask, 
    119127                                allowedServers=allowedServers, 
    120128                                loggingLevel=loggingLevel,