| 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 | |
|---|