iPXE
pool.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
3  *
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.
8  *
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.
13  *
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
17  * 02110-1301, USA.
18  *
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.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 /**
27  * @file
28  *
29  * Pooled connections
30  *
31  */
32 
33 #include <assert.h>
34 #include <ipxe/pool.h>
35 
36 /**
37  * Recycle this connection after closing
38  *
39  * @v intf Data transfer interface
40  */
41 void pool_recycle ( struct interface *intf ) {
42 
43  intf_poke ( intf, pool_recycle );
44 }
45 
46 /**
47  * Reopen a defunct connection
48  *
49  * @v intf Data transfer interface
50  */
51 void pool_reopen ( struct interface *intf ) {
52 
53  intf_poke ( intf, pool_reopen );
54 }
55 
56 /**
57  * Add connection to pool
58  *
59  * @v pool Pooled connection
60  * @v list List of pooled connections
61  * @v expiry Expiry time
62  */
63 void pool_add ( struct pooled_connection *pool, struct list_head *list,
64  unsigned long expiry ) {
65 
66  /* Sanity check */
67  assert ( list_empty ( &pool->list ) );
68  assert ( ! timer_running ( &pool->timer ) );
69 
70  /* Add to list of pooled connections */
71  list_add_tail ( &pool->list, list );
72 
73  /* Start expiry timer */
74  start_timer_fixed ( &pool->timer, expiry );
75 }
76 
77 /**
78  * Remove connection from pool
79  *
80  * @v pool Pooled connection
81  */
82 void pool_del ( struct pooled_connection *pool ) {
83 
84  /* Remove from list of pooled connections */
85  list_del ( &pool->list );
86  INIT_LIST_HEAD ( &pool->list );
87 
88  /* Stop expiry timer */
89  stop_timer ( &pool->timer );
90 
91  /* Mark as a freshly recycled connection */
92  pool->flags = POOL_RECYCLED;
93 }
94 
95 /**
96  * Close expired pooled connection
97  *
98  * @v timer Expiry timer
99  * @v over Failure indicator
100  */
101 void pool_expired ( struct retry_timer *timer, int over __unused ) {
102  struct pooled_connection *pool =
104 
105  /* Sanity check */
106  assert ( ! list_empty ( &pool->list ) );
107 
108  /* Remove from connection pool */
109  list_del ( &pool->list );
110  INIT_LIST_HEAD ( &pool->list );
111 
112  /* Close expired connection */
113  pool->expired ( pool );
114 }
void pool_add(struct pooled_connection *pool, struct list_head *list, unsigned long expiry)
Add connection to pool.
Definition: pool.c:63
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
timer_init & pool
Definition: pool.h:65
Pooled connections.
A retry timer.
Definition: retry.h:21
A pooled connection.
Definition: pool.h:17
void pool_del(struct pooled_connection *pool)
Remove connection from pool.
Definition: pool.c:82
A doubly-linked list entry (or list head)
Definition: list.h:18
A timer.
Definition: timer.h:28
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
Connection has been recycled.
Definition: pool.h:42
Assertions.
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
An object interface.
Definition: interface.h:109
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
void pool_reopen(struct interface *intf)
Reopen a defunct connection.
Definition: pool.c:51
void start_timer_fixed(struct retry_timer *timer, unsigned long timeout)
Start timer with a specified timeout.
Definition: retry.c:64
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
void stop_timer(struct retry_timer *timer)
Stop timer.
Definition: retry.c:117
void pool_expired(struct retry_timer *timer, int over __unused)
Close expired pooled connection.
Definition: pool.c:101
void pool_recycle(struct interface *intf)
Recycle this connection after closing.
Definition: pool.c:41
void intf_poke(struct interface *intf, void(type)(struct interface *intf))
Poke an object interface.
Definition: interface.c:397