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.
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.
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)
87
87
int index = findFDIndex(fd);
89
debugs(48, 2, "IdleConnList::removeFD: FD " << fd << " NOT FOUND!");
89
92
debugs(48, 3, "IdleConnList::removeFD: found FD " << fd << " at index " << index);
91
94
for (; index < nfds - 1; index++)
174
177
/* ========== PconnPool PRIVATE FUNCTIONS ============================================ */
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)
180
182
LOCAL_ARRAY(char, buf, SQUIDHOSTNAMELEN * 3 + 10);
183
char ntoabuf[MAX_IPSTRLEN];
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));
189
192
snprintf(buf, SQUIDHOSTNAMELEN * 3 + 10, "%s:%d", host, (int) port);
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 << "}" );
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)
251
253
IdleConnList *list;
252
254
const char *aKey;
253
255
LOCAL_ARRAY(char, desc, FD_DESC_SZ);
257
258
debugs(48, 3, "PconnPool::push: Not many unused FDs");
260
} else if (shutting_down)
261
} else if (shutting_down) {
263
263
debugs(48, 3, "PconnPool::push: Squid is shutting down. Refusing to do anything");
269
269
list = (IdleConnList *) hash_lookup(table, aKey);
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.
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)
299
298
const char * aKey = key(host, port, domain, client_address);
302
301
if (list == NULL) {
303
302
debugs(48, 3, "PconnPool::pop: lookup for key {" << aKey << "} failed.");
306
305
debugs(48, 3, "PconnPool::pop: found " << hashKeyStr(&list->hash) << (isRetriable?"(to use)":"(to kill)") );
309
308
int fd = list->findUseableFD(); // search from the end. skip pending reads.
313
311
list->clearHandlers(fd);
314
312
list->removeFD(fd); /* might delete list */
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();
363
PconnModule::registerWithCacheManager(CacheManager & manager)
362
PconnModule::registerWithCacheManager(void)
365
manager.registerAction("pconn",
366
"Persistent Connection Utilization Histograms",
364
CacheManager::GetInstance()->
365
registerAction("pconn",
366
"Persistent Connection Utilization Histograms",
375
375
assert(poolCount < MAX_NUM_PCONN_POOLS);
376
376
*(pools+poolCount) = aPool;