~ubuntu-branches/ubuntu/oneiric/squid3/oneiric-security

« back to all changes in this revision

Viewing changes to src/pconn.cc

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2007-05-13 16:03:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070513160316-2h6kn6h1z0q1fvyo
Tags: 3.0.PRE6-1
* New upstream release
  - Removed patches integrated upsteam:
    + 04-m68k-ftbfs

* debian/rules
  - Enable delay pools (Closes: #410785)
  - Enable cache digests (Closes: #416631)
  - Enable ICAP client
  - Raised Max Filedescriptor limit to 65536

* debian/control
  - Added real package dependency for httpd in squid3-cgi

* debian/patches/02-makefile-defaults
  - Fix default configuration file for cachemgr.cgi (Closes: #416630)

* debian/squid3.postinst
  - Fixed bashish in postinst (Closes: #411797)

* debian/patches/05-helpers-typo
  - Added upstream patch fixing compilation error in src/helpers.cc

* debian/patches/06-mem-obj-reference
  - Added upstream patch fixing a mem_obj reference in src/store.cc

* debian/patches/07-close-icap-connections
  - Added upstream patch fixing icap connection starvation

* debian/squid3.rc
  - Added LSB-compliant description to rc script

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
/*
3
 
 * $Id: pconn.cc,v 1.47 2006/09/03 21:05:20 hno Exp $
 
3
 * $Id: pconn.cc,v 1.50 2007/04/30 16:56:09 wessels Exp $
4
4
 *
5
5
 * DEBUG: section 48    Persistent Connections
6
6
 * AUTHOR: Duane Wessels
87
87
{
88
88
    int index = findFDIndex(fd);
89
89
    assert(index >= 0);
90
 
    debug(48, 3) ("IdleConnList::removeFD: found FD %d at index %d\n", fd, index);
 
90
    debugs(48, 3, "IdleConnList::removeFD: found FD " << fd << " at index " << index);
91
91
 
92
92
    for (; index < nfds - 1; index++)
93
93
        fds[index] = fds[index + 1];
94
94
 
95
95
    if (--nfds == 0) {
96
 
        debug(48, 3) ("IdleConnList::removeFD: deleting %s\n", hashKeyStr(&hash));
 
96
        debugs(48, 3, "IdleConnList::removeFD: deleting " << hashKeyStr(&hash));
97
97
        delete this;
98
98
    }
99
99
}
109
109
IdleConnList::push(int fd)
110
110
{
111
111
    if (nfds == nfds_alloc) {
112
 
        debug(48, 3) ("IdleConnList::push: growing FD array\n");
 
112
        debugs(48, 3, "IdleConnList::push: growing FD array");
113
113
        nfds_alloc <<= 1;
114
114
        int *old = fds;
115
115
        fds = (int *)xmalloc(nfds_alloc * sizeof(int));
151
151
void
152
152
IdleConnList::read(int fd, char *buf, size_t len, comm_err_t flag, int xerrno, void *data)
153
153
{
154
 
    debug(48, 3) ("IdleConnList::read: %d bytes from FD %d\n", (int) len, fd);
 
154
    debugs(48, 3, "IdleConnList::read: " << len << " bytes from FD " << fd);
155
155
 
156
156
    if (flag == COMM_ERR_CLOSING) {
157
157
        /* Bail out early on COMM_ERR_CLOSING - close handlers will tidy up for us */
166
166
void
167
167
IdleConnList::timeout(int fd, void *data)
168
168
{
169
 
    debug(48, 3) ("IdleConnList::timeout: FD %d\n", fd);
 
169
    debugs(48, 3, "IdleConnList::timeout: FD " << fd);
170
170
    IdleConnList *list = (IdleConnList *) data;
171
171
    list->removeFD(fd); /* might delete list */
172
172
    comm_close(fd);
175
175
/* ========== PconnPool PRIVATE FUNCTIONS ============================================ */
176
176
 
177
177
const char *
178
 
PconnPool::key(const char *host, u_short port, const char *domain)
 
178
 
 
179
PconnPool::key(const char *host, u_short port, const char *domain, struct IN_ADDR *client_address)
179
180
{
180
181
    LOCAL_ARRAY(char, buf, SQUIDHOSTNAMELEN * 2 + 10);
181
182
 
182
 
    if (domain)
 
183
    if (domain && client_address)
 
184
        snprintf(buf, SQUIDHOSTNAMELEN * 2 + 10, "%s:%d-%s/%s", host, (int) port, inet_ntoa(*client_address), domain);
 
185
    else if (domain && (!client_address))
183
186
        snprintf(buf, SQUIDHOSTNAMELEN * 2 + 10, "%s:%d/%s", host, (int) port, domain);
 
187
    else if ((!domain) && client_address)
 
188
        snprintf(buf, SQUIDHOSTNAMELEN * 2 + 10, "%s:%d-%s", host, (int) port, inet_ntoa(*client_address));
184
189
    else
185
190
        snprintf(buf, SQUIDHOSTNAMELEN * 2 + 10, "%s:%d", host, (int) port);
186
191
 
222
227
}
223
228
 
224
229
void
225
 
PconnPool::push(int fd, const char *host, u_short port, const char *domain)
 
230
 
 
231
PconnPool::push(int fd, const char *host, u_short port, const char *domain, struct IN_ADDR *client_address)
226
232
{
227
233
 
228
234
    IdleConnList *list;
229
235
    const char *aKey;
230
236
    LOCAL_ARRAY(char, desc, FD_DESC_SZ);
231
237
 
232
 
    if (fdUsageHigh()) {
233
 
        debug(48, 3) ("PconnPool::push: Not many unused FDs\n");
 
238
    if (fdUsageHigh())
 
239
    {
 
240
        debugs(48, 3, "PconnPool::push: Not many unused FDs");
234
241
        comm_close(fd);
235
242
        return;
236
 
    } else if (shutting_down) {
 
243
    } else if (shutting_down)
 
244
    {
237
245
        comm_close(fd);
238
246
        return;
239
247
    }
240
248
 
241
 
    aKey = key(host, port, domain);
 
249
    aKey = key(host, port, domain, client_address);
242
250
 
243
251
    list = (IdleConnList *) hash_lookup(table, aKey);
244
252
 
245
 
    if (list == NULL) {
 
253
    if (list == NULL)
 
254
    {
246
255
        list = new IdleConnList(aKey, this);
247
 
        debug(48, 3) ("pconnNew: adding %s\n", hashKeyStr(&list->hash));
 
256
        debugs(48, 3, "pconnNew: adding " << hashKeyStr(&list->hash));
248
257
        hash_join(table, &list->hash);
249
258
    }
250
259
 
253
262
    assert(!comm_has_incomplete_write(fd));
254
263
    snprintf(desc, FD_DESC_SZ, "%s idle connection", host);
255
264
    fd_note(fd, desc);
256
 
    debug(48, 3) ("PconnPool::push: pushed FD %d for %s\n", fd, aKey);
 
265
    debugs(48, 3, "PconnPool::push: pushed FD " << fd << " for " << aKey);
257
266
}
258
267
 
259
268
/*
260
269
 * return a pconn fd for host:port, or -1 if none are available
261
270
 */
262
271
int
263
 
PconnPool::pop(const char *host, u_short port, const char *domain)
 
272
 
 
273
PconnPool::pop(const char *host, u_short port, const char *domain, struct IN_ADDR *client_address)
264
274
{
265
275
    IdleConnList *list;
266
 
    const char * aKey = key(host, port, domain);
 
276
    const char * aKey = key(host, port, domain, client_address);
267
277
    list = (IdleConnList *)hash_lookup(table, aKey);
268
278
 
269
279
    if (list == NULL)
271
281
 
272
282
    int fd = list->findUseableFD();
273
283
 
274
 
    if (fd >= 0) {
 
284
    if (fd >= 0)
 
285
    {
275
286
        list->clearHandlers(fd);
276
287
        list->removeFD(fd);     /* might delete list */
277
288
    }
304
315
{
305
316
    pools = (PconnPool **) xcalloc(MAX_NUM_PCONN_POOLS, sizeof(*pools));
306
317
    pconn_fds_pool = memPoolCreate("pconn_fds", PCONN_FDS_SZ * sizeof(int));
307
 
    debug(48, 0) ("persistent connection module initialized\n");
 
318
    debugs(48, 0, "persistent connection module initialized");
308
319
}
309
320
 
310
321
PconnModule *