]>
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"
41 EventLoop::EventLoop() : errcount(0), last_loop(false), timeService(NULL
),
46 EventLoop::checkEngine(AsyncEngine
* engine
, bool const primary
)
51 requested_delay
= engine
->checkEvents(0);
53 requested_delay
= engine
->checkEvents(loop_delay
);
55 if (requested_delay
< 0)
56 switch (requested_delay
) {
58 case AsyncEngine::EVENT_IDLE
:
59 debugs(1, 9, "Engine " << engine
<< " is idle.");
62 case AsyncEngine::EVENT_ERROR
:
63 runOnceResult
= false;
68 fatal_dump("unknown AsyncEngine result");
71 /* not idle or error */
72 runOnceResult
= false;
74 if (requested_delay
< loop_delay
)
75 loop_delay
= requested_delay
;
80 EventLoop::prepareToRun()
87 EventLoop::registerEngine(AsyncEngine
*engine
)
89 engines
.push_back(engine
);
103 bool sawActivity
= false;
104 runOnceResult
= true;
106 loop_delay
= EVENT_LOOP_TIMEOUT
;
108 AsyncEngine
*waitingEngine
= primaryEngine
;
109 if (!waitingEngine
&& !engines
.empty())
110 waitingEngine
= engines
.back();
113 // generate calls and events
114 typedef engine_vector::iterator EVI
;
115 for (EVI i
= engines
.begin(); i
!= engines
.end(); ++i
) {
116 if (*i
!= waitingEngine
)
117 checkEngine(*i
, false);
120 // dispatch calls accumulated so far
121 sawActivity
= dispatchCalls();
123 runOnceResult
= false;
124 } while (sawActivity
);
126 if (waitingEngine
!= NULL
)
127 checkEngine(waitingEngine
, true);
129 if (timeService
!= NULL
)
132 // dispatch calls scheduled by waitingEngine and timeService
133 sawActivity
= dispatchCalls();
135 runOnceResult
= false;
139 debugs(1, DBG_CRITICAL
, "Select loop Error. Retry " << errcount
);
149 return runOnceResult
;
152 // dispatches calls accumulated during checkEngine()
154 EventLoop::dispatchCalls()
156 bool dispatchedSome
= AsyncCallQueue::Instance().fire();
157 return dispatchedSome
;
161 EventLoop::setPrimaryEngine(AsyncEngine
* engine
)
163 for (engine_vector::iterator i
= engines
.begin();
164 i
!= engines
.end(); ++i
)
166 primaryEngine
= engine
;
170 fatal("EventLoop::setPrimaryEngine: No such engine!.");
174 EventLoop::setTimeService(TimeEngine
*engine
)
176 timeService
= engine
;