connect.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #ifndef HEADER_CURL_CONNECT_H
  2. #define HEADER_CURL_CONNECT_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) Daniel Stenberg, <[email protected]>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at https://curl.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. * SPDX-License-Identifier: curl
  24. *
  25. ***************************************************************************/
  26. #include "curl_setup.h"
  27. #include "curlx/nonblock.h" /* for curlx_nonblock() */
  28. #include "sockaddr.h"
  29. #include "curlx/timeval.h"
  30. struct Curl_dns_entry;
  31. struct ip_quadruple;
  32. enum alpnid Curl_alpn2alpnid(const char *name, size_t len);
  33. /* generic function that returns how much time there is left to run, according
  34. to the timeouts set */
  35. timediff_t Curl_timeleft(struct Curl_easy *data,
  36. struct curltime *nowp,
  37. bool duringconnect);
  38. #define DEFAULT_CONNECT_TIMEOUT 300000 /* milliseconds == five minutes */
  39. #define DEFAULT_SHUTDOWN_TIMEOUT_MS (2 * 1000)
  40. void Curl_shutdown_start(struct Curl_easy *data, int sockindex,
  41. int timeout_ms, struct curltime *nowp);
  42. /* return how much time there is left to shutdown the connection at
  43. * sockindex. Returns 0 if there is no limit or shutdown has not started. */
  44. timediff_t Curl_shutdown_timeleft(struct connectdata *conn, int sockindex,
  45. struct curltime *nowp);
  46. /* return how much time there is left to shutdown the connection.
  47. * Returns 0 if there is no limit or shutdown has not started. */
  48. timediff_t Curl_conn_shutdown_timeleft(struct connectdata *conn,
  49. struct curltime *nowp);
  50. void Curl_shutdown_clear(struct Curl_easy *data, int sockindex);
  51. /* TRUE iff shutdown has been started */
  52. bool Curl_shutdown_started(struct Curl_easy *data, int sockindex);
  53. /*
  54. * Used to extract socket and connectdata struct for the most recent
  55. * transfer on the given Curl_easy.
  56. *
  57. * The returned socket will be CURL_SOCKET_BAD in case of failure!
  58. */
  59. curl_socket_t Curl_getconnectinfo(struct Curl_easy *data,
  60. struct connectdata **connp);
  61. bool Curl_addr2string(struct sockaddr *sa, curl_socklen_t salen,
  62. char *addr, int *port);
  63. /*
  64. * Curl_conncontrol() marks the end of a connection/stream. The 'closeit'
  65. * argument specifies if it is the end of a connection or a stream.
  66. *
  67. * For stream-based protocols (such as HTTP/2), a stream close will not cause
  68. * a connection close. Other protocols will close the connection for both
  69. * cases.
  70. *
  71. * It sets the bit.close bit to TRUE (with an explanation for debug builds),
  72. * when the connection will close.
  73. */
  74. #define CONNCTRL_KEEP 0 /* undo a marked closure */
  75. #define CONNCTRL_CONNECTION 1
  76. #define CONNCTRL_STREAM 2
  77. void Curl_conncontrol(struct connectdata *conn,
  78. int closeit
  79. #if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS)
  80. , const char *reason
  81. #endif
  82. );
  83. #if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS)
  84. #define streamclose(x,y) Curl_conncontrol(x, CONNCTRL_STREAM, y)
  85. #define connclose(x,y) Curl_conncontrol(x, CONNCTRL_CONNECTION, y)
  86. #define connkeep(x,y) Curl_conncontrol(x, CONNCTRL_KEEP, y)
  87. #else /* if !DEBUGBUILD || CURL_DISABLE_VERBOSE_STRINGS */
  88. #define streamclose(x,y) Curl_conncontrol(x, CONNCTRL_STREAM)
  89. #define connclose(x,y) Curl_conncontrol(x, CONNCTRL_CONNECTION)
  90. #define connkeep(x,y) Curl_conncontrol(x, CONNCTRL_KEEP)
  91. #endif
  92. CURLcode Curl_cf_setup_insert_after(struct Curl_cfilter *cf_at,
  93. struct Curl_easy *data,
  94. int transport,
  95. int ssl_mode);
  96. /**
  97. * Setup the cfilters at `sockindex` in connection `conn`.
  98. * If no filter chain is installed yet, inspects the configuration
  99. * in `data` and `conn? to install a suitable filter chain.
  100. */
  101. CURLcode Curl_conn_setup(struct Curl_easy *data,
  102. struct connectdata *conn,
  103. int sockindex,
  104. struct Curl_dns_entry *dns,
  105. int ssl_mode);
  106. /* Set conn to allow multiplexing. */
  107. void Curl_conn_set_multiplex(struct connectdata *conn);
  108. extern struct Curl_cftype Curl_cft_setup;
  109. #endif /* HEADER_CURL_CONNECT_H */