#include <iostream>
#include <signal.h>
#include <unistd.h>
#include "mind.h"
#include "am.h"
#include "dnsconfig.h"
#include "ex.h"
#include "loghandle.h"
#include "mindlog.h"
#include "dnssocket.h"
#include "dthreadpool.h"
#include "requestworker.h"
#include "rrcache.h"
#include "wwwi/daemon.h"
#include "wwwi/exception.h"
using std::cerr;
using WWWI::BecomeDaemon;
using WWWI::Exception;
void sigint_handler(int);
void InitializeRootServers(void);
bool g_bDone = false;
int main(int argc, char **argv) {
try {
#ifdef USE_DEBUG_POINTERS
GetSingleton<RefMgr<LabelList> >();
GetSingleton<RefMgr<RData> >();
GetSingleton<RefMgr<RR> >();
GetSingleton<RefMgr<CacheRR> >();
GetSingleton<RefMgr<RRList> >();
GetSingleton<RefMgr<CacheRRList> >();
GetSingleton<RefMgr<Question> >();
GetSingleton<RefMgr<Request> >();
GetSingleton<RefMgr<Response> >();
GetSingleton<RefMgr<DNSPacket> >();
#endif
#ifndef NDEBUG
GetSingleton<AM<Label> >();
GetSingleton<AM<LabelList> >();
GetSingleton<AM<RR> >();
GetSingleton<AM<CacheRR> >();
#endif
DNSConfigPtr dcp = GetSingleton<DNSConfig>();
dcp->Configure(argc,argv);
if (dcp->GetDaemon()==true) BecomeDaemon();
DNSSocketPtr dsp = new DNSSocket(dcp->GetUDPClientInterface(),dcp->GetUDPClientPort());
{
DynamicThreadPool<RequestWorker,DNSSocketPtr> dl(2,5,dsp);
while (1) sleep(60);
}
dsp->Close();
delete dsp;
} catch (MindEx &exr) {
LogHandle lh(LF_MISC,LY_FAILURE);
lh << (const char*)argv[0] << ": fatal " << exr.name() << ": "
<< exr.what() << endl;
} catch (exception &exr) {
LogHandle lh(LF_MISC,LY_FAILURE);
lh << (const char*)argv[0] << ": fatal exception: " << exr.what() << endl;
} catch (WWWI::Exception &exr) {
LogHandle lh(LF_MISC,LY_FAILURE);
lh << (const char*)argv[0] << ": library exception: " << exr.m_strMessage << endl;
}
return 0;
}
void sigint_handler(int) {
g_bDone = true;
}