ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

76 lines
2.4 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
  4. //
  5. // See accompanying file COPYING.TXT file for licensing details.
  6. //
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #ifndef CPPCMS_SESSION_POSIX_FILE_STORAGE_H
  9. #define CPPCMS_SESSION_POSIX_FILE_STORAGE_H
  10. #include <cppcms/defs.h>
  11. #include <cppcms/session_storage.h>
  12. #include <booster/hold_ptr.h>
  13. #include <pthread.h>
  14. #include <vector>
  15. namespace cppcms {
  16. namespace sessions {
  17. class session_file_storage_factory;
  18. class CPPCMS_API session_file_storage : public session_storage {
  19. public:
  20. session_file_storage(std::string path,int concurrency_hint,int procs_no,bool force_flock);
  21. virtual ~session_file_storage();
  22. virtual void save(std::string const &sid,time_t timeout,std::string const &in);
  23. virtual bool load(std::string const &sid,time_t &timeout,std::string &out);
  24. virtual void remove(std::string const &sid);
  25. virtual bool is_blocking();
  26. private:
  27. class locked_file;
  28. struct _data;
  29. bool read_timestamp(int fd);
  30. bool read_from_file(int fd,time_t &timeout,std::string &data);
  31. void save_to_file(int fd,time_t timeout,std::string const &in);
  32. bool read_all(int fd,void *vbuf,int n);
  33. bool write_all(int fd,void const *vbuf,int n);
  34. void gc();
  35. std::string file_name(std::string const &sid);
  36. pthread_mutex_t *sid_to_pos(std::string const &sid);
  37. void lock(std::string const &sid);
  38. void unlock(std::string const &sid);
  39. // members
  40. booster::hold_ptr<_data> d;
  41. void *memory_;
  42. std::string path_;
  43. unsigned lock_size_;
  44. bool file_lock_;
  45. pthread_mutex_t *locks_;
  46. std::vector<pthread_mutex_t> mutexes_;
  47. // friends
  48. friend class locked_file;
  49. friend class session_file_storage_factory;
  50. };
  51. class CPPCMS_API session_file_storage_factory : public session_storage_factory {
  52. public:
  53. session_file_storage_factory(std::string path,int conc,int proc_no,bool force_lock);
  54. virtual booster::shared_ptr<session_storage> get();
  55. virtual bool requires_gc();
  56. virtual void gc_job();
  57. virtual ~session_file_storage_factory();
  58. private:
  59. struct _data;
  60. booster::shared_ptr<session_file_storage> storage_;
  61. };
  62. } // sessions
  63. } // cppcms
  64. #endif