]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Squid-3 Coding guidelines polish for IdleConnList
authorAmos Jeffries <squid3@treenet.co.nz>
Tue, 5 Oct 2010 13:19:24 +0000 (02:19 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Tue, 5 Oct 2010 13:19:24 +0000 (02:19 +1300)
src/pconn.cc
src/pconn.h

index 902540550da2def4f1b69848c775e0409451f75b..8878b352ce9ea976af5edda9e786633d02c49038 100644 (file)
@@ -49,25 +49,25 @@ CBDATA_CLASS_INIT(IdleConnList);
 /* ========== IdleConnList ============================================ */
 
 IdleConnList::IdleConnList(const char *key, PconnPool *thePool) :
-        nfds_alloc(PCONN_FDS_SZ),
-        nfds(0),
-        parent(thePool)
+        capacity_(PCONN_FDS_SZ),
+        size_(0),
+        parent_(thePool)
 {
     hash.key = xstrdup(key);
-    theList = new Comm::ConnectionPointer[nfds_alloc];
-// TODO: re-attach to MemPools. WAS: fds = (int *)pconn_fds_pool->alloc();
+    theList_ = new Comm::ConnectionPointer[capacity_];
+// TODO: re-attach to MemPools. WAS: theList = (?? *)pconn_fds_pool->alloc();
 }
 
 IdleConnList::~IdleConnList()
 {
-    parent->unlinkList(this);
+    parent_->unlinkList(this);
 
 /* TODO: re-attach to MemPools.
-    if (nfds_alloc == PCONN_FDS_SZ)
-        pconn_fds_pool->freeOne(theList);
+    if (capacity_ == PCONN_FDS_SZ)
+        pconn_fds_pool->freeOne(theList_);
     else
 */
-    delete[] theList;
+    delete[] theList_;
 
     xfree(hash.key);
 }
@@ -81,8 +81,8 @@ IdleConnList::~IdleConnList()
 int
 IdleConnList::findIndexOf(const Comm::ConnectionPointer &conn) const
 {
-    for (int index = nfds - 1; index >= 0; --index) {
-        if (conn->fd == theList[index]->fd) {
+    for (int index = size_ - 1; index >= 0; --index) {
+        if (conn->fd == theList_[index]->fd) {
             debugs(48, 3, HERE << "found " << conn << " at index " << index);
             return index;
         }
@@ -98,14 +98,15 @@ IdleConnList::findIndexOf(const Comm::ConnectionPointer &conn) const
 bool
 IdleConnList::removeAt(int index)
 {
-    if (index < 0 || index >= nfds)
+    if (index < 0 || index >= size_)
         return false;
 
     // shuffle the remaining entries to fill the new gap.
-    for (; index < nfds - 1; index++)
-        theList[index] = theList[index + 1];
+    for (; index < size_ - 1; index++)
+        theList_[index] = theList_[index + 1];
+    theList_[size_] = NULL;
 
-    if (--nfds == 0) {
+    if (--size_ == 0) {
         debugs(48, 3, HERE << "deleting " << hashKeyStr(&hash));
         delete this;
     }
@@ -122,24 +123,24 @@ IdleConnList::clearHandlers(const Comm::ConnectionPointer &conn)
 void
 IdleConnList::push(const Comm::ConnectionPointer &conn)
 {
-    if (nfds == nfds_alloc) {
-        debugs(48, 3, "IdleConnList::push: growing FD array");
-        nfds_alloc <<= 1;
-        const Comm::ConnectionPointer *oldList = theList;
-        theList = new Comm::ConnectionPointer[nfds_alloc];
-        for (int index = 0; index < nfds; index++)
-            theList[index] = oldList[index];
+    if (size_ == capacity_) {
+        debugs(48, 3, HERE << "growing idle Connection array");
+        capacity_ <<= 1;
+        const Comm::ConnectionPointer *oldList = theList_;
+        theList_ = new Comm::ConnectionPointer[capacity_];
+        for (int index = 0; index < size_; index++)
+            theList_[index] = oldList[index];
 
 /* TODO: re-attach to MemPools.
-        if (nfds == PCONN_FDS_SZ)
+        if (size_ == PCONN_FDS_SZ)
             pconn_fds_pool->freeOne(oldList);
         else
 */
         delete[] oldList;
     }
 
-    theList[nfds++] = conn;
-    comm_read(conn, fakeReadBuf, sizeof(fakeReadBuf), IdleConnList::Read, this);
+    theList_[size_++] = conn;
+    comm_read(conn, fakeReadBuf_, sizeof(fakeReadBuf_), IdleConnList::Read, this);
     commSetTimeout(conn->fd, Config.Timeout.pconn, IdleConnList::Timeout, this);
 }
 
@@ -154,24 +155,24 @@ IdleConnList::push(const Comm::ConnectionPointer &conn)
 Comm::ConnectionPointer
 IdleConnList::findUseable(const Comm::ConnectionPointer &key)
 {
-    assert(nfds);
+    assert(size_);
 
-    for (int i=nfds-1; i>=0; i--) {
+    for (int i=size_-1; i>=0; i--) {
 
         // callback pending indicates that remote end of the conn has just closed.
-        if (comm_has_pending_read_callback(theList[i]->fd))
+        if (comm_has_pending_read_callback(theList_[i]->fd))
             continue;
 
         // local end port is required, but dont match.
-        if (key->local.GetPort() > 0 && key->local.GetPort() != theList[i]->local.GetPort())
+        if (key->local.GetPort() > 0 && key->local.GetPort() != theList_[i]->local.GetPort())
             continue;
 
         // local address is required, but does not match.
-        if (!key->local.IsAnyAddr() && key->local.matchIPAddr(theList[i]->local) != 0)
+        if (!key->local.IsAnyAddr() && key->local.matchIPAddr(theList_[i]->local) != 0)
             continue;
 
         // finally, a match. pop and return it.
-        Comm::ConnectionPointer result = theList[i];
+        Comm::ConnectionPointer result = theList_[i];
         /* may delete this */
         removeAt(i);
         return result;
index 00db350aa05cc4758cf9aadbd1ccd9f8050fcf44..859cc5ea8965b86a3ae87470fd734a268cc1821e 100644 (file)
@@ -34,7 +34,6 @@ class IdleConnList
 public:
     IdleConnList(const char *key, PconnPool *parent);
     ~IdleConnList();
-    int numIdle() const { return nfds; }
 
     /// Pass control of the connection to the idle list.
     void push(const Comm::ConnectionPointer &conn);
@@ -64,21 +63,21 @@ private:
      * The worst-case pop() and scans occur on timeout and link closure events
      * where timing is less critical. Occasional slow additions are okay.
      */
-    Comm::ConnectionPointer *theList;
+    Comm::ConnectionPointer *theList_;
 
     /// Number of entries theList can currently hold without re-allocating (capacity).
-    int nfds_alloc;
+    int capacity_;
     ///< Number of in-use entries in theList
-    int nfds;
+    int size_;
 
     /** The pool containing this sub-list.
      * The parent performs all stats accounting, and
      * will delete us when it dies. It persists for the
      * full duration of our existence.
      */
-    PconnPool *parent;
+    PconnPool *parent_;
 
-    char fakeReadBuf[4096]; // TODO: kill magic number.
+    char fakeReadBuf_[4096]; // TODO: kill magic number.
 
     CBDATA_CLASS2(IdleConnList);
 };