You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pool.c 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. /**
  25. * @file
  26. *
  27. * Pooled connections
  28. *
  29. */
  30. #include <assert.h>
  31. #include <ipxe/pool.h>
  32. /**
  33. * Recycle this connection after closing
  34. *
  35. * @v intf Data transfer interface
  36. */
  37. void pool_recycle ( struct interface *intf ) {
  38. intf_poke ( intf, pool_recycle );
  39. }
  40. /**
  41. * Reopen a defunct connection
  42. *
  43. * @v intf Data transfer interface
  44. */
  45. void pool_reopen ( struct interface *intf ) {
  46. intf_poke ( intf, pool_reopen );
  47. }
  48. /**
  49. * Add connection to pool
  50. *
  51. * @v pool Pooled connection
  52. * @v list List of pooled connections
  53. * @v expiry Expiry time
  54. */
  55. void pool_add ( struct pooled_connection *pool, struct list_head *list,
  56. unsigned long expiry ) {
  57. /* Sanity check */
  58. assert ( list_empty ( &pool->list ) );
  59. assert ( ! timer_running ( &pool->timer ) );
  60. /* Add to list of pooled connections */
  61. list_add_tail ( &pool->list, list );
  62. /* Start expiry timer */
  63. start_timer_fixed ( &pool->timer, expiry );
  64. }
  65. /**
  66. * Remove connection from pool
  67. *
  68. * @v pool Pooled connection
  69. */
  70. void pool_del ( struct pooled_connection *pool ) {
  71. /* Remove from list of pooled connections */
  72. list_del ( &pool->list );
  73. INIT_LIST_HEAD ( &pool->list );
  74. /* Stop expiry timer */
  75. stop_timer ( &pool->timer );
  76. /* Mark as a freshly recycled connection */
  77. pool->flags = POOL_RECYCLED;
  78. }
  79. /**
  80. * Close expired pooled connection
  81. *
  82. * @v timer Expiry timer
  83. * @v over Failure indicator
  84. */
  85. void pool_expired ( struct retry_timer *timer, int over __unused ) {
  86. struct pooled_connection *pool =
  87. container_of ( timer, struct pooled_connection, timer );
  88. /* Sanity check */
  89. assert ( ! list_empty ( &pool->list ) );
  90. /* Remove from connection pool */
  91. list_del ( &pool->list );
  92. INIT_LIST_HEAD ( &pool->list );
  93. /* Close expired connection */
  94. pool->expired ( pool );
  95. }