示例#1
0
void MemcachedSessionManager::update_session(Session &session)
{
    memcached_return rc;
    std::string const &sessionid = session.sessionid();
    std::ostringstream ss;
    save_pairs(ss, '\n', session.data());
    std::string value("userid="+std::to_string(session.user().id()));
    value += ss.str();
    rc = memcached_set(memcached_conn,
            sessionid.data(), sessionid.length(),
            value.data(), value.length(), 
            session_timeout(), 0);
    if (rc != MEMCACHED_SUCCESS)
        throw MemcacheError(memcached_conn, rc);
}
示例#2
0
static void dispatcher_loop()
{
	int numfds;
	fd_set fdset;
	int count;
	struct timeval timeout;


	timeout.tv_usec = 0;

	while(1)
	{
		if(sighup)
		{
			resource_update(config_dir);
			sighup = False;
		}

		if(trace_level > 1)
		{
			trace_sessions();
		}

		numfds = 0;
		FD_ZERO(&fdset);

		numfds = MAX(clients_sd, agents_sd);
		numfds = MAX(numfds,trap_sd);
		numfds++;
		FD_SET(clients_sd, &fdset);
		FD_SET(agents_sd, &fdset);
		FD_SET(trap_sd, &fdset);

		timeout.tv_sec = relay_agent_poll_interval;

		/* we compute the timeout according to the	*/
		/* timeout of the pending requests		*/
		session_select_info(&timeout);

		count = select(numfds, &fdset, 0, 0, &timeout);
		if(count > 0)
		{
			if(FD_ISSET(agents_sd, &fdset))
			{
				/* we read the responses of the agents */
				session_read();
				continue;
				
			}

			if(FD_ISSET(trap_sd, &fdset))
			{
				/* working on the trap */
				trap_processing();
				continue;
				
			}

			if(FD_ISSET(clients_sd, &fdset))
			{
				/* we dispatch the requests of the application */
				session_dispatch();

			        session_timeout();
				continue;
			}

		}
		else
		{
			switch(count)
			{
				case 0:
					/* we check if some requests have timeout */
					session_timeout();
					  watch_dog_in_action();
					break;

				case -1:
					if(errno == EINTR)
					{
						break;
					}
					else
					{
						error_exit(ERR_MSG_SELECT, errno_string());
					}
			}
		}
	}
}