SessionPtr SessionManager::openSession(WebContext &ctx, const string &_id) { string id = _id; if (id.empty()) id = generateSessionID(ctx); SmartLock lock(this); // Get the session SessionPtr session; sessions_t::iterator it = sessions.find(id); if (it != sessions.end()) session = it->second; if (session.isNull()) { session = factory->createSession(id); sessions.insert(sessions_t::value_type(id, session)); } // Set IP IPAddress ip = ctx.getClientIP(); ip.setPort(0); session->setIP(ip); session->touch(); // Update timestamp ctx.setSession(session); dirty = true; return session; }