/* ========== 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);
}
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;
}
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;
}
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);
}
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;
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);
* 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);
};