This patch is a little rough but it converts a couple of "should have been
MemPool'ed a long time ago" structures.
Can I get someone to look at this and tell me if its right? If so, I'll
commit it.
(Hint: If you want a quick and fun squid project, go through the code, find
all the static buffers being xcalloc()ed, and convert them to mem pools.
Duane, Henrik and I will love you for it. :-)
Adrian
Index: comm.c
===================================================================
RCS file: /cvsroot/squid/squid/src/comm.c,v
retrieving revision 1.1.1.4.2.1.4.2
diff -u -r1.1.1.4.2.1.4.2 comm.c
--- comm.c 2000/07/14 11:36:30 1.1.1.4.2.1.4.2
+++ comm.c 2000/09/25 09:48:16
@@ -69,7 +69,12 @@
static void commConnectCallback(ConnectStateData * cs, int status);
static int commResetFD(ConnectStateData * cs);
static int commRetryConnect(ConnectStateData * cs);
+static CBDUNL commConnectDataFree;
+
+static MemPool *comm_write_pool = NULL;
+static MemPool *conn_state_pool = NULL;
+
static void
CommWriteStateCallbackAndFree(int fd, int code)
{
@@ -89,7 +94,7 @@
if (callback && cbdataValid(data))
callback(fd, CommWriteState->buf, CommWriteState->offset, code, data);
cbdataUnlock(data);
- safe_free(CommWriteState);
+ memPoolFree(comm_write_pool, CommWriteState);
}
/* Return the local port associated with fd. */
@@ -223,9 +228,9 @@
void
commConnectStart(int fd, const char *host, u_short port, CNCB * callback, void *data)
{
- ConnectStateData *cs = xcalloc(1, sizeof(ConnectStateData));
+ ConnectStateData *cs = memPoolAlloc(conn_state_pool);
debug(5, 3) ("commConnectStart: FD %d, %s:%d\n", fd, host, (int) port);
- cbdataAdd(cs, cbdataXfree, 0);
+ cbdataAdd(cs, commConnectDataFree, 0);
cs->fd = fd;
cs->host = xstrdup(host);
cs->port = port;
@@ -238,6 +243,12 @@
}
static void
+commConnectDataFree(void *data, int unused)
+{
+ memPoolFree(conn_state_pool, data);
+}
+
+static void
commConnectDnsHandle(const ipcache_addrs * ia, void *data)
{
ConnectStateData *cs = data;
@@ -789,6 +800,8 @@
* after accepting a client but before it opens a socket or a file.
* Since Squid_MaxFD can be as high as several thousand, don't waste them */
RESERVED_FD = XMIN(100, Squid_MaxFD / 4);
+ comm_write_pool = memPoolCreate("CommWriteStateData", sizeof(CommWriteStateData));
+ conn_state_pool = memPoolCreate("ConnectStateData", sizeof(ConnectStateData));
}
/* Write to FD. */
@@ -861,11 +874,11 @@
fd, size, handler, handler_data);
if (NULL != state) {
debug(5, 1) ("comm_write: fd_table[%d].rwstate != NULL\n", fd);
- safe_free(state);
+ memPoolFree(comm_write_pool, state);
fd_table[fd].rwstate = NULL;
}
assert(state == NULL);
- fd_table[fd].rwstate = state = xcalloc(1, sizeof(CommWriteStateData));
+ fd_table[fd].rwstate = state = memPoolAlloc(comm_write_pool);
state->buf = buf;
state->size = size;
state->offset = 0;
----- End forwarded message -----
-- Adrian Chadd "If a butterfly flaps its wings in China, <adrian@creative.net.au> will a women get naked in Amsterdam?" -- Ashley Penney on Chaos TheoryReceived on Mon Sep 25 2000 - 03:52:45 MDT
This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:12:38 MST