Esempio n. 1
0
void test_wait_obj(void)
{
	struct wait_obj* wo;
	int set;

	wo = wait_obj_new();

	set = wait_obj_is_set(wo);
	CU_ASSERT(set == 0);

	wait_obj_set(wo);
	set = wait_obj_is_set(wo);
	CU_ASSERT(set == 1);

	wait_obj_clear(wo);
	set = wait_obj_is_set(wo);
	CU_ASSERT(set == 0);

	wait_obj_select(&wo, 1, 1000);

	wait_obj_free(wo);
}
Esempio n. 2
0
/* process the linked list of data that has queued to be sent */
static int
thread_process_data_out(rdpsndPlugin * plugin)
{
	char * data;
	int data_size;
	struct data_out_item * item;
	uint32 cur_time;
	uint32 error;

	LLOGLN(10, ("thread_process_data_out: "));
	while (1)
	{
		if (wait_obj_is_set(plugin->term_event))
		{
			break;
		}
		if (plugin->out_list_head == 0)
		{
			break;
		}
		cur_time = get_mstime();
		if (cur_time <= plugin->out_list_head->out_time_stamp)
		{
			break;
		}
		data = plugin->out_list_head->data;
		data_size = plugin->out_list_head->data_size;
		item = plugin->out_list_head;
		plugin->out_list_head = plugin->out_list_head->next;
		if (plugin->out_list_head == 0)
		{
			plugin->out_list_tail = 0;
		}

		error = plugin->ep.pVirtualChannelWrite(plugin->open_handle,
			data, data_size, data);
		if (error != CHANNEL_RC_OK)
		{
			LLOGLN(0, ("thread_process_data_out: "
				"VirtualChannelWrite "
				"failed %d", error));
		}
		LLOGLN(10, ("thread_process_data_out: confirm sent"));

		if (item != 0)
		{
			free(item);
		}
	}
	return 0;
}
Esempio n. 3
0
static void *
thread_func(void * arg)
{
	rdpsndPlugin * plugin;
	struct wait_obj * listobj[2];
	int numobj;
	int timeout;

	plugin = (rdpsndPlugin *) arg;

	plugin->thread_status = 1;
	LLOGLN(10, ("thread_func: in"));
	while (1)
	{
		listobj[0] = plugin->term_event;
		listobj[1] = plugin->data_in_event;
		numobj = 2;
		timeout = plugin->out_list_head == 0 ? -1 : 500;
		wait_obj_select(listobj, numobj, NULL, 0, timeout);
		if (wait_obj_is_set(plugin->term_event))
		{
			break;
		}
		if (wait_obj_is_set(plugin->data_in_event))
		{
			wait_obj_clear(plugin->data_in_event);
			/* process data in */
			thread_process_data_in(plugin);
		}
		if (plugin->out_list_head != 0)
		{
			thread_process_data_out(plugin);
		}
	}
	LLOGLN(10, ("thread_func: out"));
	plugin->thread_status = -1;
	return 0;
}
Esempio n. 4
0
int
wait_obj_clear(struct wait_obj * obj)
{
	int len;

	while (wait_obj_is_set(obj))
	{
		len = read(obj->pipe_fd[0], &len, 4);
		if (len != 4)
		{
			LLOGLN(0, ("chan_man_clear_ev: error"));
			return 1;
		}
	}
	return 0;
}
Esempio n. 5
0
int
wait_obj_set(struct wait_obj * obj)
{
	int len;

	if (wait_obj_is_set(obj))
	{
		return 0;
	}
	len = write(obj->pipe_fd[1], "sig", 4);
	if (len != 4)
	{
		LLOGLN(0, ("set_wait_obj: error"));
		return 1;
	}
	return 0;
}
Esempio n. 6
0
/* process the linked list of data that has come in */
static int
thread_process_data_in(rdpsndPlugin * plugin)
{
	char * data;
	int data_size;
	struct data_in_item * item;

	while (1)
	{
		if (wait_obj_is_set(plugin->term_event))
		{
			break;
		}
		pthread_mutex_lock(plugin->in_mutex);
		if (plugin->in_list_head == 0)
		{
			pthread_mutex_unlock(plugin->in_mutex);
			break;
		}
		data = plugin->in_list_head->data;
		data_size = plugin->in_list_head->data_size;
		item = plugin->in_list_head;
		plugin->in_list_head = plugin->in_list_head->next;
		if (plugin->in_list_head == 0)
		{
			plugin->in_list_tail = 0;
		}
		pthread_mutex_unlock(plugin->in_mutex);
		if (data != 0)
		{
			thread_process_message(plugin, data, data_size);
			free(data);
		}
		if (item != 0)
		{
			free(item);
		}

		if (plugin->out_list_head != 0)
		{
			thread_process_data_out(plugin);
		}
	}
	return 0;
}
Esempio n. 7
0
/* process the linked list of data that has come in */
static int
process_received_data(railCorePlugin * plugin)
{
	char * data;
	int data_size;
	struct data_in_item * item;

	while (1)
	{
		if (wait_obj_is_set(plugin->term_event))
		{
			break;
		}

		pthread_mutex_lock(plugin->in_mutex);
		if (plugin->in_list_head == NULL)
		{
			pthread_mutex_unlock(plugin->in_mutex);
			break;
		}
		data = plugin->in_list_head->data;
		data_size = plugin->in_list_head->data_size;

		item = plugin->in_list_head;
		plugin->in_list_head = plugin->in_list_head->next;
		if (plugin->in_list_head == NULL)
		{
			plugin->in_list_tail = NULL;
		}
		pthread_mutex_unlock(plugin->in_mutex);

		if (data != NULL)
		{
			rail_on_channel_data_received(plugin->session, data, data_size);
			free(data);
		}
		if (item != NULL)
		{
			free(item);
		}
	}
	return 0;
}
Esempio n. 8
0
int
wait_obj_set(struct wait_obj * obj)
{
	#ifdef _WIN32
		SetEvent(obj->event);
	#else
		int len;

		if (wait_obj_is_set(obj))
			return 0;
		len = write(obj->pipe_fd[1], "sig", 4);
		if (len != 4)
		{
			printf("wait_obj_set: error\n");
			return 1;
		}
	#endif

	return 0;
}
Esempio n. 9
0
int
wait_obj_clear(struct wait_obj * obj)
{
	#ifdef _WIN32
		ResetEvent(obj->event);
	#else
		int len;

		while (wait_obj_is_set(obj))
		{
			len = read(obj->pipe_fd[0], &len, 4);
			if (len != 4)
			{
				printf("wait_obj_clear: error\n");
				return 1;
			}
		}
	#endif

	return 0;
}