2 * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
34 #include <ipxe/pool.h>
37 * Recycle this connection after closing
39 * @v intf Data transfer interface
41 void pool_recycle ( struct interface *intf ) {
43 intf_poke ( intf, pool_recycle );
47 * Reopen a defunct connection
49 * @v intf Data transfer interface
51 void pool_reopen ( struct interface *intf ) {
53 intf_poke ( intf, pool_reopen );
57 * Add connection to pool
59 * @v pool Pooled connection
60 * @v list List of pooled connections
61 * @v expiry Expiry time
63 void pool_add ( struct pooled_connection *pool, struct list_head *list,
64 unsigned long expiry ) {
67 assert ( list_empty ( &pool->list ) );
68 assert ( ! timer_running ( &pool->timer ) );
70 /* Add to list of pooled connections */
71 list_add_tail ( &pool->list, list );
73 /* Start expiry timer */
74 start_timer_fixed ( &pool->timer, expiry );
78 * Remove connection from pool
80 * @v pool Pooled connection
82 void pool_del ( struct pooled_connection *pool ) {
84 /* Remove from list of pooled connections */
85 list_del ( &pool->list );
86 INIT_LIST_HEAD ( &pool->list );
88 /* Stop expiry timer */
89 stop_timer ( &pool->timer );
91 /* Mark as a freshly recycled connection */
92 pool->flags = POOL_RECYCLED;
96 * Close expired pooled connection
98 * @v timer Expiry timer
99 * @v over Failure indicator
101 void pool_expired ( struct retry_timer *timer, int over __unused ) {
102 struct pooled_connection *pool =
103 container_of ( timer, struct pooled_connection, timer );
106 assert ( ! list_empty ( &pool->list ) );
108 /* Remove from connection pool */
109 list_del ( &pool->list );
110 INIT_LIST_HEAD ( &pool->list );
112 /* Close expired connection */
113 pool->expired ( pool );