]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/EventLoop.cc
247ada8e23001d145222f7681c672535088881d1
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
),
42 loop_delay(EVENT_LOOP_TIMEOUT
),
48 EventLoop::checkEngine(AsyncEngine
* engine
, bool const primary
)
53 requested_delay
= engine
->checkEvents(0);
55 requested_delay
= engine
->checkEvents(loop_delay
);
57 if (requested_delay
< 0)
58 switch (requested_delay
) {
60 case AsyncEngine::EVENT_IDLE
:
61 debugs(1, 9, "Engine " << engine
<< " is idle.");
64 case AsyncEngine::EVENT_ERROR
:
65 runOnceResult
= false;
70 fatal_dump("unknown AsyncEngine result");
73 /* not idle or error */
74 runOnceResult
= false;
76 if (requested_delay
< loop_delay
)
77 loop_delay
= requested_delay
;
82 EventLoop::prepareToRun()
89 EventLoop::registerEngine(AsyncEngine
*engine
)
91 engines
.push_back(engine
);
105 bool sawActivity
= false;
106 runOnceResult
= true;
108 loop_delay
= EVENT_LOOP_TIMEOUT
;
110 AsyncEngine
*waitingEngine
= primaryEngine
;
111 if (!waitingEngine
&& !engines
.empty())
112 waitingEngine
= engines
.back();
115 // generate calls and events
116 typedef engine_vector::iterator EVI
;
117 for (EVI i
= engines
.begin(); i
!= engines
.end(); ++i
) {
118 if (*i
!= waitingEngine
)
119 checkEngine(*i
, false);
122 // dispatch calls accumulated so far
123 sawActivity
= dispatchCalls();
125 runOnceResult
= false;
126 } while (sawActivity
);
128 if (waitingEngine
!= NULL
)
129 checkEngine(waitingEngine
, true);
131 if (timeService
!= NULL
)
134 // dispatch calls scheduled by waitingEngine and timeService
135 sawActivity
= dispatchCalls();
137 runOnceResult
= false;
141 debugs(1, DBG_CRITICAL
, "Select loop Error. Retry " << errcount
);
151 return runOnceResult
;
154 // dispatches calls accumulated during checkEngine()
156 EventLoop::dispatchCalls()
158 bool dispatchedSome
= AsyncCallQueue::Instance().fire();
159 return dispatchedSome
;
163 EventLoop::setPrimaryEngine(AsyncEngine
* engine
)
165 for (engine_vector::iterator i
= engines
.begin();
166 i
!= engines
.end(); ++i
)
168 primaryEngine
= engine
;
172 fatal("EventLoop::setPrimaryEngine: No such engine!.");
176 EventLoop::setTimeService(TimeEngine
*engine
)
178 timeService
= engine
;