Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 844

Show
Ignore:
Timestamp:
11/28/05 01:08:51
Author:
fumanchu
Message:

Patched _cpserver to allow check_port on IPv6 addresses (see #388). Also a fix for http://groups.google.com/group/cherrypy-users/browse_frm/thread/bbfe5eb39c904fe0.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/_cpserver.py

    r808 r844  
    283283def check_port(host, port): 
    284284    """Raise an error if the given port is not free on the given host.""" 
     285    sockFile = cherrypy.config.get('server.socketFile') 
     286    if sockFile: 
     287        return 
     288     
    285289    if not host: 
    286290        host = 'localhost' 
     291    port = int(port) 
    287292     
    288293    import socket 
    289     try: 
    290         s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
    291         s.connect((host, int(port))) 
    292         s.close() 
    293         raise IOError("Port %s is in use on %s; perhaps the previous " 
    294                       "server did not shut down properly." % 
    295                       (repr(port), repr(host))) 
    296     except socket.error: 
    297         pass 
     294     
     295    # AF_INET or AF_INET6 socket 
     296    # Get the correct address family for our host (allows IPv6 addresses) 
     297    for res in socket.getaddrinfo(host, port, socket.AF_UNSPEC, 
     298                                  socket.SOCK_STREAM): 
     299        af, socktype, proto, canonname, sa = res 
     300        s = None 
     301        try: 
     302            s = socket.socket(af, socktype, proto) 
     303            # See http://groups.google.com/group/cherrypy-users/ 
     304            #        browse_frm/thread/bbfe5eb39c904fe0 
     305            s.settimeout(1.0) 
     306            s.connect((host, port)) 
     307            s.close() 
     308            raise IOError("Port %s is in use on %s; perhaps the previous " 
     309                          "server did not shut down properly." % 
     310                          (repr(port), repr(host))) 
     311        except socket.error, msg: 
     312            if s: 
     313                s.close() 
     314 
    298315 
    299316def wait_for_free_port(host, port): 

Hosted by WebFaction

Log in as guest/cpguest to create tickets