]>
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"
35 #include "base/AsyncCallQueue.h"
37 #include "EventLoop.h"
38 #include "SquidTime.h"
40 EventLoop
*EventLoop::Running
= NULL
;
42 EventLoop::EventLoop() : errcount(0), last_loop(false), timeService(NULL
),
44 loop_delay(EVENT_LOOP_TIMEOUT
),
50 EventLoop::checkEngine(AsyncEngine
* engine
, bool const primary
)
55 requested_delay
= engine
->checkEvents(0);
57 requested_delay
= engine
->checkEvents(loop_delay
);
59 if (requested_delay
< 0)
60 switch (requested_delay
) {
62 case AsyncEngine::EVENT_IDLE
:
63 debugs(1, 9, "Engine " << engine
<< " is idle.");
66 case AsyncEngine::EVENT_ERROR
:
67 runOnceResult
= false;
72 fatal_dump("unknown AsyncEngine result");
75 /* not idle or error */
76 runOnceResult
= false;
78 if (requested_delay
< loop_delay
)
79 loop_delay
= requested_delay
;
84 EventLoop::prepareToRun()
91 EventLoop::registerEngine(AsyncEngine
*engine
)
93 engines
.push_back(engine
);
112 bool sawActivity
= false;
113 runOnceResult
= true;
115 loop_delay
= EVENT_LOOP_TIMEOUT
;
117 AsyncEngine
*waitingEngine
= primaryEngine
;
118 if (!waitingEngine
&& !engines
.empty())
119 waitingEngine
= engines
.back();
122 // generate calls and events
123 typedef engine_vector::iterator EVI
;
124 for (EVI i
= engines
.begin(); i
!= engines
.end(); ++i
) {
125 if (*i
!= waitingEngine
)
126 checkEngine(*i
, false);
129 // dispatch calls accumulated so far
130 sawActivity
= dispatchCalls();
132 runOnceResult
= false;
133 } while (sawActivity
);
135 if (waitingEngine
!= NULL
)
136 checkEngine(waitingEngine
, true);
138 if (timeService
!= NULL
)
141 // dispatch calls scheduled by waitingEngine and timeService
142 sawActivity
= dispatchCalls();
144 runOnceResult
= false;
148 debugs(1, DBG_CRITICAL
, "Select loop Error. Retry " << errcount
);
158 return runOnceResult
;
161 // dispatches calls accumulated during checkEngine()
163 EventLoop::dispatchCalls()
165 bool dispatchedSome
= AsyncCallQueue::Instance().fire();
166 return dispatchedSome
;
170 EventLoop::setPrimaryEngine(AsyncEngine
* engine
)
172 for (engine_vector::iterator i
= engines
.begin();
173 i
!= engines
.end(); ++i
)
175 primaryEngine
= engine
;
179 fatal("EventLoop::setPrimaryEngine: No such engine!.");
183 EventLoop::setTimeService(TimeEngine
*engine
)
185 timeService
= engine
;