cshutdn.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #ifndef HEADER_CURL_CSHUTDN_H
  2. #define HEADER_CURL_CSHUTDN_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
  11. * Copyright (C) Linus Nielsen Feltzing, <[email protected]>
  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.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. * SPDX-License-Identifier: curl
  25. *
  26. ***************************************************************************/
  27. #include <curl/curl.h>
  28. #include "curlx/timeval.h"
  29. struct connectdata;
  30. struct Curl_easy;
  31. struct curl_pollfds;
  32. struct Curl_waitfds;
  33. struct Curl_multi;
  34. struct Curl_share;
  35. /* Run the shutdown of the connection once.
  36. * Will shortly attach/detach `data` to `conn` while doing so.
  37. * `done` will be set TRUE if any error was encountered or if
  38. * the connection was shut down completely. */
  39. void Curl_cshutdn_run_once(struct Curl_easy *data,
  40. struct connectdata *conn,
  41. bool *done);
  42. /* Terminates the connection, e.g. closes and destroys it.
  43. * If `run_shutdown` is TRUE, the shutdown will be run once before
  44. * terminating it.
  45. * Takes ownership of `conn`. */
  46. void Curl_cshutdn_terminate(struct Curl_easy *data,
  47. struct connectdata *conn,
  48. bool run_shutdown);
  49. /* A `cshutdown` is always owned by a multi handle to maintain
  50. * the connections to be shut down. It registers timers and
  51. * sockets to monitor via the multi handle. */
  52. struct cshutdn {
  53. struct Curl_llist list; /* connections being shut down */
  54. struct Curl_multi *multi; /* the multi owning this */
  55. BIT(initialised);
  56. };
  57. /* Init as part of the given multi handle. */
  58. int Curl_cshutdn_init(struct cshutdn *cshutdn,
  59. struct Curl_multi *multi);
  60. /* Terminate all remaining connections and free resources. */
  61. void Curl_cshutdn_destroy(struct cshutdn *cshutdn,
  62. struct Curl_easy *data);
  63. /* Number of connections being shut down. */
  64. size_t Curl_cshutdn_count(struct Curl_easy *data);
  65. /* Number of connections to the destination being shut down. */
  66. size_t Curl_cshutdn_dest_count(struct Curl_easy *data,
  67. const char *destination);
  68. /* Close the oldest connection in shutdown to destination or,
  69. * when destination is NULL for any destination.
  70. * Return TRUE if a connection has been closed. */
  71. bool Curl_cshutdn_close_oldest(struct Curl_easy *data,
  72. const char *destination);
  73. /* Add a connection to have it shut down. Will terminate the oldest
  74. * connection when total connection limit of multi is being reached. */
  75. void Curl_cshutdn_add(struct cshutdn *cshutdn,
  76. struct connectdata *conn,
  77. size_t conns_in_pool);
  78. /* Add sockets and POLLIN/OUT flags for connections being shut down. */
  79. CURLcode Curl_cshutdn_add_pollfds(struct cshutdn *cshutdn,
  80. struct Curl_easy *data,
  81. struct curl_pollfds *cpfds);
  82. unsigned int Curl_cshutdn_add_waitfds(struct cshutdn *cshutdn,
  83. struct Curl_easy *data,
  84. struct Curl_waitfds *cwfds);
  85. void Curl_cshutdn_setfds(struct cshutdn *cshutdn,
  86. struct Curl_easy *data,
  87. fd_set *read_fd_set, fd_set *write_fd_set,
  88. int *maxfd);
  89. /* Run shut down connections using socket. If socket is CURL_SOCKET_TIMEOUT,
  90. * run maintenance on all connections. */
  91. void Curl_cshutdn_perform(struct cshutdn *cshutdn,
  92. struct Curl_easy *data,
  93. curl_socket_t s);
  94. #endif /* HEADER_CURL_CSHUTDN_H */