Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-11 08:38:54

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 man page 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   /* network has changed, adjust caches/connection reuse */
0399   CURLOPT(CURLMOPT_NETWORK_CHANGED, CURLOPTTYPE_LONG, 17),
0400 
0401   /* This is the notify callback function pointer */
0402   CURLOPT(CURLMOPT_NOTIFYFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 18),
0403 
0404   /* This is the argument passed to the notify callback */
0405   CURLOPT(CURLMOPT_NOTIFYDATA, CURLOPTTYPE_OBJECTPOINT, 19),
0406 
0407   CURLMOPT_LASTENTRY /* the last unused */
0408 } CURLMoption;
0409 
0410 /* Definition of bits for the CURLMOPT_NETWORK_CHANGED argument: */
0411 
0412 /* - CURLMNWC_CLEAR_CONNS tells libcurl to prevent further reuse of existing
0413    connections. Connections that are idle will be closed. Ongoing transfers
0414    will continue with the connection they have. */
0415 #define CURLMNWC_CLEAR_CONNS (1L << 0)
0416 
0417 /* - CURLMNWC_CLEAR_DNS tells libcurl to prevent further reuse of existing
0418    connections. Connections that are idle will be closed. Ongoing transfers
0419    will continue with the connection they have. */
0420 #define CURLMNWC_CLEAR_DNS (1L << 0)
0421 
0422 /*
0423  * Name:    curl_multi_setopt()
0424  *
0425  * Desc:    Sets options for the multi handle.
0426  *
0427  * Returns: CURLM error code.
0428  */
0429 CURL_EXTERN CURLMcode curl_multi_setopt(CURLM *multi_handle,
0430                                         CURLMoption option, ...);
0431 
0432 /*
0433  * Name:    curl_multi_assign()
0434  *
0435  * Desc:    This function sets an association in the multi handle between the
0436  *          given socket and a private pointer of the application. This is
0437  *          (only) useful for curl_multi_socket uses.
0438  *
0439  * Returns: CURLM error code.
0440  */
0441 CURL_EXTERN CURLMcode curl_multi_assign(CURLM *multi_handle,
0442                                         curl_socket_t sockfd, void *sockp);
0443 
0444 /*
0445  * Name:    curl_multi_get_handles()
0446  *
0447  * Desc:    Returns an allocated array holding all handles currently added to
0448  *          the multi handle. Marks the final entry with a NULL pointer. If
0449  *          there is no easy handle added to the multi handle, this function
0450  *          returns an array with the first entry as a NULL pointer.
0451  *
0452  * Returns: NULL on failure, otherwise a CURL **array pointer
0453  */
0454 CURL_EXTERN CURL **curl_multi_get_handles(CURLM *multi_handle);
0455 
0456 typedef enum {
0457   CURLMINFO_NONE, /* first, never use this */
0458   /* The number of easy handles currently managed by the multi handle,
0459    * e.g. have been added but not yet removed. */
0460   CURLMINFO_XFERS_CURRENT = 1,
0461   /* The number of easy handles running, e.g. not done and not queueing. */
0462   CURLMINFO_XFERS_RUNNING = 2,
0463   /* The number of easy handles waiting to start, e.g. for a connection
0464    * to become available due to limits on parallelism, max connections
0465    * or other factors. */
0466   CURLMINFO_XFERS_PENDING = 3,
0467   /* The number of easy handles finished, waiting for their results to
0468    * be read via `curl_multi_info_read()`. */
0469   CURLMINFO_XFERS_DONE = 4,
0470   /* The total number of easy handles added to the multi handle, ever. */
0471   CURLMINFO_XFERS_ADDED = 5,
0472 
0473   CURLMINFO_LASTENTRY /* the last unused */
0474 } CURLMinfo_offt;
0475 
0476 /*
0477  * Name:    curl_multi_get_offt()
0478  *
0479  * Desc:    Retrieves a numeric value for the `CURLMINFO_*` enums.
0480  *
0481  * Returns: CULRM_OK or error when value could not be obtained.
0482  */
0483 CURL_EXTERN CURLMcode curl_multi_get_offt(CURLM *multi_handle,
0484                                           CURLMinfo_offt info,
0485                                           curl_off_t *pvalue);
0486 
0487 /*
0488  * Name: curl_push_callback
0489  *
0490  * Desc: This callback gets called when a new stream is being pushed by the
0491  *       server. It approves or denies the new stream. It can also decide
0492  *       to completely fail the connection.
0493  *
0494  * Returns: CURL_PUSH_OK, CURL_PUSH_DENY or CURL_PUSH_ERROROUT
0495  */
0496 #define CURL_PUSH_OK       0
0497 #define CURL_PUSH_DENY     1
0498 #define CURL_PUSH_ERROROUT 2 /* added in 7.72.0 */
0499 
0500 struct curl_pushheaders;  /* forward declaration only */
0501 
0502 CURL_EXTERN char *curl_pushheader_bynum(struct curl_pushheaders *h,
0503                                         size_t num);
0504 CURL_EXTERN char *curl_pushheader_byname(struct curl_pushheaders *h,
0505                                          const char *name);
0506 
0507 typedef int (*curl_push_callback)(CURL *parent,
0508                                   CURL *easy,
0509                                   size_t num_headers,
0510                                   struct curl_pushheaders *headers,
0511                                   void *userp);
0512 
0513 /*
0514  * Name:    curl_multi_waitfds()
0515  *
0516  * Desc:    Ask curl for fds for polling. The app can use these to poll on.
0517  *          We want curl_multi_perform() called as soon as one of them are
0518  *          ready. Passing zero size allows to get just a number of fds.
0519  *
0520  * Returns: CURLMcode type, general multi error code.
0521  */
0522 CURL_EXTERN CURLMcode curl_multi_waitfds(CURLM *multi,
0523                                          struct curl_waitfd *ufds,
0524                                          unsigned int size,
0525                                          unsigned int *fd_count);
0526 
0527 /*
0528  * Notifications dispatched by a multi handle, when enabled.
0529  */
0530 #define CURLMNOTIFY_INFO_READ    0
0531 #define CURLMNOTIFY_EASY_DONE    1
0532 
0533 /*
0534  * Callback to install via CURLMOPT_NOTIFYFUNCTION.
0535  */
0536 typedef void (*curl_notify_callback)(CURLM *multi,
0537                                      unsigned int notification,
0538                                      CURL *easy,
0539                                      void *user_data);
0540 
0541 CURL_EXTERN CURLMcode curl_multi_notify_disable(CURLM *multi,
0542                                                 unsigned int notification);
0543 
0544 CURL_EXTERN CURLMcode curl_multi_notify_enable(CURLM *multi,
0545                                                unsigned int notification);
0546 
0547 #ifdef __cplusplus
0548 } /* end of extern "C" */
0549 #endif
0550 
0551 #endif