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
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25FILE_SECBOOT ( PERMITTED );
26
27/**
28 * @file
29 *
30 * Pooled connections
31 *
32 */
33
34#include <assert.h>
35#include <ipxe/pool.h>
36
37/**
38 * Recycle this connection after closing
39 *
40 * @v intf Data transfer interface
41 */
42void pool_recycle ( struct interface *intf ) {
43
44 intf_poke ( intf, pool_recycle );
45}
46
47/**
48 * Reopen a defunct connection
49 *
50 * @v intf Data transfer interface
51 */
52void pool_reopen ( struct interface *intf ) {
53
54 intf_poke ( intf, pool_reopen );
55}
56
57/**
58 * Add connection to pool
59 *
60 * @v pool Pooled connection
61 * @v list List of pooled connections
62 * @v expiry Expiry time
63 */
64void pool_add ( struct pooled_connection *pool, struct list_head *list,
65 unsigned long expiry ) {
66
67 /* Sanity check */
68 assert ( list_empty ( &pool->list ) );
69 assert ( ! timer_running ( &pool->timer ) );
70
71 /* Add to list of pooled connections */
72 list_add_tail ( &pool->list, list );
73
74 /* Start expiry timer */
75 start_timer_fixed ( &pool->timer, expiry );
76}
77
78/**
79 * Remove connection from pool
80 *
81 * @v pool Pooled connection
82 */
84
85 /* Remove from list of pooled connections */
86 list_del ( &pool->list );
87 INIT_LIST_HEAD ( &pool->list );
88
89 /* Stop expiry timer */
90 stop_timer ( &pool->timer );
91
92 /* Mark as a freshly recycled connection */
93 pool->flags = POOL_RECYCLED;
94}
95
96/**
97 * Close expired pooled connection
98 *
99 * @v timer Expiry timer
100 * @v over Failure indicator
101 */
102void pool_expired ( struct retry_timer *timer, int over __unused ) {
103 struct pooled_connection *pool =
105
106 /* Sanity check */
107 assert ( ! list_empty ( &pool->list ) );
108
109 /* Remove from connection pool */
110 list_del ( &pool->list );
111 INIT_LIST_HEAD ( &pool->list );
112
113 /* Close expired connection */
114 pool->expired ( pool );
115}
Assertions.
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
#define __unused
Declare a variable or data structure as unused.
Definition compiler.h:573
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
void intf_poke(struct interface *intf, void(type)(struct interface *intf))
Poke an object interface.
Definition interface.c:421
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition list.h:94
#define list_del(list)
Delete an entry from a list.
Definition list.h:120
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition list.h:46
#define list_empty(list)
Test whether a list is empty.
Definition list.h:137
void pool_add(struct pooled_connection *pool, struct list_head *list, unsigned long expiry)
Add connection to pool.
Definition pool.c:64
void pool_recycle(struct interface *intf)
Recycle this connection after closing.
Definition pool.c:42
void pool_del(struct pooled_connection *pool)
Remove connection from pool.
Definition pool.c:83
void pool_expired(struct retry_timer *timer, int over __unused)
Close expired pooled connection.
Definition pool.c:102
void pool_reopen(struct interface *intf)
Reopen a defunct connection.
Definition pool.c:52
Pooled connections.
@ POOL_RECYCLED
Connection has been recycled.
Definition pool.h:43
timer_init & pool
Definition pool.h:66
void start_timer_fixed(struct retry_timer *timer, unsigned long timeout)
Start timer with a specified timeout.
Definition retry.c:65
void stop_timer(struct retry_timer *timer)
Stop timer.
Definition retry.c:118
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
An object interface.
Definition interface.h:125
A doubly-linked list entry (or list head)
Definition list.h:19
A pooled connection.
Definition pool.h:18
A retry timer.
Definition retry.h:22
A timer.
Definition timer.h:29