From 2ce2a9c2281d782d853011dcb84be38320ea7196 Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Mon, 25 Jun 2012 20:03:34 +0200 Subject: [PATCH] Better error messages when socket could not be opened --- servefile | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/servefile b/servefile index f249c03..4b7c239 100755 --- a/servefile +++ b/servefile @@ -798,10 +798,15 @@ class ServeFile(): self.handler = self._confAndFindHandler() self.server = [] - if self.listenIPv4: - self.server.append(self._createServer(self.handler)) - if self.listenIPv6: - self.server.append(self._createServer(self.handler, withv6=True)) + try: + currsocktype = "IPv4" + if self.listenIPv4: + 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: print("Serving \"%s\" at port %d." % (self.target, self.port))