fastcgi++
A C++ FastCGI/Web API
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Fastcgipp::Http::Sessions< T > Class Template Reference

Container for HTTP sessions. More...

#include <fastcgi++/http.hpp>

Public Member Functions

 Sessions (unsigned int keepAlive)
 Constructor takes session keep alive times. More...
 
std::shared_ptr< const T > get (const SessionId &id)
 Get session data from session ID. More...
 
size_t size () const
 How many active sessions are there? More...
 
SessionId generate (const std::shared_ptr< const T > &data)
 Generates a new session. More...
 
void erase (const SessionId &id)
 Erase a session. More...
 
const char * expiration () const
 Expiration string for setting cookies. More...
 

Private Member Functions

void setExpiration ()
 Internal helper for building the m_expiration string. More...
 

Private Attributes

const unsigned int m_keepAlive
 Amount of seconds to keep sessions around for. More...
 
std::time_t m_cleanupTime
 The time that the next session cleanup should be done. More...
 
std::map< SessionId, std::shared_ptr< const T > > m_sessions
 Actual container of sessions. More...
 
std::mutex m_mutex
 Thread safe all operations. More...
 
char m_expiration [2][expirationLength]
 Internal string for cookie expirations. More...
 
std::atomic< const char * > m_expirationPtr
 Point for the current expiration string. More...
 

Static Private Attributes

static const size_t expirationLength = 30
 Length of expiration string (with null terminator) More...
 

Detailed Description

template<class T>
class Fastcgipp::Http::Sessions< T >

Container for HTTP sessions.

In many ways this class behaves like an std::map. Additions include a mechanism for clearing out expired sessions based on a keep alive time and a frequency of deletion, and full thread safety. Basically it contains all session data and associates it with ID values.

Session data is only available as constant in order to ensure thread safety when accessing the data. It is not only possible, but very probable, that multiple requests/threads will be accessing the same session data simultaneously.

Template Parameters
TClass containing session data.
Date
May 26, 2016
Author
Eddie Carle <eddie.nosp@m.@isa.nosp@m.tec.c.nosp@m.a>

Definition at line 641 of file http.hpp.

Constructor & Destructor Documentation

template<class T >
Fastcgipp::Http::Sessions< T >::Sessions ( unsigned int  keepAlive)
inline

Constructor takes session keep alive times.

Parameters
[in]keepAliveAmount of seconds a session will stay alive for.

Definition at line 674 of file http.hpp.

Member Function Documentation

template<class T >
void Fastcgipp::Http::Sessions< T >::erase ( const SessionId id)
inline

Erase a session.

Parameters
[in]idThe session we want to erase.

Definition at line 709 of file http.hpp.

template<class T >
const char* Fastcgipp::Http::Sessions< T >::expiration ( ) const
inline

Expiration string for setting cookies.

Definition at line 716 of file http.hpp.

template<class T >
Fastcgipp::Http::SessionId Fastcgipp::Http::Sessions< T >::generate ( const std::shared_ptr< const T > &  data)

Generates a new session.

Parameters
[in]dataData to store in the session.
Returns
A session ID for the session. This is not a reference for thread safety purposes.

Definition at line 803 of file http.hpp.

template<class T >
std::shared_ptr< const T > Fastcgipp::Http::Sessions< T >::get ( const SessionId id)

Get session data from session ID.

Parameters
[in]idThe session ID we are looking for.
Returns
Shared pointer to session data. The pointer will evaluate to false if the session does not actually exist.

Definition at line 819 of file http.hpp.

template<class T >
void Fastcgipp::Http::Sessions< T >::setExpiration ( )
private

Internal helper for building the m_expiration string.

Definition at line 854 of file http.hpp.

template<class T >
size_t Fastcgipp::Http::Sessions< T >::size ( ) const
inline

How many active sessions are there?

Definition at line 690 of file http.hpp.

Member Data Documentation

template<class T >
const size_t Fastcgipp::Http::Sessions< T >::expirationLength = 30
staticprivate

Length of expiration string (with null terminator)

Definition at line 657 of file http.hpp.

template<class T >
std::time_t Fastcgipp::Http::Sessions< T >::m_cleanupTime
private

The time that the next session cleanup should be done.

Definition at line 648 of file http.hpp.

template<class T >
char Fastcgipp::Http::Sessions< T >::m_expiration[2][expirationLength]
private

Internal string for cookie expirations.

Definition at line 660 of file http.hpp.

template<class T >
std::atomic<const char*> Fastcgipp::Http::Sessions< T >::m_expirationPtr
private

Point for the current expiration string.

Definition at line 663 of file http.hpp.

template<class T >
const unsigned int Fastcgipp::Http::Sessions< T >::m_keepAlive
private

Amount of seconds to keep sessions around for.

Definition at line 645 of file http.hpp.

template<class T >
std::mutex Fastcgipp::Http::Sessions< T >::m_mutex
mutableprivate

Thread safe all operations.

Definition at line 654 of file http.hpp.

template<class T >
std::map<SessionId, std::shared_ptr<const T> > Fastcgipp::Http::Sessions< T >::m_sessions
private

Actual container of sessions.

Definition at line 651 of file http.hpp.


The documentation for this class was generated from the following file: