Example #1
0
static int wlfreerdp_run(freerdp* instance)
{
	DWORD count;
	HANDLE handles[64];
	DWORD status;

	if (!freerdp_connect(instance))
	{
			printf("Failed to connect\n");
			return -1;
	}

	handle_uwac_events(instance, g_display);

	while (!freerdp_shall_disconnect(instance))
	{
		handles[0] = g_displayHandle;

		count = freerdp_get_event_handles(instance->context, &handles[1], 63);
		if (!count)
		{
			printf("Failed to get FreeRDP file descriptor\n");
			break;
		}

		status = WaitForMultipleObjects(count+1, handles, FALSE, INFINITE);
		if (WAIT_FAILED == status)
		{
			printf("%s: WaitForMultipleObjects failed\n", __FUNCTION__);
			break;
		}

		if (!handle_uwac_events(instance, g_display)) {
			printf("error handling UWAC events\n");
			break;
		}

		//if (WaitForMultipleObjects(count, &handles[1], FALSE, INFINITE)) {
			if (freerdp_check_event_handles(instance->context) != TRUE)
			{
				printf("Failed to check FreeRDP file descriptor\n");
				break;
			}
		//}

	}

	freerdp_channels_disconnect(instance->context->channels, instance);
	freerdp_disconnect(instance);

	return 0;
}
Example #2
0
static DWORD WINAPI tf_client_thread_proc(LPVOID arg)
{
	freerdp* instance = (freerdp*)arg;
	DWORD nCount;
	DWORD status;
	HANDLE handles[64];

	if (!freerdp_connect(instance))
	{
		WLog_ERR(TAG, "connection failure");
		return 0;
	}

	while (!freerdp_shall_disconnect(instance))
	{
		nCount = freerdp_get_event_handles(instance->context, &handles[0], 64);

		if (nCount == 0)
		{
			WLog_ERR(TAG, "%s: freerdp_get_event_handles failed", __FUNCTION__);
			break;
		}

		status = WaitForMultipleObjects(nCount, handles, FALSE, 100);

		if (status == WAIT_FAILED)
		{
			WLog_ERR(TAG, "%s: WaitForMultipleObjects failed with %"PRIu32"", __FUNCTION__,
			         status);
			break;
		}

		if (!freerdp_check_event_handles(instance->context))
		{
			if (freerdp_get_last_error(instance->context) == FREERDP_ERROR_SUCCESS)
				WLog_ERR(TAG, "Failed to check FreeRDP event handles");

			break;
		}
	}

	freerdp_disconnect(instance);
	ExitThread(0);
	return 0;
}
Example #3
0
static void* tf_client_thread_proc(freerdp* instance)
{
	DWORD nCount;
	DWORD status;
	HANDLE handles[64];

	if (!freerdp_connect(instance))
	{
		WLog_ERR(TAG, "connection failure");
		return NULL;
	}

	while (!freerdp_shall_disconnect(instance))
	{
		nCount = freerdp_get_event_handles(instance->context, &handles[0], 64);

		if (nCount == 0)
		{
			WLog_ERR(TAG, "%s: freerdp_get_event_handles failed", __FUNCTION__);
			break;
		}

		status = WaitForMultipleObjects(nCount, handles, FALSE, 100);

		if (status == WAIT_FAILED)
		{
			WLog_ERR(TAG, "%s: WaitForMultipleObjects failed with %lu", __FUNCTION__,
			         (unsigned long) status);
			break;
		}

		if (!freerdp_check_event_handles(instance->context))
		{
			WLog_ERR(TAG, "Failed to check FreeRDP event handles");
			break;
		}
	}

	freerdp_disconnect(instance);
	ExitThread(0);
	return NULL;
}
Example #4
0
static int wlfreerdp_run(freerdp* instance)
{
	DWORD count;
	HANDLE handles[64];
	DWORD status;

	if (!freerdp_connect(instance))
	{
			printf("Failed to connect\n");
			return -1;
	}

	while (!freerdp_shall_disconnect(instance))
	{
		count = freerdp_get_event_handles(instance->context, handles, 64);
		if (!count)
		{
			printf("Failed to get FreeRDP file descriptor\n");
			break;
		}

		status = WaitForMultipleObjects(count, handles, FALSE, INFINITE);
		if (WAIT_FAILED == status)
		{
			printf("%s: WaitForMultipleObjects failed\n", __FUNCTION__);
			break;
		}

		if (freerdp_check_event_handles(instance->context) != TRUE)
		{
			printf("Failed to check FreeRDP file descriptor\n");
			break;
		}
	}

	freerdp_channels_disconnect(instance->context->channels, instance);
	freerdp_disconnect(instance);

	return 0;
}
Example #5
0
static void* transport_client_thread(void* arg)
{
	DWORD dwExitCode = 0;
	DWORD status;
	DWORD nCount;
	DWORD nCountTmp;
	HANDLE handles[64];
	rdpTransport* transport = (rdpTransport*) arg;
	rdpContext* context = transport->context;
	rdpRdp* rdp = context->rdp;

	WLog_DBG(TAG, "Asynchronous transport thread started");

	nCount = 0;
	handles[nCount++] = transport->stopEvent;
	handles[nCount++] = transport->connectedEvent;

	status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);

	switch (status)
	{
		case WAIT_OBJECT_0:
			WLog_DBG(TAG, "stopEvent triggered");
			goto out;

		case WAIT_OBJECT_0 + 1:
			WLog_DBG(TAG, "connectedEvent event triggered");
			break;

		default:
			WLog_ERR(TAG, "WaitForMultipleObjects failed with status 0x%08X", status);
			dwExitCode = 1;
			goto out;
	}

	while (1)
	{
		nCount = 1; /* transport->stopEvent */

		if (!(nCountTmp = freerdp_get_event_handles(context, &handles[nCount], 64 - nCount)))
		{
			WLog_ERR(TAG, "freerdp_get_event_handles failed");
			break;
		}
		nCount += nCountTmp;

		status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);

		if (transport->layer == TRANSPORT_LAYER_CLOSED)
		{
			WLog_DBG(TAG, "TRANSPORT_LAYER_CLOSED");
			rdp_set_error_info(rdp, ERRINFO_PEER_DISCONNECTED);
			break;
		}

		if (status == WAIT_OBJECT_0)
		{
			WLog_DBG(TAG, "stopEvent triggered");
			break;
		}
		else if (status > WAIT_OBJECT_0 && status < (WAIT_OBJECT_0 + nCount))
		{
			if (!freerdp_check_event_handles(context))
			{
				WLog_ERR(TAG, "freerdp_check_event_handles()");
				rdp_set_error_info(rdp, ERRINFO_PEER_DISCONNECTED);
				break;
			}
		}
		else
		{
			if (status == WAIT_TIMEOUT)
				WLog_ERR(TAG, "WaitForMultipleObjects returned WAIT_TIMEOUT");
			else
				WLog_ERR(TAG, "WaitForMultipleObjects returned 0x%08X", status);
			dwExitCode = 1;
			break;
		}
	}

