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.
 
 
 
 
 
 

82 lines
2.1 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. #define CPPCMS_SOURCE
  9. #include "session_tcp_storage.h"
  10. #include "tcp_messenger.h"
  11. #include <cppcms/session_sid.h>
  12. #include <stdio.h>
  13. #include <time.h>
  14. namespace cppcms {
  15. namespace sessions {
  16. using namespace cppcms::impl;
  17. class sessions_tcp_connector : public cppcms::impl::tcp_connector {
  18. public:
  19. sessions_tcp_connector(std::vector<std::string> const &ips,std::vector<int> const &ports) :
  20. cppcms::impl::tcp_connector(ips,ports)
  21. {
  22. }
  23. };
  24. bool tcp_storage::is_blocking()
  25. {
  26. return true;
  27. }
  28. void tcp_storage::save(std::string const &sid,time_t timeout,std::string const &in)
  29. {
  30. tcp_operation_header h=tcp_operation_header();
  31. h.opcode=opcodes::session_save;
  32. h.size=in.size() + 32;
  33. h.operations.session_save.timeout=timeout;
  34. std::string data;
  35. data.reserve(sid.size() + in.size());
  36. data+=sid;
  37. data+=in;
  38. tcp().get(sid).transmit(h,data);
  39. }
  40. bool tcp_storage::load(std::string const &sid,time_t &timeout,std::string &out)
  41. {
  42. tcp_operation_header h=tcp_operation_header();
  43. h.opcode=opcodes::session_load;
  44. h.size=sid.size();
  45. std::string data=sid;
  46. tcp().get(sid).transmit(h,data);
  47. if(h.opcode==opcodes::session_load_data) {
  48. timeout = to_time_t(h.operations.session_data.timeout);
  49. out.swap(data);
  50. return true;
  51. }
  52. else {
  53. return false;
  54. }
  55. }
  56. void tcp_storage::remove(std::string const &sid)
  57. {
  58. tcp_operation_header h=tcp_operation_header();
  59. h.opcode=opcodes::session_remove;
  60. h.size=sid.size();
  61. std::string data=sid;
  62. tcp().get(sid).transmit(h,data);
  63. }
  64. tcp_connector &tcp_storage::tcp()
  65. {
  66. tcp_connector *p = tcp_.get();
  67. if(!p) {
  68. p=new sessions_tcp_connector(ips_,ports_);
  69. tcp_.reset(p);
  70. }
  71. return *p;
  72. }
  73. } // sessions
  74. } // cppcms