]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/communicator.cc
and the final bit of whitespace/tab cleanup
[thirdparty/pdns.git] / pdns / communicator.cc
1 /*
2 PowerDNS Versatile Database Driven Nameserver
3 Copyright (C) 2002-2009 PowerDNS.COM BV
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License version 2 as
7 published by the Free Software Foundation;
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 #include "packetcache.hh"
19 #include "utility.hh"
20 #include <errno.h>
21 #include "communicator.hh"
22 #include <set>
23 #include <boost/utility.hpp>
24 #include "dnsbackend.hh"
25 #include "ueberbackend.hh"
26 #include "packethandler.hh"
27 #include "resolver.hh"
28 #include "logger.hh"
29 #include "dns.hh"
30 #include "arguments.hh"
31 #include "session.hh"
32 #include "packetcache.hh"
33 #include <boost/lexical_cast.hpp>
34
35 #include "namespaces.hh"
36
37
38 void CommunicatorClass::mainloop(void)
39 {
40 try {
41 #ifndef WIN32
42 signal(SIGPIPE,SIG_IGN);
43 #endif // WIN32
44 L<<Logger::Error<<"Master/slave communicator launching"<<endl;
45 PacketHandler P;
46 d_tickinterval=::arg().asNum("slave-cycle-interval");
47 makeNotifySocket();
48
49 int rc;
50 time_t next;
51
52 time_t tick;
53
54 for(;;) {
55 slaveRefresh(&P);
56 masterUpdateCheck(&P);
57 tick=doNotifications();
58
59 tick = min (tick, d_tickinterval);
60
61 // L<<Logger::Error<<"tick = "<<tick<<", d_tickinterval = "<<d_tickinterval<<endl;
62 next=time(0)+tick;
63
64 while(time(0) < next) {
65 rc=d_any_sem.tryWait();
66
67 if(rc)
68 Utility::sleep(1);
69 else {
70 if(!d_suck_sem.tryWait()) {
71 SuckRequest sr;
72 {
73 Lock l(&d_lock);
74 sr=d_suckdomains.front();
75 d_suckdomains.pop_front();
76 }
77 suck(sr.domain,sr.master);
78 }
79 }
80 // this gets executed at least once every second
81 doNotifications();
82 }
83 }
84 }
85 catch(AhuException &ae) {
86 L<<Logger::Error<<"Communicator thread died because of error: "<<ae.reason<<endl;
87 Utility::sleep(1);
88 exit(0);
89 }
90 catch(std::exception &e) {
91 L<<Logger::Error<<"Communicator thread died because of STL error: "<<e.what()<<endl;
92 exit(0);
93 }
94 catch( ... )
95 {
96 L << Logger::Error << "Communicator caught unknown exception." << endl;
97 exit( 0 );
98 }
99 }
100