\r
m_log->debug("NNTPListener::run thread started.");\r
\r
+ LoadDatabase();\r
+\r
StartListen();\r
\r
do\r
void NNTPListener::StartListen()\r
{\r
\r
- std::string bindaddresses;\r
std::vector<std::string> listenaddresses;\r
+ std::string bindaddresses; \r
std::string nntpport;\r
- if(Option::Instance()->Get("NNTPListenPort",nntpport)==false)\r
+ Option option(m_db);\r
+\r
+ if(option.Get("NNTPListenPort",nntpport)==false)\r
{\r
nntpport="1119";\r
- Option::Instance()->Set("NNTPListenPort",nntpport);\r
+ option.Set("NNTPListenPort",nntpport);\r
}\r
- if(Option::Instance()->Get("NNTPBindAddresses",bindaddresses)==false)\r
+ if(option.Get("NNTPBindAddresses",bindaddresses)==false)\r
{\r
bindaddresses="127.0.0.1";\r
- Option::Instance()->Set("NNTPBindAddresses",bindaddresses);\r
+ option.Set("NNTPBindAddresses",bindaddresses);\r
}\r
+\r
StringFunctions::Split(bindaddresses,",",listenaddresses);\r
\r
for(std::vector<std::string>::iterator i=listenaddresses.begin(); i!=listenaddresses.end(); i++)\r
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 on "+sa.toString());\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 on "+sa.toString());\r
#ifdef _WIN32\r
closesocket(sock);\r
#else\r
}\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 on "+sa.toString());\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
}\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