From 13f286925b1e9e34fe71413edcba23686c005f8a Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 25 Jan 2011 12:17:47 +0000 Subject: New database layout. --- server/src/session.cc | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) (limited to 'server/src/session.cc') diff --git a/server/src/session.cc b/server/src/session.cc index 5fe9230..612f264 100644 --- a/server/src/session.cc +++ b/server/src/session.cc @@ -46,9 +46,9 @@ Session::Session(std::string sessionid) { - _id = sessionid; _journal = NULL; _database = NULL; + database()->setSessionId(sessionid); } Session::~Session() @@ -59,7 +59,7 @@ Session::~Session() std::string Session::id() { - return _id; + return database()->sessionId(); } void Session::lock() @@ -86,6 +86,13 @@ void Session::commit() } } +void Session::nocommit() +{ + if(_database != NULL) { + _database->nocommit(); + } +} + void Session::discard() { if(_journal) { @@ -127,13 +134,6 @@ static bool fexists(const std::string &f) { bool ret; -/* - struct stat sbuf; - int n = stat(f.c_str(), &sbuf); - if(n != -1) ret = true; - ret = errno != ENOENT; -*/ - FILE *fp = fopen(f.c_str(), "r"); ret = fp != NULL; if(fp) fclose(fp); @@ -143,14 +143,7 @@ static bool fexists(const std::string &f) Session *Sessions::newSession() { - char sessionid[32]; - std::string filename; - do { - snprintf(sessionid, sizeof(sessionid)-1, "%d", rand()); - filename = getSessionFilename(Conf::session_path, sessionid); - } while(sessions.find(sessionid) != sessions.end() || fexists(filename)); - - Session *session = new Session(sessionid); + Session *session = new Session(); sessions[session->id()] = session; return session; } @@ -162,13 +155,9 @@ Session *Sessions::session(std::string sessionid) std::string filename = getSessionFilename(Conf::session_path, sessionid); if(fexists(filename)) { - Session *s = new Session(sessionid); - SessionSerialiser ser(Conf::session_path, s); - ser.load(); + SessionSerialiser ser(Conf::session_path); + Session *s = ser.load(sessionid); sessions[s->id()] = s; - - fprintf(stderr, "s: %p\n",s); - return s; } @@ -177,6 +166,8 @@ Session *Sessions::session(std::string sessionid) Session *Sessions::takeSession(std::string sessionid) { + DEBUG(session,"%s\n", sessionid.c_str()); + Session *s = NULL; if(sessions.find(sessionid) != sessions.end()) { s = sessions[sessionid]; @@ -185,6 +176,7 @@ Session *Sessions::takeSession(std::string sessionid) if(s) { sessions.erase(sessionid); } + else DEBUG(session, "No such session!\n"); return s; } @@ -204,8 +196,8 @@ void Sessions::store() { std::map::iterator i = sessions.begin(); while(i != sessions.end()) { - SessionSerialiser ser(Conf::session_path, i->second); - ser.save(); + SessionSerialiser ser(Conf::session_path); + ser.save(i->second); delete i->second; sessions.erase(i); i++; -- cgit v1.2.3