multiif.h (7683B)
1 #ifndef HEADER_CURL_MULTIIF_H 2 #define HEADER_CURL_MULTIIF_H 3 /*************************************************************************** 4 * _ _ ____ _ 5 * Project ___| | | | _ \| | 6 * / __| | | | |_) | | 7 * | (__| |_| | _ <| |___ 8 * \___|\___/|_| \_\_____| 9 * 10 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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 27 /* 28 * Prototypes for library-wide functions provided by multi.c 29 */ 30 31 void Curl_expire(struct Curl_easy *data, timediff_t milli, expire_id); 32 void Curl_expire_ex(struct Curl_easy *data, 33 const struct curltime *nowp, 34 timediff_t milli, expire_id id); 35 bool Curl_expire_clear(struct Curl_easy *data); 36 void Curl_expire_done(struct Curl_easy *data, expire_id id); 37 CURLMcode Curl_update_timer(struct Curl_multi *multi) WARN_UNUSED_RESULT; 38 void Curl_attach_connection(struct Curl_easy *data, 39 struct connectdata *conn); 40 void Curl_detach_connection(struct Curl_easy *data); 41 bool Curl_multiplex_wanted(const struct Curl_multi *multi); 42 void Curl_set_in_callback(struct Curl_easy *data, bool value); 43 bool Curl_is_in_callback(struct Curl_easy *data); 44 CURLcode Curl_preconnect(struct Curl_easy *data); 45 46 void Curl_multi_connchanged(struct Curl_multi *multi); 47 48 /* Internal version of curl_multi_init() accepts size parameters for the 49 socket, connection and dns hashes */ 50 struct Curl_multi *Curl_multi_handle(unsigned int xfer_table_size, 51 size_t hashsize, 52 size_t chashsize, 53 size_t dnssize, 54 size_t sesssize); 55 56 /* the write bits start at bit 16 for the *getsock() bitmap */ 57 #define GETSOCK_WRITEBITSTART 16 58 59 #define GETSOCK_BLANK 0 /* no bits set */ 60 61 /* set the bit for the given sock number to make the bitmap for writable */ 62 #define GETSOCK_WRITESOCK(x) (1 << (GETSOCK_WRITEBITSTART + (x))) 63 64 /* set the bit for the given sock number to make the bitmap for readable */ 65 #define GETSOCK_READSOCK(x) (1 << (x)) 66 67 /* mask for checking if read and/or write is set for index x */ 68 #define GETSOCK_MASK_RW(x) (GETSOCK_READSOCK(x)|GETSOCK_WRITESOCK(x)) 69 70 /** 71 * Let the multi handle know that the socket is about to be closed. 72 * The multi will then remove anything it knows about the socket, so 73 * when the OS is using this socket (number) again subsequently, 74 * the internal book keeping will not get confused. 75 */ 76 void Curl_multi_will_close(struct Curl_easy *data, curl_socket_t s); 77 78 /* 79 * Add a handle and move it into PERFORM state at once. For pushed streams. 80 */ 81 CURLMcode Curl_multi_add_perform(struct Curl_multi *multi, 82 struct Curl_easy *data, 83 struct connectdata *conn); 84 85 86 /* Return the value of the CURLMOPT_MAX_CONCURRENT_STREAMS option */ 87 unsigned int Curl_multi_max_concurrent_streams(struct Curl_multi *multi); 88 89 void Curl_multi_getsock(struct Curl_easy *data, 90 struct easy_pollset *ps, 91 const char *caller); 92 93 /** 94 * Borrow the transfer buffer from the multi, suitable 95 * for the given transfer `data`. The buffer may only be used in one 96 * multi processing of the easy handle. It MUST be returned to the 97 * multi before it can be borrowed again. 98 * Pointers into the buffer remain only valid as long as it is borrowed. 99 * 100 * @param data the easy handle 101 * @param pbuf on return, the buffer to use or NULL on error 102 * @param pbuflen on return, the size of *pbuf or 0 on error 103 * @return CURLE_OK when buffer is available and is returned. 104 * CURLE_OUT_OF_MEMORy on failure to allocate the buffer, 105 * CURLE_FAILED_INIT if the easy handle is without multi. 106 * CURLE_AGAIN if the buffer is borrowed already. 107 */ 108 CURLcode Curl_multi_xfer_buf_borrow(struct Curl_easy *data, 109 char **pbuf, size_t *pbuflen); 110 /** 111 * Release the borrowed buffer. All references into the buffer become 112 * invalid after this. 113 * @param buf the buffer pointer borrowed for coding error checks. 114 */ 115 void Curl_multi_xfer_buf_release(struct Curl_easy *data, char *buf); 116 117 /** 118 * Borrow the upload buffer from the multi, suitable 119 * for the given transfer `data`. The buffer may only be used in one 120 * multi processing of the easy handle. It MUST be returned to the 121 * multi before it can be borrowed again. 122 * Pointers into the buffer remain only valid as long as it is borrowed. 123 * 124 * @param data the easy handle 125 * @param pbuf on return, the buffer to use or NULL on error 126 * @param pbuflen on return, the size of *pbuf or 0 on error 127 * @return CURLE_OK when buffer is available and is returned. 128 * CURLE_OUT_OF_MEMORy on failure to allocate the buffer, 129 * CURLE_FAILED_INIT if the easy handle is without multi. 130 * CURLE_AGAIN if the buffer is borrowed already. 131 */ 132 CURLcode Curl_multi_xfer_ulbuf_borrow(struct Curl_easy *data, 133 char **pbuf, size_t *pbuflen); 134 135 /** 136 * Release the borrowed upload buffer. All references into the buffer become 137 * invalid after this. 138 * @param buf the upload buffer pointer borrowed for coding error checks. 139 */ 140 void Curl_multi_xfer_ulbuf_release(struct Curl_easy *data, char *buf); 141 142 /** 143 * Borrow the socket scratch buffer from the multi, suitable 144 * for the given transfer `data`. The buffer may only be used for 145 * direct socket I/O operation by one connection at a time and MUST be 146 * returned to the multi before the I/O call returns. 147 * Pointers into the buffer remain only valid as long as it is borrowed. 148 * 149 * @param data the easy handle 150 * @param blen requested length of the buffer 151 * @param pbuf on return, the buffer to use or NULL on error 152 * @return CURLE_OK when buffer is available and is returned. 153 * CURLE_OUT_OF_MEMORy on failure to allocate the buffer, 154 * CURLE_FAILED_INIT if the easy handle is without multi. 155 * CURLE_AGAIN if the buffer is borrowed already. 156 */ 157 CURLcode Curl_multi_xfer_sockbuf_borrow(struct Curl_easy *data, 158 size_t blen, char **pbuf); 159 /** 160 * Release the borrowed buffer. All references into the buffer become 161 * invalid after this. 162 * @param buf the buffer pointer borrowed for coding error checks. 163 */ 164 void Curl_multi_xfer_sockbuf_release(struct Curl_easy *data, char *buf); 165 166 /** 167 * Get the easy handle for the given mid. 168 * Returns NULL if not found. 169 */ 170 struct Curl_easy *Curl_multi_get_easy(struct Curl_multi *multi, 171 unsigned int mid); 172 173 /* Get the # of transfers current in process/pending. */ 174 unsigned int Curl_multi_xfers_running(struct Curl_multi *multi); 175 176 /* Mark a transfer as dirty, e.g. to be rerun at earliest convenience. 177 * A cheap operation, can be done many times repeatedly. */ 178 void Curl_multi_mark_dirty(struct Curl_easy *data); 179 180 #endif /* HEADER_CURL_MULTIIF_H */