conncache.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef HEADER_CURL_CONNCACHE_H
  2. #define HEADER_CURL_CONNCACHE_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 2015 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
  11. * Copyright (C) 2012 - 2014, Linus Nielsen Feltzing, <linus@haxx.se>
  12. *
  13. * This software is licensed as described in the file COPYING, which
  14. * you should have received as part of this distribution. The terms
  15. * are also available at https://curl.haxx.se/docs/copyright.html.
  16. *
  17. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  18. * copies of the Software, and permit persons to whom the Software is
  19. * furnished to do so, under the terms of the COPYING file.
  20. *
  21. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  22. * KIND, either express or implied.
  23. *
  24. ***************************************************************************/
  25. /*
  26. * All accesses to struct fields and changing of data in the connection cache
  27. * and connectbundles must be done with the conncache LOCKED. The cache might
  28. * be shared.
  29. */
  30. struct conncache {
  31. struct curl_hash hash;
  32. size_t num_conn;
  33. long next_connection_id;
  34. struct curltime last_cleanup;
  35. /* handle used for closing cached connections */
  36. struct Curl_easy *closure_handle;
  37. };
  38. #define BUNDLE_NO_MULTIUSE -1
  39. #define BUNDLE_UNKNOWN 0 /* initial value */
  40. #define BUNDLE_MULTIPLEX 2
  41. struct connectbundle {
  42. int multiuse; /* supports multi-use */
  43. size_t num_connections; /* Number of connections in the bundle */
  44. struct curl_llist conn_list; /* The connectdata members of the bundle */
  45. };
  46. /* returns 1 on error, 0 is fine */
  47. int Curl_conncache_init(struct conncache *, int size);
  48. void Curl_conncache_destroy(struct conncache *connc);
  49. /* return the correct bundle, to a host or a proxy */
  50. struct connectbundle *Curl_conncache_find_bundle(struct connectdata *conn,
  51. struct conncache *connc);
  52. void Curl_conncache_unlock(struct Curl_easy *data);
  53. /* returns number of connections currently held in the connection cache */
  54. size_t Curl_conncache_size(struct Curl_easy *data);
  55. size_t Curl_conncache_bundle_size(struct connectdata *conn);
  56. bool Curl_conncache_return_conn(struct connectdata *conn);
  57. CURLcode Curl_conncache_add_conn(struct conncache *connc,
  58. struct connectdata *conn) WARN_UNUSED_RESULT;
  59. void Curl_conncache_remove_conn(struct Curl_easy *data,
  60. struct connectdata *conn,
  61. bool lock);
  62. bool Curl_conncache_foreach(struct Curl_easy *data,
  63. struct conncache *connc,
  64. void *param,
  65. int (*func)(struct connectdata *conn,
  66. void *param));
  67. struct connectdata *
  68. Curl_conncache_find_first_connection(struct conncache *connc);
  69. struct connectdata *
  70. Curl_conncache_extract_bundle(struct Curl_easy *data,
  71. struct connectbundle *bundle);
  72. struct connectdata *
  73. Curl_conncache_extract_oldest(struct Curl_easy *data);
  74. void Curl_conncache_close_all_connections(struct conncache *connc);
  75. void Curl_conncache_print(struct conncache *connc);
  76. #endif /* HEADER_CURL_CONNCACHE_H */