pike.git / lib / modules / Protocols.pmod / HTTP.pmod / Session.pike

version» Context lines:

pike.git/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:1:   #pike __REAL_VERSION__    - // $Id: Session.pike,v 1.14 2004/01/11 00:49:02 nilsson Exp $ + // $Id$      import Protocols.HTTP;      typedef string|Standards.URI|SessionURL URL;      //! The number of redirects to follow, if any.   //! This is the default to the created Request objects.   //!   //! A redirect automatically turns into a GET request,   //! and all header, query, post or put information is dropped.
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:594:   //! (live connections + kept-alive connections <= this number)   //! Defaults to 50 connections.   int maximum_total_connections=50;      //! Maximum times a connection is reused.   //! Defaults to 1000000. <2 means no reuse at all.   int maximum_connection_reuse=1000000;      // internal (but readable for debug purposes)   mapping(string:array(KeptConnection)) connection_cache=([]); + Thread.Mutex connection_cache_mux = Thread.Mutex();   int connections_kept_n=0;   int connections_inuse_n=0;   mapping(string:int) connections_host_n=([]);      static class KeptConnection   {    string lookup;    Query q;       void create(string _lookup,Query _q)    { -  +  Thread.MutexKey key = connection_cache_mux->lock(2);    lookup=_lookup;    q=_q;       call_out(disconnect,time_to_keep_unused_connections);    connection_cache[lookup]=    (connection_cache[lookup]||({}))+({this});    connections_kept_n++;    }       void disconnect()    { -  +  Thread.MutexKey key = connection_cache_mux->lock(2);    connection_cache[lookup]-=({this});    if (!sizeof(connection_cache[lookup]))    m_delete(connection_cache,lookup);    remove_call_out(disconnect); // if called externally       if (q->con) destruct(q->con);    connections_kept_n--;    if (!--connections_host_n[lookup])    m_delete(connections_host_n,lookup);    destruct(q);    destruct(this);    }       Query use()    { -  +  Thread.MutexKey key = connection_cache_mux->lock(2);    connection_cache[lookup]-=({this});    if (!sizeof(connection_cache[lookup]))    m_delete(connection_cache,lookup);    remove_call_out(disconnect);       connections_kept_n--;    return q; // subsequently, this object is removed (no refs)    }   }   
pike.git/lib/modules/Protocols.pmod/HTTP.pmod/Session.pike:653:    return url->scheme+"://"+url->host+":"+url->port;   }      //! Request a @[Query] object suitable to use for the   //! given URL. This may be a reused object from a keep-alive   //! connection.   Query give_me_connection(Standards.URI url)   {    Query q;    +  Thread.MutexKey key = connection_cache_mux->lock(); +     if (array(KeptConnection) v =    connection_cache[connection_lookup(url)])    {    q=v[0]->use(); // removes itself    // clean up    q->buf="";    q->headerbuf="";    q->n_used++;    }    else