Exemplo n.º 1
0
void tcp_client::run_no_wait()
{
	tcp_session::run();
	{
		boost::mutex::scoped_lock lock( m_mutex );
		if( !m_isconnected && m_isreconnect && !m_isconnecting && m_isinitconncted )
		{
			unsigned int now = (unsigned int)time( NULL );
			if( now - m_last_reconnect_time > m_reconnect_time )
				reconnect();
		}
	}

	m_cb_mgr.poll();
	int proc_index = 0;
	{
		boost::mutex::scoped_lock lock( m_msg_mutex );
		if( m_queue_recv_msg[m_current_recv_queue].empty() )
			return;
		
		proc_index = m_current_recv_queue;
		m_current_recv_queue = !m_current_recv_queue;
	}
	while( !m_queue_recv_msg[proc_index].empty() )
	{
		message_t* msg = m_queue_recv_msg[proc_index].front();
		proc_message( *msg );
		net_global::free_message( msg );
		m_queue_recv_msg[proc_index].pop();
	}
}
Exemplo n.º 2
0
xui_method_explain(xui_desktop, update,			void					)( f32 delta )
{
	xui_panel::update(delta);
	proc_message();
	proc_recycle();
	proc_settext();
}
Exemplo n.º 3
0
void tcp_ProtoClient::run_no_wait()
{
	m_cb_mgr.poll();
	{
		boost::mutex::scoped_lock lock( m_msg_mutex );
		if( m_queue_recv_msg.empty() )
			return;
		std::swap( m_queue_proc_swap_msg, m_queue_recv_msg );
	}
	while( !m_queue_proc_swap_msg.empty() )
	{
		message_t* msg = m_queue_proc_swap_msg.front();
		proc_message( *msg );
		MyNetGlobleObj::free_message( msg );
		m_queue_proc_swap_msg.pop();
	}
}
Exemplo n.º 4
0
void tcp_ProtoClient::run()
{
	m_cb_mgr.poll();
	{
		boost::mutex::scoped_lock lock( m_msg_mutex );
		if( m_queue_recv_msg.empty() )
		{
			boost::xtime xt;
			boost::xtime_get( &xt, boost::xtime_clock_types::TIME_UTC_ );
			xt.nsec += 10000000;
			if( !m_msg_cond.timed_wait( m_msg_mutex, xt ) )
				return;
		}
		std::swap( m_queue_proc_swap_msg, m_queue_recv_msg );
	}
	while( !m_queue_proc_swap_msg.empty() )
	{
		message_t* msg = m_queue_proc_swap_msg.front();
		proc_message( *msg );
		MyNetGlobleObj::free_message( msg );
		m_queue_proc_swap_msg.pop();
	}
}
Exemplo n.º 5
0
int proc_loop(void)
{
	int rc = 0;

	log_debug("setting working directory ...\n");
	if ((mkdir(daemon_cfg.notify_dir, 0777) != 0) && (errno != EEXIST)) {
		rc = -errno;
		log_error("failed create folder %s (errno = %d)\n",
			  daemon_cfg.notify_dir, errno);
		goto err;
	}

	log_debug("setting store ...\n");
	rc = open_store();
	if (rc < 0) {
		goto err;
	}

	log_debug("setting flow ...\n");
	rc = open_flow();
	if (rc < 0) {
		goto err;
	}

	log_debug("setting notification ...\n");
	rc = open_notify();
	if (rc < 0) {
		goto err;
	}

	log_debug("setting message processing ...\n");
	rc = open_message();
	if (rc < 0) {
		goto err;
	}

	log_debug("starting loop ...\n");
	while ((0 == daemon_cfg.sig) && (errno != EINTR)) {
		fd_set readfds;
		struct timeval tv;
		int max_fd = -1;

		FD_ZERO(&readfds);
		FD_SET(daemon_cfg.sock_fd, &readfds);
		max_fd = daemon_cfg.sock_fd;
		FD_SET(daemon_cfg.notify_fd, &readfds);
		max_fd = (max_fd < daemon_cfg.notify_fd ? daemon_cfg.notify_fd : max_fd);

		/* Use timeout for select() call */
		tv.tv_sec = 60;
		tv.tv_usec = 0;

		rc = select(max_fd + 1, &readfds, NULL, NULL, &tv);
		if (rc < 0) {
			rc = 0;
			if (errno != EINTR) {
				rc = -errno;
				log_error("Failed select() errno %d (%s)\n", errno,
						strerror(errno));
			}
			goto err;
		} else if (rc == 0) {
			continue;
		}

		/* Check messages from processes */
		if (FD_ISSET(daemon_cfg.sock_fd, &readfds)) {
			log_debug("message processing ...\n");
			rc = proc_message();
		}

		/* Check any events from file system monitor */
		if (FD_ISSET(daemon_cfg.notify_fd, &readfds)) {
			log_debug("notification processing ...\n");
			rc = proc_notify();
		}
	}

err:
	log_debug("finishing loop ...\n");

	close_message();
	close_notify();
	close_flow();
	close_store();

	return rc;
}