X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnntp%2Fnntplistener.cpp;h=7f6e4693a099ffd8ada4821018990027fd9a77df;hb=b9c3763a932cebaa015a27fe111017f6f34dfbaa;hp=29f8eb4752dbe442cec9c8c2ecf7a8d211cb8183;hpb=868c533e84b3c81b6604b45b84efa32073aa20b4;p=fms.git diff --git a/src/nntp/nntplistener.cpp b/src/nntp/nntplistener.cpp index 29f8eb4..7f6e469 100644 --- a/src/nntp/nntplistener.cpp +++ b/src/nntp/nntplistener.cpp @@ -27,7 +27,7 @@ NNTPListener::~NNTPListener() } -void NNTPListener::run() +void NNTPListener::Run() { int rval; fd_set readfs; @@ -35,6 +35,8 @@ void NNTPListener::run() std::vector::iterator listeni; SOCKET highsocket; + LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPListener::run thread started."); + StartListen(); do @@ -69,28 +71,79 @@ void NNTPListener::run() { SOCKET newsock; struct sockaddr_storage addr; - int addrlen=sizeof(addr); + socklen_t addrlen=sizeof(addr); newsock=accept((*listeni),(struct sockaddr *)&addr,&addrlen); - LogFile::instance()->WriteLog(LogFile::LOGLEVEL_INFO,"NNTPListener::run NNTP client connected"); - m_connections.execute(new NNTPConnection(newsock)); + LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_INFO,"NNTPListener::run NNTP client connected"); + //m_connections.execute(new NNTPConnection(newsock)); + //m_connectionthreads.push_back(new PThread::Thread(new NNTPConnection(newsock))); + m_connections.Execute(new NNTPConnection(newsock)); } } } +/* + // check for any non-running connection threads that we can delete + for(std::vector::iterator i=m_connectionthreads.begin(); i!=m_connectionthreads.end(); ) + { + if((*i)->IsRunning()==false) + { + delete (*i); + i=m_connectionthreads.erase(i); + } + if(i!=m_connectionthreads.end()) + { + i++; + } + } +*/ - }while(!ZThread::Thread::interrupted() && m_listensockets.size()>0); + //}while(!ZThread::Thread::interrupted() && m_listensockets.size()>0); + }while(!IsCancelled() && m_listensockets.size()>0); // see if any threads are still running - just calling interrupt without check would cause assert in debug mode + /* if(m_connections.wait(1)==false) { + LogFile::instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPListener::run interrupting connection threads and waiting 60 seconds for exit."); try { m_connections.interrupt(); } catch(...) { + LogFile::instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPListener::run caught unhandled exception."); + } + if(m_connections.wait(60000)==false) + { + LogFile::instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPListener::run connection threads did not exit after 60 seconds."); } - m_connections.wait(); } + */ + /* + for(std::vector::iterator i=m_connectionthreads.begin(); i!=m_connectionthreads.end(); i++) + { + if((*i)->IsRunning()) + { + LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPListener::Run waiting for connection thread to exit."); + (*i)->Cancel(); + (*i)->Join(); + } + delete (*i); + } + */ + m_connections.Cancel(); + m_connections.Join(); + + for(listeni=m_listensockets.begin(); listeni!=m_listensockets.end(); listeni++) + { + #ifdef _WIN32 + closesocket((*listeni)); + #else + close((*listeni)); + #endif + } + m_listensockets.clear(); + + LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_DEBUG,"NNTPListener::run thread exiting."); } @@ -100,15 +153,15 @@ void NNTPListener::StartListen() std::string bindaddresses; std::vector listenaddresses; std::string nntpport; - if(Option::instance()->Get("NNTPListenPort",nntpport)==false) + if(Option::Instance()->Get("NNTPListenPort",nntpport)==false) { nntpport="1119"; - Option::instance()->Set("NNTPListenPort",nntpport); + Option::Instance()->Set("NNTPListenPort",nntpport); } - if(Option::instance()->Get("NNTPBindAddresses",bindaddresses)==false) + if(Option::Instance()->Get("NNTPBindAddresses",bindaddresses)==false) { bindaddresses="127.0.0.1"; - Option::instance()->Set("NNTPBindAddresses",bindaddresses); + Option::Instance()->Set("NNTPBindAddresses",bindaddresses); } StringFunctions::Split(bindaddresses,",",listenaddresses); @@ -135,12 +188,12 @@ void NNTPListener::StartListen() { if(listen(sock,10)==0) { - LogFile::instance()->WriteLog(LogFile::LOGLEVEL_INFO,"NNTPListener::StartListen started listening at "+(*i)+":"+nntpport); + LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_INFO,"NNTPListener::StartListen started listening at "+(*i)+":"+nntpport); m_listensockets.push_back(sock); } else { - LogFile::instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPListener::StartListen socket listen failed"); + LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPListener::StartListen socket listen failed"); #ifdef _WIN32 closesocket(sock); #else @@ -150,7 +203,7 @@ void NNTPListener::StartListen() } else { - LogFile::instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPListener::StartListen socket bind failed"); + LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPListener::StartListen socket bind failed"); #ifdef _WIN32 closesocket(sock); #else @@ -160,7 +213,7 @@ void NNTPListener::StartListen() } else { - LogFile::instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPListener::StartListen couldn't create socket"); + LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_ERROR,"NNTPListener::StartListen couldn't create socket"); } } } @@ -171,6 +224,6 @@ void NNTPListener::StartListen() } if(m_listensockets.size()==0) { - LogFile::instance()->WriteLog(LogFile::LOGLEVEL_FATAL,"NNTPListener::StartListen couldn't start listening on any sockets"); + LogFile::Instance()->WriteLog(LogFile::LOGLEVEL_FATAL,"NNTPListener::StartListen couldn't start listening on any sockets"); } }