1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-22 08:08:50 -05:00

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!
This commit is contained in:
Alejandro Alvarez Ayllon 2011-11-17 23:34:38 +01:00 committed by Daniel Stenberg
parent 97b73fec7a
commit 35f61c404d
3 changed files with 18 additions and 5 deletions

View File

@ -91,6 +91,7 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...)
share->nsslsession = 8; share->nsslsession = 8;
share->sslsession = calloc(share->nsslsession, share->sslsession = calloc(share->nsslsession,
sizeof(struct curl_ssl_session)); sizeof(struct curl_ssl_session));
share->sessionage = 0;
if(!share->sslsession) if(!share->sslsession)
return CURLSHE_NOMEM; return CURLSHE_NOMEM;
} }

View File

@ -52,6 +52,7 @@ struct Curl_share {
struct curl_ssl_session *sslsession; struct curl_ssl_session *sslsession;
unsigned int nsslsession; unsigned int nsslsession;
long sessionage;
}; };
CURLSHcode Curl_share_lock (struct SessionHandle *, curl_lock_data, CURLSHcode Curl_share_lock (struct SessionHandle *, curl_lock_data,

View File

@ -232,14 +232,19 @@ int Curl_ssl_getsessionid(struct connectdata *conn,
struct curl_ssl_session *check; struct curl_ssl_session *check;
struct SessionHandle *data = conn->data; struct SessionHandle *data = conn->data;
long i; long i;
long *general_age;
if(!conn->ssl_config.sessionid) if(!conn->ssl_config.sessionid)
/* session ID re-use is disabled */ /* session ID re-use is disabled */
return TRUE; return TRUE;
/* Lock for reading if shared */ /* 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); 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++) { for(i=0; i< data->set.ssl.numsessions; i++) {
check = &data->state.session[i]; check = &data->state.session[i];
@ -250,8 +255,8 @@ int Curl_ssl_getsessionid(struct connectdata *conn,
(conn->remote_port == check->remote_port) && (conn->remote_port == check->remote_port) &&
Curl_ssl_config_matches(&conn->ssl_config, &check->ssl_config)) { Curl_ssl_config_matches(&conn->ssl_config, &check->ssl_config)) {
/* yes, we have a session ID! */ /* yes, we have a session ID! */
data->state.sessionage++; /* increase general age */ *general_age++; /* increase general age */
check->age = data->state.sessionage; /* set this as used in this age */ check->age = *general_age; /* set this as used in this age */
*ssl_sessionid = check->sessionid; *ssl_sessionid = check->sessionid;
if(idsize) if(idsize)
*idsize = check->idsize; *idsize = check->idsize;
@ -333,6 +338,7 @@ CURLcode Curl_ssl_addsessionid(struct connectdata *conn,
struct curl_ssl_session *store = &data->state.session[0]; struct curl_ssl_session *store = &data->state.session[0];
long oldest_age=data->state.session[0].age; /* zero if unused */ long oldest_age=data->state.session[0].age; /* zero if unused */
char *clone_host; char *clone_host;
long *general_age;
/* Even though session ID re-use might be disabled, that only disables USING /* 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 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) */ the oldest if necessary) */
/* If using shared SSL session, lock! */ /* 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); 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 */ /* find an empty slot for us, or find the oldest */
for(i=1; (i<data->set.ssl.numsessions) && 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 */ /* now init the session struct wisely */
store->sessionid = ssl_sessionid; store->sessionid = ssl_sessionid;
store->idsize = idsize; store->idsize = idsize;
store->age = data->state.sessionage; /* set current age */ store->age = *general_age; /* set current age */
if(store->name) if(store->name)
/* free it if there's one already present */ /* free it if there's one already present */
free(store->name); free(store->name);