File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / curl / lib / conncache.h
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Jun 3 10:01:15 2020 UTC (5 years ago) by misho
Branches: curl, MAIN
CVS tags: v7_70_0p4, HEAD
curl

    1: #ifndef HEADER_CURL_CONNCACHE_H
    2: #define HEADER_CURL_CONNCACHE_H
    3: /***************************************************************************
    4:  *                                  _   _ ____  _
    5:  *  Project                     ___| | | |  _ \| |
    6:  *                             / __| | | | |_) | |
    7:  *                            | (__| |_| |  _ <| |___
    8:  *                             \___|\___/|_| \_\_____|
    9:  *
   10:  * Copyright (C) 2015 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
   11:  * Copyright (C) 2012 - 2014, Linus Nielsen Feltzing, <linus@haxx.se>
   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.haxx.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:  ***************************************************************************/
   25: 
   26: /*
   27:  * All accesses to struct fields and changing of data in the connection cache
   28:  * and connectbundles must be done with the conncache LOCKED. The cache might
   29:  * be shared.
   30:  */
   31: 
   32: struct conncache {
   33:   struct curl_hash hash;
   34:   size_t num_conn;
   35:   long next_connection_id;
   36:   struct curltime last_cleanup;
   37:   /* handle used for closing cached connections */
   38:   struct Curl_easy *closure_handle;
   39: };
   40: 
   41: #define BUNDLE_NO_MULTIUSE -1
   42: #define BUNDLE_UNKNOWN     0  /* initial value */
   43: #define BUNDLE_MULTIPLEX   2
   44: 
   45: #ifdef CURLDEBUG
   46: /* the debug versions of these macros make extra certain that the lock is
   47:    never doubly locked or unlocked */
   48: #define CONN_LOCK(x) if((x)->share) {                                   \
   49:     Curl_share_lock((x), CURL_LOCK_DATA_CONNECT, CURL_LOCK_ACCESS_SINGLE); \
   50:     DEBUGASSERT(!(x)->state.conncache_lock);                            \
   51:     (x)->state.conncache_lock = TRUE;                                   \
   52:   }
   53: 
   54: #define CONN_UNLOCK(x) if((x)->share) {                                 \
   55:     DEBUGASSERT((x)->state.conncache_lock);                             \
   56:     (x)->state.conncache_lock = FALSE;                                  \
   57:     Curl_share_unlock((x), CURL_LOCK_DATA_CONNECT);                     \
   58:   }
   59: #else
   60: #define CONN_LOCK(x) if((x)->share)                                     \
   61:     Curl_share_lock((x), CURL_LOCK_DATA_CONNECT, CURL_LOCK_ACCESS_SINGLE)
   62: #define CONN_UNLOCK(x) if((x)->share)                   \
   63:     Curl_share_unlock((x), CURL_LOCK_DATA_CONNECT)
   64: #endif
   65: 
   66: struct connectbundle {
   67:   int multiuse;                 /* supports multi-use */
   68:   size_t num_connections;       /* Number of connections in the bundle */
   69:   struct curl_llist conn_list;  /* The connectdata members of the bundle */
   70: };
   71: 
   72: /* returns 1 on error, 0 is fine */
   73: int Curl_conncache_init(struct conncache *, int size);
   74: void Curl_conncache_destroy(struct conncache *connc);
   75: 
   76: /* return the correct bundle, to a host or a proxy */
   77: struct connectbundle *Curl_conncache_find_bundle(struct connectdata *conn,
   78:                                                  struct conncache *connc,
   79:                                                  const char **hostp);
   80: void Curl_conncache_unlock(struct Curl_easy *data);
   81: /* returns number of connections currently held in the connection cache */
   82: size_t Curl_conncache_size(struct Curl_easy *data);
   83: 
   84: bool Curl_conncache_return_conn(struct Curl_easy *data,
   85:                                 struct connectdata *conn);
   86: CURLcode Curl_conncache_add_conn(struct conncache *connc,
   87:                                  struct connectdata *conn) WARN_UNUSED_RESULT;
   88: void Curl_conncache_remove_conn(struct Curl_easy *data,
   89:                                 struct connectdata *conn,
   90:                                 bool lock);
   91: bool Curl_conncache_foreach(struct Curl_easy *data,
   92:                             struct conncache *connc,
   93:                             void *param,
   94:                             int (*func)(struct connectdata *conn,
   95:                                         void *param));
   96: 
   97: struct connectdata *
   98: Curl_conncache_find_first_connection(struct conncache *connc);
   99: 
  100: struct connectdata *
  101: Curl_conncache_extract_bundle(struct Curl_easy *data,
  102:                               struct connectbundle *bundle);
  103: struct connectdata *
  104: Curl_conncache_extract_oldest(struct Curl_easy *data);
  105: void Curl_conncache_close_all_connections(struct conncache *connc);
  106: void Curl_conncache_print(struct conncache *connc);
  107: 
  108: #endif /* HEADER_CURL_CONNCACHE_H */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>