out:
	WLog_DBG(TAG, "Terminating transport thread");
	ExitThread(dwExitCode);
	return NULL;
}
Example #6
0
DWORD WINAPI wf_client_thread(LPVOID lpParam)
{
	MSG msg;
	int width;
	int height;
	BOOL msg_ret;
	int quit_msg;
	DWORD nCount;
	HANDLE handles[64];
	wfContext* wfc;
	freerdp* instance;
	rdpContext* context;
	rdpChannels* channels;
	rdpSettings* settings;
	BOOL async_input;
	BOOL async_transport;
	HANDLE input_thread;

	instance = (freerdp*) lpParam;
	context = instance->context;
	wfc = (wfContext*) instance->context;

	if (!freerdp_connect(instance))
		return 0;

	channels = instance->context->channels;
	settings = instance->context->settings;

	async_input = settings->AsyncInput;
	async_transport = settings->AsyncTransport;

	if (async_input)
	{
		if (!(input_thread = CreateThread(NULL, 0,
				(LPTHREAD_START_ROUTINE) wf_input_thread,
				instance, 0, NULL)))
		{
			WLog_ERR(TAG, "Failed to create async input thread.");
			goto disconnect;
		}
	}

	while (1)
	{
		nCount = 0;

		if (freerdp_focus_required(instance))
		{
			wf_event_focus_in(wfc);
			wf_event_focus_in(wfc);
		}

		if (!async_transport)
		{
			DWORD tmp = freerdp_get_event_handles(context, &handles[nCount], 64 - nCount);

			if (tmp == 0)
			{
				WLog_ERR(TAG, "freerdp_get_event_handles failed");
				break;
			}

			nCount += tmp;
		}

		if (MsgWaitForMultipleObjects(nCount, handles, FALSE, 1000, QS_ALLINPUT) == WAIT_FAILED)
		{
			WLog_ERR(TAG, "wfreerdp_run: WaitForMultipleObjects failed: 0x%04X", GetLastError());
			break;
		}

		if (!async_transport)
		{
			if (!freerdp_check_event_handles(context))
			{
				if (wf_auto_reconnect(instance))
					continue;

				WLog_ERR(TAG, "Failed to check FreeRDP file descriptor");
				break;
			}
		}

		if (freerdp_shall_disconnect(instance))
			break;

		quit_msg = FALSE;

		while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
		{
			msg_ret = GetMessage(&msg, NULL, 0, 0);

			if (instance->settings->EmbeddedWindow)
			{
				if ((msg.message == WM_SETFOCUS) && (msg.lParam == 1))
				{
					PostMessage(wfc->hwnd, WM_SETFOCUS, 0, 0);
				}
				else if ((msg.message == WM_KILLFOCUS) && (msg.lParam == 1))
				{
					PostMessage(wfc->hwnd, WM_KILLFOCUS, 0, 0);
				}
			}

			if (msg.message == WM_SIZE)
			{
				width = LOWORD(msg.lParam);
				height = HIWORD(msg.lParam);

				SetWindowPos(wfc->hwnd, HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED);
			}

			if ((msg_ret == 0) || (msg_ret == -1))
			{
				quit_msg = TRUE;
				break;
			}

			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

		if (quit_msg)
			break;
	}

	/* cleanup */
	freerdp_channels_disconnect(channels, instance);

	if (async_input)
	{
		wMessageQueue* input_queue;
		input_queue = freerdp_get_message_queue(instance, FREERDP_INPUT_MESSAGE_QUEUE);
		if (MessageQueue_PostQuit(input_queue, 0))
			WaitForSingleObject(input_thread, INFINITE);
		CloseHandle(input_thread);
	}

disconnect:
	freerdp_disconnect(instance);
	WLog_DBG(TAG, "Main thread exited.");

	ExitThread(0);
	return 0;
}
Example #7
0
static void* transport_client_thread(void* arg)
{
	DWORD dwExitCode = 0;
	DWORD status;
	DWORD nCount;
	HANDLE handles[64];
	rdpTransport* transport = (rdpTransport*) arg;
	rdpContext* context = transport->context;
	rdpRdp* rdp = context->rdp;

	WLog_DBG(TAG, "Asynchronous transport thread started");

	nCount = 0;
	handles[nCount++] = transport->stopEvent;
	handles[nCount++] = transport->connectedEvent;

	status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);

	switch (status)
	{
		case WAIT_OBJECT_0:
			WLog_DBG(TAG, "stopEvent triggered");
			goto out;

		case WAIT_OBJECT_0 + 1:
			WLog_DBG(TAG, "connectedEvent event triggered");
			break;

		default:
			WLog_ERR(TAG, "WaitForMultipleObjects failed with status 0x%08X", status);
			dwExitCode = 1;
			goto out;
	}

	while (1)
	{
		handles[0] = transport->stopEvent;

		if (!(nCount = freerdp_get_event_handles(context, &handles[1], 63)))
		{
			WLog_ERR(TAG, "freerdp_get_event_handles failed");
			break;
		}
		nCount++;

		status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);

		if (transport->layer == TRANSPORT_LAYER_CLOSED)
		{
			rdp_set_error_info(rdp, ERRINFO_PEER_DISCONNECTED);
			break;
		}

		if (status == WAIT_OBJECT_0)
		{
			WLog_DBG(TAG, "stopEvent triggered");
			break;
		}
		else if (status > WAIT_OBJECT_0 && status < (WAIT_OBJECT_0 + nCount))
		{
			if (!freerdp_check_event_handles(context))
			{
				rdp_set_error_info(rdp, ERRINFO_PEER_DISCONNECTED);
				break;
			}
		}
		else
		{
			if (status == WAIT_TIMEOUT)
			{
				/* This happens quite frequently although we've specified an INFINITE timeout
				 * WaitForMultipleObjects bug ?
				 */
				continue;
			}
			WLog_ERR(TAG, "WaitForMultipleObjects failed with status 0x%08X", status);
			dwExitCode = 1;
			break;
		}
	}

