]>
git.saurik.com Git - apple/security.git/blob - Network/connectionpool.cpp
bea735d4cf32464daa87e3866824176c4288380a
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 // connectionpool - manage pool of active, unused Connection objects
22 #include "connectionpool.h"
23 #include "netconnection.h"
31 // Try to locate a Connection with a suitable HostTarget from the pool.
32 // If found, remove it from the pool and return it. Otherwise, return NULL (no error).
34 Connection
*ConnectionPool::get(const HostTarget
&host
)
36 //@@@ locking, of course :-)
37 ConnectionMap::iterator it
= mConnections
.find(host
);
38 if (it
!= mConnections
.end()) {
40 Connection
*connection
= it
->second
;
41 mConnections
.erase(it
);
42 secdebug("connpool", "Connection %p retrieved from pool", connection
);
51 // Retain a Connection in the pool
53 void ConnectionPool::retain(Connection
*connection
)
55 //@@@ threading, of course :-)
56 secdebug("connpool", "Connection %p retained in connection pool", connection
);
57 mConnections
.insert(ConnectionMap::value_type(connection
->hostTarget
, connection
));
58 //mConnections[connection->hostTarget] = connection;
63 // Remove a retained Connection from the pool.
64 // Returns true if found (and removed); false otherwise.
66 bool ConnectionPool::remove(Connection
*connection
)
68 // this search is two-stage to deal with potentially large multimaps
69 typedef ConnectionMap::iterator Iter
;
70 pair
<Iter
, Iter
> range
= mConnections
.equal_range(connection
->hostTarget
);
71 for (Iter it
= range
.first
; it
!= range
.second
; it
++)
72 if (it
->second
== connection
) {
73 mConnections
.erase(it
);
74 secdebug("connpool", "Connection %p removed from connection pool", connection
);
82 // Clear the connection pool
84 void ConnectionPool::purge()
86 secdebug("connpool", "Connection pool purging %ld connections", mConnections
.size());
87 for (ConnectionMap::iterator it
= mConnections
.begin(); it
!= mConnections
.end(); it
++)
89 mConnections
.erase(mConnections
.begin(), mConnections
.end());
93 } // end namespace Network
94 } // end namespace Security