c++sessionasynchronouscppcms

cppcms session in async. mode


I use this code to run async. server:

int main(int argc, char ** argv)
{
  cppcms::service service(argc, argv);
  booster::intrusive_prt<gameServer> c = new gameServer(service);
  service.applications_pool().mount(c);
  service.run();
}

And in gameServer class I have this codes:

session().reset_session();
session()["username"] = "admin";
session().save();
...
if(!session().load())
  std::cerr<<" session doesn't load";

When I compile and run program, session doesn't load message shows. If I replace the main function with sync. server and remove session().load() and session().save(), there is no error and session["username"] can be shown.

Here is my configuration file

{
  ...
  "file_server" : { "enable" : true, "document_root" : "." },
  "session : 
  {
    "expire" : "browser",
    "timeout" : 604800,
    "location" : "server",
    "server" : { "storage" : "files" }
  }
}

What is wrong with my code?


Solution

  • The session().load() should be first statement in session handling of asynchronous applications

    You don't really need to check the status.

    After you change the session you call save.

    You don't call "load()" at the end