Commit 35f61c40 authored by Alejandro Alvarez Ayllon's avatar Alejandro Alvarez Ayllon Committed by Daniel Stenberg
Browse files

SSL session share: move the age counter to the share object

Previously the age counter would be counted individually in each easy
handle that shared SSL sessions!
parent 97b73fec
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...)
        share->nsslsession = 8;
        share->sslsession = calloc(share->nsslsession,
                                   sizeof(struct curl_ssl_session));
        share->sessionage = 0;
        if(!share->sslsession)
          return CURLSHE_NOMEM;
      }
+1 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ struct Curl_share {

  struct curl_ssl_session *sslsession;
  unsigned int nsslsession;
  long sessionage;
};

CURLSHcode Curl_share_lock (struct SessionHandle *, curl_lock_data,
+16 −5
Original line number Diff line number Diff line
@@ -232,14 +232,19 @@ int Curl_ssl_getsessionid(struct connectdata *conn,
  struct curl_ssl_session *check;
  struct SessionHandle *data = conn->data;
  long i;
  long *general_age;

  if(!conn->ssl_config.sessionid)
    /* session ID re-use is disabled */
    return TRUE;

  /* Lock for reading if shared */
  if(data->share && data->share->sslsession == data->state.session)
  if(data->share && data->share->sslsession == data->state.session) {
    Curl_share_lock(data, CURL_LOCK_DATA_SSL_SESSION, CURL_LOCK_ACCESS_SHARED);
    general_age = &data->share->sessionage;
  }
  else
    general_age = &data->state.sessionage;

  for(i=0; i< data->set.ssl.numsessions; i++) {
    check = &data->state.session[i];
@@ -250,8 +255,8 @@ int Curl_ssl_getsessionid(struct connectdata *conn,
       (conn->remote_port == check->remote_port) &&
       Curl_ssl_config_matches(&conn->ssl_config, &check->ssl_config)) {
      /* yes, we have a session ID! */
      data->state.sessionage++;            /* increase general age */
      check->age = data->state.sessionage; /* set this as used in this age */
      *general_age++;            /* increase general age */
      check->age = *general_age; /* set this as used in this age */
      *ssl_sessionid = check->sessionid;
      if(idsize)
        *idsize = check->idsize;
@@ -333,6 +338,7 @@ CURLcode Curl_ssl_addsessionid(struct connectdata *conn,
  struct curl_ssl_session *store = &data->state.session[0];
  long oldest_age=data->state.session[0].age; /* zero if unused */
  char *clone_host;
  long *general_age;

  /* Even though session ID re-use might be disabled, that only disables USING
     IT. We still store it here in case the re-using is again enabled for an
@@ -346,8 +352,13 @@ CURLcode Curl_ssl_addsessionid(struct connectdata *conn,
     the oldest if necessary) */

  /* If using shared SSL session, lock! */
  if(data->share && data->share->sslsession == data->state.session)
  if(data->share && data->share->sslsession == data->state.session) {
    Curl_share_lock(data, CURL_LOCK_DATA_SSL_SESSION, CURL_LOCK_ACCESS_SINGLE);
    general_age = &data->share->sessionage;
  }
  else {
    general_age = &data->state.sessionage;
  }

  /* find an empty slot for us, or find the oldest */
  for(i=1; (i<data->set.ssl.numsessions) &&
@@ -366,7 +377,7 @@ CURLcode Curl_ssl_addsessionid(struct connectdata *conn,
  /* now init the session struct wisely */
  store->sessionid = ssl_sessionid;
  store->idsize = idsize;
  store->age = data->state.sessionage;    /* set current age */
  store->age = *general_age;    /* set current age */
  if(store->name)
    /* free it if there's one already present */
    free(store->name);