Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:54:37

0001 #ifndef CURLINC_MULTI_H
0002 #define CURLINC_MULTI_H
0003 /***************************************************************************
0004  *                                  _   _ ____  _
0005  *  Project                     ___| | | |  _ \| |
0006  *                             / __| | | | |_) | |
0007  *                            | (__| |_| |  _ <| |___
0008  *                             \___|\___/|_| \_\_____|
0009  *
0010  * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
0011  *
0012  * This software is licensed as described in the file COPYING, which
0013  * you should have received as part of this distribution. The terms
0014  * are also available at https://curl.se/docs/copyright.html.
0015  *
0016  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
0017  * copies of the Software, and permit persons to whom the Software is
0018  * furnished to do so, under the terms of the COPYING file.
0019  *
0020  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
0021  * KIND, either express or implied.
0022  *
0023  * SPDX-License-Identifier: curl
0024  *
0025  ***************************************************************************/
0026 /*
0027   This is an "external" header file. Do not give away any internals here!
0028 
0029   GOALS
0030 
0031   o Enable a "pull" interface. The application that uses libcurl decides where
0032     and when to ask libcurl to get/send data.
0033 
0034   o Enable multiple simultaneous transfers in the same thread without making it
0035     complicated for the application.
0036 
0037   o Enable the application to select() on its own file descriptors and curl's
0038     file descriptors simultaneous easily.
0039 
0040 */
0041 
0042 /*
0043  * This header file should not really need to include "curl.h" since curl.h
0044  * itself includes this file and we expect user applications to do #include
0045  * <curl/curl.h> without the need for especially including multi.h.
0046  *
0047  * For some reason we added this include here at one point, and rather than to
0048  * break existing (wrongly written) libcurl applications, we leave it as-is
0049  * but with this warning attached.
0050  */
0051 #include "curl.h"
0052 
0053 #ifdef  __cplusplus
0054 extern "C" {
0055 #endif
0056 
0057 typedef void CURLM;
0058 
0059 typedef enum {
0060   CURLM_CALL_MULTI_PERFORM = -1, /* please call curl_multi_perform() or
0061                                     curl_multi_socket*() soon */
0062   CURLM_OK,
0063   CURLM_BAD_HANDLE,      /* the passed-in handle is not a valid CURLM handle */
0064   CURLM_BAD_EASY_HANDLE, /* an easy handle was not good/valid */
0065   CURLM_OUT_OF_MEMORY,   /* if you ever get this, you are in deep sh*t */
0066   CURLM_INTERNAL_ERROR,  /* this is a libcurl bug */
0067   CURLM_BAD_SOCKET,      /* the passed in socket argument did not match */
0068   CURLM_UNKNOWN_OPTION,  /* curl_multi_setopt() with unsupported option */
0069   CURLM_ADDED_ALREADY,   /* an easy handle already added to a multi handle was
0070                             attempted to get added - again */
0071   CURLM_RECURSIVE_API_CALL, /* an api function was called from inside a
0072                                callback */
0073   CURLM_WAKEUP_FAILURE,  /* wakeup is unavailable or failed */
0074   CURLM_BAD_FUNCTION_ARGUMENT, /* function called with a bad parameter */
0075   CURLM_ABORTED_BY_CALLBACK,
0076   CURLM_UNRECOVERABLE_POLL,
0077   CURLM_LAST
0078 } CURLMcode;
0079 
0080 /* just to make code nicer when using curl_multi_socket() you can now check
0081    for CURLM_CALL_MULTI_SOCKET too in the same style it works for
0082    curl_multi_perform() and CURLM_CALL_MULTI_PERFORM */
0083 #define CURLM_CALL_MULTI_SOCKET CURLM_CALL_MULTI_PERFORM
0084 
0085 /* bitmask bits for CURLMOPT_PIPELINING */
0086 #define CURLPIPE_NOTHING   0L
0087 #define CURLPIPE_HTTP1     1L
0088 #define CURLPIPE_MULTIPLEX 2L
0089 
0090 typedef enum {
0091   CURLMSG_NONE, /* first, not used */
0092   CURLMSG_DONE, /* This easy handle has completed. 'result' contains
0093                    the CURLcode of the transfer */
0094   CURLMSG_LAST /* last, not used */
0095 } CURLMSG;
0096 
0097 struct CURLMsg {
0098   CURLMSG msg;       /* what this message means */
0099   CURL *easy_handle; /* the handle it concerns */
0100   union {
0101     void *whatever;    /* message-specific data */
0102     CURLcode result;   /* return code for transfer */
0103   } data;
0104 };
0105 typedef struct CURLMsg CURLMsg;
0106 
0107 /* Based on poll(2) structure and values.
0108  * We do not use pollfd and POLL* constants explicitly
0109  * to cover platforms without poll(). */
0110 #define CURL_WAIT_POLLIN    0x0001
0111 #define CURL_WAIT_POLLPRI   0x0002
0112 #define CURL_WAIT_POLLOUT   0x0004
0113 
0114 struct curl_waitfd {
0115   curl_socket_t fd;
0116   short events;
0117   short revents;
0118 };
0119 
0120 /*
0121  * Name:    curl_multi_init()
0122  *
0123  * Desc:    initialize multi-style curl usage
0124  *
0125  * Returns: a new CURLM handle to use in all 'curl_multi' functions.
0126  */
0127 CURL_EXTERN CURLM *curl_multi_init(void);
0128 
0129 /*
0130  * Name:    curl_multi_add_handle()
0131  *
0132  * Desc:    add a standard curl handle to the multi stack
0133  *
0134  * Returns: CURLMcode type, general multi error code.
0135  */
0136 CURL_EXTERN CURLMcode curl_multi_add_handle(CURLM *multi_handle,
0137                                             CURL *curl_handle);
0138 
0139  /*
0140   * Name:    curl_multi_remove_handle()
0141   *
0142   * Desc:    removes a curl handle from the multi stack again
0143   *
0144   * Returns: CURLMcode type, general multi error code.
0145   */
0146 CURL_EXTERN CURLMcode curl_multi_remove_handle(CURLM *multi_handle,
0147                                                CURL *curl_handle);
0148 
0149  /*
0150   * Name:    curl_multi_fdset()
0151   *
0152   * Desc:    Ask curl for its fd_set sets. The app can use these to select() or
0153   *          poll() on. We want curl_multi_perform() called as soon as one of
0154   *          them are ready.
0155   *
0156   * Returns: CURLMcode type, general multi error code.
0157   */
0158 CURL_EXTERN CURLMcode curl_multi_fdset(CURLM *multi_handle,
0159                                        fd_set *read_fd_set,
0160                                        fd_set *write_fd_set,
0161                                        fd_set *exc_fd_set,
0162                                        int *max_fd);
0163 
0164 /*
0165  * Name:     curl_multi_wait()
0166  *
0167  * Desc:     Poll on all fds within a CURLM set as well as any
0168  *           additional fds passed to the function.
0169  *
0170  * Returns:  CURLMcode type, general multi error code.
0171  */
0172 CURL_EXTERN CURLMcode curl_multi_wait(CURLM *multi_handle,
0173                                       struct curl_waitfd extra_fds[],
0174                                       unsigned int extra_nfds,
0175                                       int timeout_ms,
0176                                       int *ret);
0177 
0178 /*
0179  * Name:     curl_multi_poll()
0180  *
0181  * Desc:     Poll on all fds within a CURLM set as well as any
0182  *           additional fds passed to the function.
0183  *
0184  * Returns:  CURLMcode type, general multi error code.
0185  */
0186 CURL_EXTERN CURLMcode curl_multi_poll(CURLM *multi_handle,
0187                                       struct curl_waitfd extra_fds[],
0188                                       unsigned int extra_nfds,
0189                                       int timeout_ms,
0190                                       int *ret);
0191 
0192 /*
0193  * Name:     curl_multi_wakeup()
0194  *
0195  * Desc:     wakes up a sleeping curl_multi_poll call.
0196  *
0197  * Returns:  CURLMcode type, general multi error code.
0198  */
0199 CURL_EXTERN CURLMcode curl_multi_wakeup(CURLM *multi_handle);
0200 
0201  /*
0202   * Name:    curl_multi_perform()
0203   *
0204   * Desc:    When the app thinks there is data available for curl it calls this
0205   *          function to read/write whatever there is right now. This returns
0206   *          as soon as the reads and writes are done. This function does not
0207   *          require that there actually is data available for reading or that
0208   *          data can be written, it can be called just in case. It returns
0209   *          the number of handles that still transfer data in the second
0210   *          argument's integer-pointer.
0211   *
0212   * Returns: CURLMcode type, general multi error code. *NOTE* that this only
0213   *          returns errors etc regarding the whole multi stack. There might
0214   *          still have occurred problems on individual transfers even when
0215   *          this returns OK.
0216   */
0217 CURL_EXTERN CURLMcode curl_multi_perform(CURLM *multi_handle,
0218                                          int *running_handles);
0219 
0220  /*
0221   * Name:    curl_multi_cleanup()
0222   *
0223   * Desc:    Cleans up and removes a whole multi stack. It does not free or
0224   *          touch any individual easy handles in any way. We need to define
0225   *          in what state those handles will be if this function is called
0226   *          in the middle of a transfer.
0227   *
0228   * Returns: CURLMcode type, general multi error code.
0229   */
0230 CURL_EXTERN CURLMcode curl_multi_cleanup(CURLM *multi_handle);
0231 
0232 /*
0233  * Name:    curl_multi_info_read()
0234  *
0235  * Desc:    Ask the multi handle if there is any messages/informationals from
0236  *          the individual transfers. Messages include informationals such as
0237  *          error code from the transfer or just the fact that a transfer is
0238  *          completed. More details on these should be written down as well.
0239  *
0240  *          Repeated calls to this function will return a new struct each
0241  *          time, until a special "end of msgs" struct is returned as a signal
0242  *          that there is no more to get at this point.
0243  *
0244  *          The data the returned pointer points to will not survive calling
0245  *          curl_multi_cleanup().
0246  *
0247  *          The 'CURLMsg' struct is meant to be simple and only contain basic
0248  *          information. If more involved information is wanted, we will
0249  *          provide the particular "transfer handle" in that struct and that
0250  *          should/could/would be used in subsequent curl_easy_getinfo() calls
0251  *          (or similar). The point being that we must never expose complex
0252  *          structs to applications, as then we will undoubtably get backwards
0253  *          compatibility problems in the future.
0254  *
0255  * Returns: A pointer to a filled-in struct, or NULL if it failed or ran out
0256  *          of structs. It also writes the number of messages left in the
0257  *          queue (after this read) in the integer the second argument points
0258  *          to.
0259  */
0260 CURL_EXTERN CURLMsg *curl_multi_info_read(CURLM *multi_handle,
0261                                           int *msgs_in_queue);
0262 
0263 /*
0264  * Name:    curl_multi_strerror()
0265  *
0266  * Desc:    The curl_multi_strerror function may be used to turn a CURLMcode
0267  *          value into the equivalent human readable error string. This is
0268  *          useful for printing meaningful error messages.
0269  *
0270  * Returns: A pointer to a null-terminated error message.
0271  */
0272 CURL_EXTERN const char *curl_multi_strerror(CURLMcode);
0273 
0274 /*
0275  * Name:    curl_multi_socket() and
0276  *          curl_multi_socket_all()
0277  *
0278  * Desc:    An alternative version of curl_multi_perform() that allows the
0279  *          application to pass in one of the file descriptors that have been
0280  *          detected to have "action" on them and let libcurl perform.
0281  *          See manpage for details.
0282  */
0283 #define CURL_POLL_NONE   0
0284 #define CURL_POLL_IN     1
0285 #define CURL_POLL_OUT    2
0286 #define CURL_POLL_INOUT  3
0287 #define CURL_POLL_REMOVE 4
0288 
0289 #define CURL_SOCKET_TIMEOUT CURL_SOCKET_BAD
0290 
0291 #define CURL_CSELECT_IN   0x01
0292 #define CURL_CSELECT_OUT  0x02
0293 #define CURL_CSELECT_ERR  0x04
0294 
0295 typedef int (*curl_socket_callback)(CURL *easy,      /* easy handle */
0296                                     curl_socket_t s, /* socket */
0297                                     int what,        /* see above */
0298                                     void *userp,     /* private callback
0299                                                         pointer */
0300                                     void *socketp);  /* private socket
0301                                                         pointer */
0302 /*
0303  * Name:    curl_multi_timer_callback
0304  *
0305  * Desc:    Called by libcurl whenever the library detects a change in the
0306  *          maximum number of milliseconds the app is allowed to wait before
0307  *          curl_multi_socket() or curl_multi_perform() must be called
0308  *          (to allow libcurl's timed events to take place).
0309  *
0310  * Returns: The callback should return zero.
0311  */
0312 typedef int (*curl_multi_timer_callback)(CURLM *multi,    /* multi handle */
0313                                          long timeout_ms, /* see above */
0314                                          void *userp);    /* private callback
0315                                                              pointer */
0316 
0317 CURL_EXTERN CURLMcode CURL_DEPRECATED(7.19.5, "Use curl_multi_socket_action()")
0318 curl_multi_socket(CURLM *multi_handle, curl_socket_t s, int *running_handles);
0319 
0320 CURL_EXTERN CURLMcode curl_multi_socket_action(CURLM *multi_handle,
0321                                                curl_socket_t s,
0322                                                int ev_bitmask,
0323                                                int *running_handles);
0324 
0325 CURL_EXTERN CURLMcode CURL_DEPRECATED(7.19.5, "Use curl_multi_socket_action()")
0326 curl_multi_socket_all(CURLM *multi_handle, int *running_handles);
0327 
0328 #ifndef CURL_ALLOW_OLD_MULTI_SOCKET
0329 /* This macro below was added in 7.16.3 to push users who recompile to use
0330    the new curl_multi_socket_action() instead of the old curl_multi_socket()
0331 */
0332 #define curl_multi_socket(x,y,z) curl_multi_socket_action(x,y,0,z)
0333 #endif
0334 
0335 /*
0336  * Name:    curl_multi_timeout()
0337  *
0338  * Desc:    Returns the maximum number of milliseconds the app is allowed to
0339  *          wait before curl_multi_socket() or curl_multi_perform() must be
0340  *          called (to allow libcurl's timed events to take place).
0341  *
0342  * Returns: CURLM error code.
0343  */
0344 CURL_EXTERN CURLMcode curl_multi_timeout(CURLM *multi_handle,
0345                                          long *milliseconds);
0346 
0347 typedef enum {
0348   /* This is the socket callback function pointer */
0349   CURLOPT(CURLMOPT_SOCKETFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 1),
0350 
0351   /* This is the argument passed to the socket callback */
0352   CURLOPT(CURLMOPT_SOCKETDATA, CURLOPTTYPE_OBJECTPOINT, 2),
0353 
0354     /* set to 1 to enable pipelining for this multi handle */
0355   CURLOPT(CURLMOPT_PIPELINING, CURLOPTTYPE_LONG, 3),
0356 
0357    /* This is the timer callback function pointer */
0358   CURLOPT(CURLMOPT_TIMERFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 4),
0359 
0360   /* This is the argument passed to the timer callback */
0361   CURLOPT(CURLMOPT_TIMERDATA, CURLOPTTYPE_OBJECTPOINT, 5),
0362 
0363   /* maximum number of entries in the connection cache */
0364   CURLOPT(CURLMOPT_MAXCONNECTS, CURLOPTTYPE_LONG, 6),
0365 
0366   /* maximum number of (pipelining) connections to one host */
0367   CURLOPT(CURLMOPT_MAX_HOST_CONNECTIONS, CURLOPTTYPE_LONG, 7),
0368 
0369   /* maximum number of requests in a pipeline */
0370   CURLOPT(CURLMOPT_MAX_PIPELINE_LENGTH, CURLOPTTYPE_LONG, 8),
0371 
0372   /* a connection with a content-length longer than this
0373      will not be considered for pipelining */
0374   CURLOPT(CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE, CURLOPTTYPE_OFF_T, 9),
0375 
0376   /* a connection with a chunk length longer than this
0377      will not be considered for pipelining */
0378   CURLOPT(CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE, CURLOPTTYPE_OFF_T, 10),
0379 
0380   /* a list of site names(+port) that are blocked from pipelining */
0381   CURLOPT(CURLMOPT_PIPELINING_SITE_BL, CURLOPTTYPE_OBJECTPOINT, 11),
0382 
0383   /* a list of server types that are blocked from pipelining */
0384   CURLOPT(CURLMOPT_PIPELINING_SERVER_BL, CURLOPTTYPE_OBJECTPOINT, 12),
0385 
0386   /* maximum number of open connections in total */
0387   CURLOPT(CURLMOPT_MAX_TOTAL_CONNECTIONS, CURLOPTTYPE_LONG, 13),
0388 
0389    /* This is the server push callback function pointer */
0390   CURLOPT(CURLMOPT_PUSHFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 14),
0391 
0392   /* This is the argument passed to the server push callback */
0393   CURLOPT(CURLMOPT_PUSHDATA, CURLOPTTYPE_OBJECTPOINT, 15),
0394 
0395   /* maximum number of concurrent streams to support on a connection */
0396   CURLOPT(CURLMOPT_MAX_CONCURRENT_STREAMS, CURLOPTTYPE_LONG, 16),
0397 
0398   CURLMOPT_LASTENTRY /* the last unused */
0399 } CURLMoption;
0400 
0401 
0402 /*
0403  * Name:    curl_multi_setopt()
0404  *
0405  * Desc:    Sets options for the multi handle.
0406  *
0407  * Returns: CURLM error code.
0408  */
0409 CURL_EXTERN CURLMcode curl_multi_setopt(CURLM *multi_handle,
0410                                         CURLMoption option, ...);
0411 
0412 
0413 /*
0414  * Name:    curl_multi_assign()
0415  *
0416  * Desc:    This function sets an association in the multi handle between the
0417  *          given socket and a private pointer of the application. This is
0418  *          (only) useful for curl_multi_socket uses.
0419  *
0420  * Returns: CURLM error code.
0421  */
0422 CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle,
0423                                         curl_socket_t sockfd, void *sockp);
0424 
0425 /*
0426  * Name:    curl_multi_get_handles()
0427  *
0428  * Desc:    Returns an allocated array holding all handles currently added to
0429  *          the multi handle. Marks the final entry with a NULL pointer. If
0430  *          there is no easy handle added to the multi handle, this function
0431  *          returns an array with the first entry as a NULL pointer.
0432  *
0433  * Returns: NULL on failure, otherwise a CURL **array pointer
0434  */
0435 CURL_EXTERN CURL **curl_multi_get_handles(CURLM *multi_handle);
0436 
0437 /*
0438  * Name: curl_push_callback
0439  *
0440  * Desc: This callback gets called when a new stream is being pushed by the
0441  *       server. It approves or denies the new stream. It can also decide
0442  *       to completely fail the connection.
0443  *
0444  * Returns: CURL_PUSH_OK, CURL_PUSH_DENY or CURL_PUSH_ERROROUT
0445  */
0446 #define CURL_PUSH_OK       0
0447 #define CURL_PUSH_DENY     1
0448 #define CURL_PUSH_ERROROUT 2 /* added in 7.72.0 */
0449 
0450 struct curl_pushheaders;  /* forward declaration only */
0451 
0452 CURL_EXTERN char *curl_pushheader_bynum(struct curl_pushheaders *h,
0453                                         size_t num);
0454 CURL_EXTERN char *curl_pushheader_byname(struct curl_pushheaders *h,
0455                                          const char *name);
0456 
0457 typedef int (*curl_push_callback)(CURL *parent,
0458                                   CURL *easy,
0459                                   size_t num_headers,
0460                                   struct curl_pushheaders *headers,
0461                                   void *userp);
0462 
0463 /*
0464  * Name:    curl_multi_waitfds()
0465  *
0466  * Desc:    Ask curl for fds for polling. The app can use these to poll on.
0467  *          We want curl_multi_perform() called as soon as one of them are
0468  *          ready. Passing zero size allows to get just a number of fds.
0469  *
0470  * Returns: CURLMcode type, general multi error code.
0471  */
0472 CURL_EXTERN CURLMcode curl_multi_waitfds(CURLM *multi,
0473                                          struct curl_waitfd *ufds,
0474                                          unsigned int size,
0475                                          unsigned int *fd_count);
0476 
0477 #ifdef __cplusplus
0478 } /* end of extern "C" */
0479 #endif
0480 
0481 #endif