Better error messages when socket could not be opened

This commit is contained in:
Sebastian Lohff 2012-06-25 20:03:34 +02:00
parent f48838f63c
commit 2ce2a9c228
1 changed files with 9 additions and 4 deletions

View File

@ -798,10 +798,15 @@ class ServeFile():
self.handler = self._confAndFindHandler() self.handler = self._confAndFindHandler()
self.server = [] self.server = []
if self.listenIPv4: try:
self.server.append(self._createServer(self.handler)) currsocktype = "IPv4"
if self.listenIPv6: if self.listenIPv4:
self.server.append(self._createServer(self.handler, withv6=True)) self.server.append(self._createServer(self.handler))
currsocktype = "IPv6"
if self.listenIPv6:
self.server.append(self._createServer(self.handler, withv6=True))
except socket.error as e:
raise ServeFileException("Could not open %s socket: %s" % (currsocktype, e))
if self.serveMode != self.MODE_UPLOAD: if self.serveMode != self.MODE_UPLOAD:
print("Serving \"%s\" at port %d." % (self.target, self.port)) print("Serving \"%s\" at port %d." % (self.target, self.port))