|
fastcgi++
A C++ FastCGI/Web API
|
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... | |
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.
| T | Class containing session data. |
|
inline |
Constructor takes session keep alive times.
| [in] | keepAlive | Amount of seconds a session will stay alive for. |
Definition at line 674 of file http.hpp.
References Fastcgipp::Http::Sessions< T >::setExpiration().
|
inline |
Erase a session.
| [in] | id | The session we want to erase. |
Definition at line 709 of file http.hpp.
References Fastcgipp::Http::Sessions< T >::m_mutex, and Fastcgipp::Http::Sessions< T >::m_sessions.
|
inline |
Expiration string for setting cookies.
Definition at line 716 of file http.hpp.
References Fastcgipp::Http::Sessions< T >::m_expirationPtr.
| Fastcgipp::Http::SessionId Fastcgipp::Http::Sessions< T >::generate | ( | const std::shared_ptr< const T > & | data | ) |
| std::shared_ptr< const T > Fastcgipp::Http::Sessions< T >::get | ( | const SessionId & | id | ) |
|
private |
Internal helper for building the m_expiration string.
Definition at line 854 of file http.hpp.
Referenced by Fastcgipp::Http::Sessions< T >::Sessions().
|
inline |
How many active sessions are there?
Definition at line 690 of file http.hpp.
References Fastcgipp::Http::Sessions< T >::m_mutex, and Fastcgipp::Http::Sessions< T >::m_sessions.
|
staticprivate |
|
private |
|
private |
|
private |
Point for the current expiration string.
Definition at line 663 of file http.hpp.
Referenced by Fastcgipp::Http::Sessions< T >::expiration().
|
private |
|
mutableprivate |
Thread safe all operations.
Definition at line 654 of file http.hpp.
Referenced by Fastcgipp::Http::Sessions< T >::erase(), and Fastcgipp::Http::Sessions< T >::size().
|
private |
Actual container of sessions.
Definition at line 651 of file http.hpp.
Referenced by Fastcgipp::Http::Sessions< T >::erase(), and Fastcgipp::Http::Sessions< T >::size().
1.8.14