static DWORD WINAPI wf_peer_main_loop(LPVOID lpParam) { int rcount; void* rfds[32]; wfPeerContext* context; freerdp_peer* client = (freerdp_peer*) lpParam; memset(rfds, 0, sizeof(rfds)); wf_peer_init(client); /* Initialize the real server settings here */ client->settings->cert_file = xstrdup("server.crt"); client->settings->privatekey_file = xstrdup("server.key"); client->PostConnect = wf_peer_post_connect; client->Activate = wf_peer_activate; client->input->SynchronizeEvent = wf_peer_synchronize_event; client->input->KeyboardEvent = wf_peer_keyboard_event; client->input->UnicodeKeyboardEvent = wf_peer_unicode_keyboard_event; client->input->MouseEvent = wf_peer_mouse_event; client->input->ExtendedMouseEvent = wf_peer_extended_mouse_event; client->Initialize(client); context = (wfPeerContext*) client->context; printf("We've got a client %s\n", client->local ? "(local)" : client->hostname); while (1) { rcount = 0; if (client->GetFileDescriptor(client, rfds, &rcount) != true) { printf("Failed to get FreeRDP file descriptor\n"); break; } if (client->CheckFileDescriptor(client) != true) { printf("Failed to check FreeRDP file descriptor\n"); break; } } printf("Client %s disconnected.\n", client->local ? "(local)" : client->hostname); client->Disconnect(client); freerdp_peer_context_free(client); freerdp_peer_free(client); return 0; }
DWORD WINAPI wf_peer_main_loop(LPVOID lpParam) { wfInfo* wfi; DWORD nCount; DWORD status; HANDLE handles[32]; rdpSettings* settings; wfPeerContext* context; freerdp_peer* client = (freerdp_peer*) lpParam; wf_peer_init(client); settings = client->settings; settings->RemoteFxCodec = TRUE; settings->ColorDepth = 32; settings->NSCodec = FALSE; settings->JpegCodec = FALSE; wf_peer_read_settings(client); client->PostConnect = wf_peer_post_connect; client->Activate = wf_peer_activate; client->Logon = wf_peer_logon; client->input->SynchronizeEvent = wf_peer_synchronize_event; client->input->KeyboardEvent = wf_peer_keyboard_event; client->input->UnicodeKeyboardEvent = wf_peer_unicode_keyboard_event; client->input->MouseEvent = wf_peer_mouse_event; client->input->ExtendedMouseEvent = wf_peer_extended_mouse_event; client->Initialize(client); context = (wfPeerContext*) client->context; if (context->socketClose) return 0; wfi = context->info; if (wfi->input_disabled == TRUE) { printf("client input is disabled\n"); client->input->KeyboardEvent = wf_peer_keyboard_event_dummy; client->input->UnicodeKeyboardEvent = wf_peer_unicode_keyboard_event_dummy; client->input->MouseEvent = wf_peer_mouse_event_dummy; client->input->ExtendedMouseEvent = wf_peer_extended_mouse_event_dummy; } context->socketEvent = CreateEvent(NULL, TRUE, FALSE, NULL); context->socketSemaphore = CreateSemaphore(NULL, 0, 1, NULL); context->socketThread = CreateThread(NULL, 0, wf_peer_socket_listener, client, 0, NULL); printf("We've got a client %s\n", client->local ? "(local)" : client->hostname); nCount = 0; handles[nCount++] = context->updateEvent; handles[nCount++] = context->socketEvent; while (1) { status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE); if ((status == WAIT_FAILED) || (status == WAIT_TIMEOUT)) { printf("WaitForMultipleObjects failed\n"); break; } if (WaitForSingleObject(context->updateEvent, 0) == 0) { if (client->activated) wf_update_peer_send(wfi, context); ResetEvent(context->updateEvent); ReleaseSemaphore(wfi->updateSemaphore, 1, NULL); } if (WaitForSingleObject(context->socketEvent, 0) == 0) { if (client->CheckFileDescriptor(client) != TRUE) { //printf("Failed to check peer file descriptor\n"); context->socketClose = TRUE; } ResetEvent(context->socketEvent); ReleaseSemaphore(context->socketSemaphore, 1, NULL); if (context->socketClose) break; } //force disconnect if(wfi->force_all_disconnect == TRUE) { printf("Forcing Disconnect -> "); break; } /* FIXME: we should wait on this, instead of calling it every time */ if (WTSVirtualChannelManagerCheckFileDescriptor(context->vcm) != TRUE) break; } printf("Client %s disconnected.\n", client->local ? "(local)" : client->hostname); if (WaitForSingleObject(context->updateEvent, 0) == 0) { ResetEvent(context->updateEvent); ReleaseSemaphore(wfi->updateSemaphore, 1, NULL); } wf_update_peer_deactivate(wfi, context); client->Disconnect(client); freerdp_peer_context_free(client); freerdp_peer_free(client); return 0; }