version 0.3.8
[fms.git] / src / nntp / nntplistener.cpp
index 860da2c..6355ebc 100644 (file)
@@ -129,32 +129,47 @@ void NNTPListener::StartListen()
                hint.ai_socktype=SOCK_STREAM;\r
                hint.ai_protocol=IPPROTO_TCP;\r
                hint.ai_flags=AI_PASSIVE;\r
+\r
+               m_log->trace("NNTPListener::StartListen getting address info for "+(*i));\r
                \r
                rval=getaddrinfo((*i).c_str(),nntpport.c_str(),&hint,&result);\r
                if(rval==0)\r
                {\r
                        for(current=result; current!=NULL; current=current->ai_next)\r
                        {\r
-                               Poco::Net::SocketAddress sa(current->ai_addr,current->ai_addrlen);\r
-                               m_log->debug("NNTPListener::StartListen trying to create socket, bind, and listen on "+sa.toString());\r
-\r
-                               sock=socket(current->ai_family,current->ai_socktype,current->ai_protocol);\r
-                               if(sock!=INVALID_SOCKET)\r
+                               try\r
                                {\r
-                                       #ifndef _WIN32\r
-                                       const char optval='1';\r
-                                       setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&optval,sizeof(optval));\r
-                                       #endif\r
-                                       if(bind(sock,current->ai_addr,current->ai_addrlen)==0)\r
+                                       Poco::Net::SocketAddress sa(current->ai_addr,current->ai_addrlen);\r
+\r
+                                       m_log->debug("NNTPListener::StartListen trying to create socket, bind, and listen on "+sa.toString());\r
+\r
+                                       sock=socket(current->ai_family,current->ai_socktype,current->ai_protocol);\r
+                                       if(sock!=INVALID_SOCKET)\r
                                        {\r
-                                               if(listen(sock,10)==0)\r
+                                               #ifndef _WIN32\r
+                                               const char optval='1';\r
+                                               setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&optval,sizeof(optval));\r
+                                               #endif\r
+                                               if(bind(sock,current->ai_addr,current->ai_addrlen)==0)\r
                                                {\r
-                                                       m_log->information("NNTPListener::StartListen started listening on "+sa.toString());\r
-                                                       m_listensockets.push_back(sock);\r
+                                                       if(listen(sock,10)==0)\r
+                                                       {\r
+                                                               m_log->information("NNTPListener::StartListen started listening on "+sa.toString());\r
+                                                               m_listensockets.push_back(sock);\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               m_log->error("NNTPListener::StartListen socket listen failed");\r
+                                                               #ifdef _WIN32\r
+                                                               closesocket(sock);\r
+                                                               #else\r
+                                                               close(sock);\r
+                                                               #endif\r
+                                                       }\r
                                                }\r
                                                else\r
                                                {\r
-                                                       m_log->error("NNTPListener::StartListen socket listen failed");\r
+                                                       m_log->error("NNTPListener::StartListen socket bind failed");\r
                                                        #ifdef _WIN32\r
                                                        closesocket(sock);\r
                                                        #else\r
@@ -164,17 +179,18 @@ void NNTPListener::StartListen()
                                        }\r
                                        else\r
                                        {\r
-                                               m_log->error("NNTPListener::StartListen socket bind failed");\r
-                                               #ifdef _WIN32\r
-                                               closesocket(sock);\r
-                                               #else\r
-                                               close(sock);\r
-                                               #endif\r
+                                               m_log->error("NNTPListener::StartListen couldn't create socket");\r
                                        }\r
                                }\r
-                               else\r
+                               catch(Poco::Exception &e)\r
+                               {\r
+                                       m_log->error("NNTPListener::StartListen caught "+e.displayText());\r
+                                       continue;\r
+                               }\r
+                               catch(...)\r
                                {\r
-                                       m_log->error("NNTPListener::StartListen couldn't create socket");\r
+                                       m_log->error("NNTPListener::StartListen caught unknown exception");\r
+                                       continue;\r
                                }\r
                        }\r
                }\r
@@ -185,6 +201,6 @@ void NNTPListener::StartListen()
        }\r
        if(m_listensockets.size()==0)\r
        {\r
-               m_log->fatal("NNTPListener::StartListen couldn't start listening on any sockets");\r
+               m_log->fatal("NNTPListener::StartListen couldn't start listening on any interfaces");\r
        }\r
 }\r