]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/EventLoop.cc
2 * DEBUG: section 01 Main Loop
3 * AUTHOR: Harvest Derived
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
34 #include "AsyncEngine.h"
36 #include "EventLoop.h"
37 #include "base/AsyncCallQueue.h"
38 #include "SquidTime.h"
40 EventLoop::EventLoop() : errcount(0), last_loop(false), timeService(NULL
),
45 EventLoop::checkEngine(AsyncEngine
* engine
, bool const primary
)
50 requested_delay
= engine
->checkEvents(0);
52 requested_delay
= engine
->checkEvents(loop_delay
);
54 if (requested_delay
< 0)
55 switch (requested_delay
) {
57 case AsyncEngine::EVENT_IDLE
:
58 debugs(1, 9, "Engine " << engine
<< " is idle.");
61 case AsyncEngine::EVENT_ERROR
:
62 runOnceResult
= false;
67 fatal_dump("unknown AsyncEngine result");
70 /* not idle or error */
71 runOnceResult
= false;
73 if (requested_delay
< loop_delay
)
74 loop_delay
= requested_delay
;
79 EventLoop::prepareToRun()
86 EventLoop::registerEngine(AsyncEngine
*engine
)
88 engines
.push_back(engine
);
102 bool sawActivity
= false;
103 runOnceResult
= true;
105 loop_delay
= EVENT_LOOP_TIMEOUT
;
107 AsyncEngine
*waitingEngine
= primaryEngine
;
108 if (!waitingEngine
&& !engines
.empty())
109 waitingEngine
= engines
.back();
112 // generate calls and events
113 typedef engine_vector::iterator EVI
;
114 for (EVI i
= engines
.begin(); i
!= engines
.end(); ++i
) {
115 if (*i
!= waitingEngine
)
116 checkEngine(*i
, false);
119 // dispatch calls accumulated so far
120 sawActivity
= dispatchCalls();
122 runOnceResult
= false;
123 } while (sawActivity
);
125 if (waitingEngine
!= NULL
)
126 checkEngine(waitingEngine
, true);
128 if (timeService
!= NULL
)
131 // dispatch calls scheduled by waitingEngine and timeService
132 sawActivity
= dispatchCalls();
134 runOnceResult
= false;
138 debugs(1, DBG_CRITICAL
, "Select loop Error. Retry " << errcount
);
148 return runOnceResult
;
151 // dispatches calls accumulated during checkEngine()
153 EventLoop::dispatchCalls()
155 bool dispatchedSome
= AsyncCallQueue::Instance().fire();
156 return dispatchedSome
;
160 EventLoop::setPrimaryEngine(AsyncEngine
* engine
)
162 for (engine_vector::iterator i
= engines
.begin();
163 i
!= engines
.end(); ++i
)
165 primaryEngine
= engine
;
169 fatal("EventLoop::setPrimaryEngine: No such engine!.");
173 EventLoop::setTimeService(TimeEngine
*engine
)
175 timeService
= engine
;