~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to src/pconn.cc

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2010-05-04 11:15:49 UTC
  • mfrom: (1.3.1 upstream)
  • mto: (20.3.1 squeeze) (21.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20100504111549-1apjh2g5sndki4te
Tags: upstream-3.1.3
ImportĀ upstreamĀ versionĀ 3.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 *  it under the terms of the GNU General Public License as published by
21
21
 *  the Free Software Foundation; either version 2 of the License, or
22
22
 *  (at your option) any later version.
23
 
 *  
 
23
 *
24
24
 *  This program is distributed in the hope that it will be useful,
25
25
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
26
26
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
27
 *  GNU General Public License for more details.
28
 
 *  
 
28
 *
29
29
 *  You should have received a copy of the GNU General Public License
30
30
 *  along with this program; if not, write to the Free Software
31
31
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
85
85
IdleConnList::removeFD(int fd)
86
86
{
87
87
    int index = findFDIndex(fd);
88
 
    assert(index >= 0);
 
88
    if (index < 0) {
 
89
        debugs(48, 2, "IdleConnList::removeFD: FD " << fd << " NOT FOUND!");
 
90
        return;
 
91
    }
89
92
    debugs(48, 3, "IdleConnList::removeFD: found FD " << fd << " at index " << index);
90
93
 
91
94
    for (; index < nfds - 1; index++)
174
177
/* ========== PconnPool PRIVATE FUNCTIONS ============================================ */
175
178
 
176
179
const char *
177
 
 
178
 
PconnPool::key(const char *host, u_short port, const char *domain, struct IN_ADDR *client_address)
 
180
PconnPool::key(const char *host, u_short port, const char *domain, IpAddress &client_address)
179
181
{
180
182
    LOCAL_ARRAY(char, buf, SQUIDHOSTNAMELEN * 3 + 10);
 
183
    char ntoabuf[MAX_IPSTRLEN];
181
184
 
182
 
    if (domain && client_address)
183
 
        snprintf(buf, SQUIDHOSTNAMELEN * 3 + 10, "%s:%d-%s/%s", host, (int) port, inet_ntoa(*client_address), domain);
184
 
    else if (domain && (!client_address))
 
185
    if (domain && !client_address.IsAnyAddr())
 
186
        snprintf(buf, SQUIDHOSTNAMELEN * 3 + 10, "%s:%d-%s/%s", host, (int) port, client_address.NtoA(ntoabuf,MAX_IPSTRLEN), domain);
 
187
    else if (domain && client_address.IsAnyAddr())
185
188
        snprintf(buf, SQUIDHOSTNAMELEN * 3 + 10, "%s:%d/%s", host, (int) port, domain);
186
 
    else if ((!domain) && client_address)
187
 
        snprintf(buf, SQUIDHOSTNAMELEN * 3 + 10, "%s:%d-%s", host, (int) port, inet_ntoa(*client_address));
 
189
    else if ((!domain) && !client_address.IsAnyAddr())
 
190
        snprintf(buf, SQUIDHOSTNAMELEN * 3 + 10, "%s:%d-%s", host, (int) port, client_address.NtoA(ntoabuf,MAX_IPSTRLEN));
188
191
    else
189
192
        snprintf(buf, SQUIDHOSTNAMELEN * 3 + 10, "%s:%d", host, (int) port);
190
193
 
191
 
    debugs(48,6,"PconnPool::key(" << (host?host:"(no host!)") << "," << port << "," << (domain?domain:"(no domain)") << "," << (client_address?inet_ntoa(*client_address):"(no client IP)") << "is {" << buf << "}" );
 
194
    debugs(48,6,"PconnPool::key(" << (host?host:"(no host!)") << "," << port << "," << (domain?domain:"(no domain)") << "," << client_address << "is {" << buf << "}" );
192
195
    return buf;
193
196
}
194
197
 
245
248
}
246
249
 
247
250
void
248
 
 
249
 
PconnPool::push(int fd, const char *host, u_short port, const char *domain, struct IN_ADDR *client_address)
 
251
PconnPool::push(int fd, const char *host, u_short port, const char *domain, IpAddress &client_address)
250
252
{
251
253
    IdleConnList *list;
252
254
    const char *aKey;
253
255
    LOCAL_ARRAY(char, desc, FD_DESC_SZ);
254
256
 
255
 
    if (fdUsageHigh())
256
 
    {
 
257
    if (fdUsageHigh()) {
257
258
        debugs(48, 3, "PconnPool::push: Not many unused FDs");
258
259
        comm_close(fd);
259
260
        return;
260
 
    } else if (shutting_down)
261
 
    {
 
261
    } else if (shutting_down) {
262
262
        comm_close(fd);
263
263
        debugs(48, 3, "PconnPool::push: Squid is shutting down. Refusing to do anything");
264
264
        return;
268
268
 
269
269
    list = (IdleConnList *) hash_lookup(table, aKey);
270
270
 
271
 
    if (list == NULL)
272
 
    {
 
271
    if (list == NULL) {
273
272
        list = new IdleConnList(aKey, this);
274
273
        debugs(48, 3, "PconnPool::push: new IdleConnList for {" << hashKeyStr(&list->hash) << "}" );
275
274
        hash_join(table, &list->hash);
294
293
 * transactions create persistent connections but are not retriable.
295
294
 */
296
295
int
297
 
PconnPool::pop(const char *host, u_short port, const char *domain, struct in_addr *client_address, bool isRetriable)
 
296
PconnPool::pop(const char *host, u_short port, const char *domain, IpAddress &client_address, bool isRetriable)
298
297
{
299
298
    const char * aKey = key(host, port, domain, client_address);
300
299
 
302
301
    if (list == NULL) {
303
302
        debugs(48, 3, "PconnPool::pop: lookup for key {" << aKey << "} failed.");
304
303
        return -1;
305
 
    } else { 
 
304
    } else {
306
305
        debugs(48, 3, "PconnPool::pop: found " << hashKeyStr(&list->hash) << (isRetriable?"(to use)":"(to kill)") );
307
306
    }
308
307
 
309
308
    int fd = list->findUseableFD(); // search from the end. skip pending reads.
310
309
 
311
 
    if (fd >= 0)
312
 
    {
 
310
    if (fd >= 0) {
313
311
        list->clearHandlers(fd);
314
312
        list->removeFD(fd);     /* might delete list */
315
313
 
348
346
    pools = (PconnPool **) xcalloc(MAX_NUM_PCONN_POOLS, sizeof(*pools));
349
347
    pconn_fds_pool = memPoolCreate("pconn_fds", PCONN_FDS_SZ * sizeof(int));
350
348
    debugs(48, 0, "persistent connection module initialized");
 
349
    registerWithCacheManager();
351
350
}
352
351
 
353
352
PconnModule *
360
359
}
361
360
 
362
361
void
363
 
PconnModule::registerWithCacheManager(CacheManager & manager)
 
362
PconnModule::registerWithCacheManager(void)
364
363
{
365
 
    manager.registerAction("pconn",
366
 
                           "Persistent Connection Utilization Histograms",
367
 
                           DumpWrapper, 0, 1);
 
364
    CacheManager::GetInstance()->
 
365
    registerAction("pconn",
 
366
                   "Persistent Connection Utilization Histograms",
 
367
                   DumpWrapper, 0, 1);
368
368
}
369
369
 
370
370
void
371
371
 
372
372
PconnModule::add
373
 
    (PconnPool *aPool)
 
373
(PconnPool *aPool)
374
374
{
375
375
    assert(poolCount < MAX_NUM_PCONN_POOLS);
376
376
    *(pools+poolCount) = aPool;