out:
	WLog_DBG(TAG, "Terminating transport thread");
	ExitThread(dwExitCode);
	return NULL;
}
Example #8
0
static int android_freerdp_run(freerdp* instance)
{
	DWORD count;
	DWORD status = WAIT_FAILED;
	HANDLE handles[64];
	HANDLE inputEvent = NULL;
	HANDLE inputThread = NULL;
	const rdpSettings* settings = instance->context->settings;
	rdpContext* context = instance->context;
	BOOL async_input = settings->AsyncInput;
	WLog_DBG(TAG, "AsyncInput=%d", settings->AsyncInput);

	if (async_input)
	{
		if (!(inputThread = CreateThread(NULL, 0,
		                                 (LPTHREAD_START_ROUTINE) jni_input_thread, instance, 0, NULL)))
		{
			WLog_ERR(TAG, "async input: failed to create input thread");
			goto disconnect;
		}
	}
	else
		inputEvent = android_get_handle(instance);

	while (!freerdp_shall_disconnect(instance))
	{
		DWORD tmp;
		count = 0;

		if (inputThread)
			handles[count++] = inputThread;
		else
			handles[count++] = inputEvent;

		tmp = freerdp_get_event_handles(context, &handles[count], 64 - count);

		if (tmp == 0)
		{
			WLog_ERR(TAG, "freerdp_get_event_handles failed");
			break;
		}

		count += tmp;
		status = WaitForMultipleObjects(count, handles, FALSE, INFINITE);

		if ((status == WAIT_FAILED))
		{
			WLog_ERR(TAG, "WaitForMultipleObjects failed with %lu [%08lX]",
			         status, GetLastError());
			break;
		}

		if (!freerdp_check_event_handles(context))
		{
			/* TODO: Auto reconnect
			if (xf_auto_reconnect(instance))
				continue;
				*/
			WLog_ERR(TAG, "Failed to check FreeRDP file descriptor");
			status = GetLastError();
			break;
		}

		if (freerdp_shall_disconnect(instance))
			break;

		if (!async_input)
		{
			if (android_check_handle(instance) != TRUE)
			{
				WLog_ERR(TAG, "Failed to check android file descriptor");
				status = GetLastError();
				break;
			}
		}
	}

disconnect:
	WLog_INFO(TAG, "Prepare shutdown...");

	if (async_input && inputThread)
	{
		WaitForSingleObject(inputThread, INFINITE);
		CloseHandle(inputThread);
	}

	return status;
}