iPXE
pool.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 /**
00027  * @file
00028  *
00029  * Pooled connections
00030  *
00031  */
00032 
00033 #include <assert.h>
00034 #include <ipxe/pool.h>
00035 
00036 /**
00037  * Recycle this connection after closing
00038  *
00039  * @v intf              Data transfer interface
00040  */
00041 void pool_recycle ( struct interface *intf ) {
00042 
00043         intf_poke ( intf, pool_recycle );
00044 }
00045 
00046 /**
00047  * Reopen a defunct connection
00048  *
00049  * @v intf              Data transfer interface
00050  */
00051 void pool_reopen ( struct interface *intf ) {
00052 
00053         intf_poke ( intf, pool_reopen );
00054 }
00055 
00056 /**
00057  * Add connection to pool
00058  *
00059  * @v pool              Pooled connection
00060  * @v list              List of pooled connections
00061  * @v expiry            Expiry time
00062  */
00063 void pool_add ( struct pooled_connection *pool, struct list_head *list,
00064                 unsigned long expiry ) {
00065 
00066         /* Sanity check */
00067         assert ( list_empty ( &pool->list ) );
00068         assert ( ! timer_running ( &pool->timer ) );
00069 
00070         /* Add to list of pooled connections */
00071         list_add_tail ( &pool->list, list );
00072 
00073         /* Start expiry timer */
00074         start_timer_fixed ( &pool->timer, expiry );
00075 }
00076 
00077 /**
00078  * Remove connection from pool
00079  *
00080  * @v pool              Pooled connection
00081  */
00082 void pool_del ( struct pooled_connection *pool ) {
00083 
00084         /* Remove from list of pooled connections */
00085         list_del ( &pool->list );
00086         INIT_LIST_HEAD ( &pool->list );
00087 
00088         /* Stop expiry timer */
00089         stop_timer ( &pool->timer );
00090 
00091         /* Mark as a freshly recycled connection */
00092         pool->flags = POOL_RECYCLED;
00093 }
00094 
00095 /**
00096  * Close expired pooled connection
00097  *
00098  * @v timer             Expiry timer
00099  * @v over              Failure indicator
00100  */
00101 void pool_expired ( struct retry_timer *timer, int over __unused ) {
00102         struct pooled_connection *pool =
00103                 container_of ( timer, struct pooled_connection, timer );
00104 
00105         /* Sanity check */
00106         assert ( ! list_empty ( &pool->list ) );
00107 
00108         /* Remove from connection pool */
00109         list_del ( &pool->list );
00110         INIT_LIST_HEAD ( &pool->list );
00111 
00112         /* Close expired connection */
00113         pool->expired ( pool );
00114 }