commit
5622b911cb
@ -21,16 +21,6 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/select.h>
|
||||
#else
|
||||
#include <winsock2.h>
|
||||
#include <Windows.h>
|
||||
#include <ws2tcpip.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -55,24 +45,28 @@ struct tf_context
|
||||
};
|
||||
typedef struct tf_context tfContext;
|
||||
|
||||
int tf_context_new(freerdp* instance, rdpContext* context)
|
||||
static int tf_context_new(freerdp* instance, rdpContext* context)
|
||||
{
|
||||
context->channels = freerdp_channels_new();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tf_context_free(freerdp* instance, rdpContext* context)
|
||||
static void tf_context_free(freerdp* instance, rdpContext* context)
|
||||
{
|
||||
|
||||
if (context && context->channels)
|
||||
{
|
||||
freerdp_channels_close(context->channels, instance);
|
||||
freerdp_channels_free(context->channels);
|
||||
}
|
||||
}
|
||||
|
||||
void tf_begin_paint(rdpContext* context)
|
||||
static void tf_begin_paint(rdpContext* context)
|
||||
{
|
||||
rdpGdi* gdi = context->gdi;
|
||||
gdi->primary->hdc->hwnd->invalid->null = 1;
|
||||
}
|
||||
|
||||
void tf_end_paint(rdpContext* context)
|
||||
static void tf_end_paint(rdpContext* context)
|
||||
{
|
||||
rdpGdi* gdi = context->gdi;
|
||||
|
||||
@ -80,12 +74,10 @@ void tf_end_paint(rdpContext* context)
|
||||
return;
|
||||
}
|
||||
|
||||
BOOL tf_pre_connect(freerdp* instance)
|
||||
static BOOL tf_pre_connect(freerdp* instance)
|
||||
{
|
||||
tfContext* tfc;
|
||||
rdpSettings* settings;
|
||||
|
||||
tfc = (tfContext*) instance->context;
|
||||
|
||||
settings = instance->settings;
|
||||
|
||||
@ -117,12 +109,9 @@ BOOL tf_pre_connect(freerdp* instance)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL tf_post_connect(freerdp* instance)
|
||||
static BOOL tf_post_connect(freerdp* instance)
|
||||
{
|
||||
rdpGdi* gdi;
|
||||
|
||||
gdi_init(instance, CLRCONV_ALPHA | CLRCONV_INVERT | CLRBUF_16BPP | CLRBUF_32BPP, NULL);
|
||||
gdi = instance->context->gdi;
|
||||
|
||||
instance->update->BeginPaint = tf_begin_paint;
|
||||
instance->update->EndPaint = tf_end_paint;
|
||||
@ -132,112 +121,11 @@ BOOL tf_post_connect(freerdp* instance)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int tfreerdp_run(freerdp* instance)
|
||||
static void* tf_client_thread_proc(freerdp* instance)
|
||||
{
|
||||
int i;
|
||||
int fds;
|
||||
int max_fds;
|
||||
int rcount;
|
||||
int wcount;
|
||||
void* rfds[32];
|
||||
void* wfds[32];
|
||||
fd_set rfds_set;
|
||||
fd_set wfds_set;
|
||||
rdpChannels* channels;
|
||||
|
||||
channels = instance->context->channels;
|
||||
|
||||
freerdp_connect(instance);
|
||||
|
||||
while (1)
|
||||
{
|
||||
rcount = 0;
|
||||
wcount = 0;
|
||||
|
||||
ZeroMemory(rfds, sizeof(rfds));
|
||||
ZeroMemory(wfds, sizeof(wfds));
|
||||
|
||||
if (!freerdp_get_fds(instance, rfds, &rcount, wfds, &wcount))
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
|
||||
break;
|
||||
}
|
||||
|
||||
if (!freerdp_channels_get_fds(channels, instance, rfds, &rcount, wfds, &wcount))
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to get channel manager file descriptor");
|
||||
break;
|
||||
}
|
||||
|
||||
max_fds = 0;
|
||||
FD_ZERO(&rfds_set);
|
||||
FD_ZERO(&wfds_set);
|
||||
|
||||
fprintf(stderr, "rcount: %d\n", rcount);
|
||||
|
||||
for (i = 0; i < rcount; i++)
|
||||
{
|
||||
fds = (int)(long)(rfds[i]);
|
||||
|
||||
if (fds > max_fds)
|
||||
max_fds = fds;
|
||||
|
||||
FD_SET(fds, &rfds_set);
|
||||
}
|
||||
|
||||
if (max_fds == 0)
|
||||
break;
|
||||
|
||||
if (select(max_fds + 1, &rfds_set, &wfds_set, NULL, NULL) == -1)
|
||||
{
|
||||
/* these are not really errors */
|
||||
if (!((errno == EAGAIN) ||
|
||||
(errno == EWOULDBLOCK) ||
|
||||
(errno == EINPROGRESS) ||
|
||||
(errno == EINTR))) /* signal occurred */
|
||||
{
|
||||
WLog_ERR(TAG, "tfreerdp_run: select failed");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!freerdp_check_fds(instance))
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to check FreeRDP file descriptor");
|
||||
break;
|
||||
}
|
||||
|
||||
if (!freerdp_channels_check_fds(channels, instance))
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to check channel manager file descriptor");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
freerdp_channels_disconnect(channels, instance);
|
||||
freerdp_disconnect(instance);
|
||||
|
||||
freerdp_channels_close(channels, instance);
|
||||
freerdp_channels_free(channels);
|
||||
freerdp_free(instance);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void* tf_client_thread_proc(freerdp* instance)
|
||||
{
|
||||
int i;
|
||||
int fds;
|
||||
int max_fds;
|
||||
int rcount;
|
||||
int wcount;
|
||||
void* rfds[32];
|
||||
void* wfds[32];
|
||||
fd_set rfds_set;
|
||||
fd_set wfds_set;
|
||||
rdpChannels* channels;
|
||||
|
||||
channels = instance->context->channels;
|
||||
DWORD nCount;
|
||||
DWORD status;
|
||||
HANDLE handles[64];
|
||||
|
||||
if (!freerdp_connect(instance))
|
||||
{
|
||||
@ -245,72 +133,26 @@ void* tf_client_thread_proc(freerdp* instance)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (1)
|
||||
while (!freerdp_shall_disconnect(instance))
|
||||
{
|
||||
rcount = 0;
|
||||
wcount = 0;
|
||||
nCount = freerdp_get_event_handles(instance->context, &handles[0]);
|
||||
|
||||
ZeroMemory(rfds, sizeof(rfds));
|
||||
ZeroMemory(wfds, sizeof(wfds));
|
||||
status = WaitForMultipleObjects(nCount, handles, FALSE, 100);
|
||||
|
||||
if (!freerdp_get_fds(instance, rfds, &rcount, wfds, &wcount))
|
||||
if (status == WAIT_FAILED)
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
|
||||
break;
|
||||
}
|
||||
|
||||
if (!freerdp_channels_get_fds(channels, instance, rfds, &rcount, wfds, &wcount))
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to get channel manager file descriptor");
|
||||
break;
|
||||
}
|
||||
|
||||
max_fds = 0;
|
||||
FD_ZERO(&rfds_set);
|
||||
FD_ZERO(&wfds_set);
|
||||
|
||||
for (i = 0; i < rcount; i++)
|
||||
{
|
||||
fds = (int)(long)(rfds[i]);
|
||||
|
||||
if (fds > max_fds)
|
||||
max_fds = fds;
|
||||
|
||||
FD_SET(fds, &rfds_set);
|
||||
}
|
||||
|
||||
if (max_fds == 0)
|
||||
break;
|
||||
|
||||
if (select(max_fds + 1, &rfds_set, &wfds_set, NULL, NULL) == -1)
|
||||
{
|
||||
/* these are not really errors */
|
||||
if (!((errno == EAGAIN) ||
|
||||
(errno == EWOULDBLOCK) ||
|
||||
(errno == EINPROGRESS) ||
|
||||
(errno == EINTR))) /* signal occurred */
|
||||
{
|
||||
WLog_ERR(TAG, "tfreerdp_run: select failed");
|
||||
WLog_ERR(TAG, "%s: WaitForMultipleObjects failed with %lu", __FUNCTION__, status);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!freerdp_check_fds(instance))
|
||||
if (!freerdp_check_event_handles(instance->context))
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to check FreeRDP file descriptor");
|
||||
break;
|
||||
}
|
||||
|
||||
if (!freerdp_channels_check_fds(channels, instance))
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to check channel manager file descriptor");
|
||||
WLog_ERR(TAG, "Failed to check FreeRDP event handles");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
freerdp_channels_close(channels, instance);
|
||||
freerdp_channels_free(channels);
|
||||
freerdp_free(instance);
|
||||
freerdp_disconnect(instance);
|
||||
|
||||
ExitThread(0);
|
||||
return NULL;
|
||||
@ -321,7 +163,6 @@ int main(int argc, char* argv[])
|
||||
int status;
|
||||
HANDLE thread;
|
||||
freerdp* instance;
|
||||
rdpChannels* channels;
|
||||
|
||||
instance = freerdp_new();
|
||||
if (!instance)
|
||||
@ -341,8 +182,6 @@ int main(int argc, char* argv[])
|
||||
exit(1);
|
||||
}
|
||||
|
||||
channels = instance->context->channels;
|
||||
|
||||
status = freerdp_client_settings_parse_command_line(instance->settings, argc, argv, FALSE);
|
||||
|
||||
if (status < 0)
|
||||
@ -356,6 +195,8 @@ int main(int argc, char* argv[])
|
||||
tf_client_thread_proc, instance, 0, NULL);
|
||||
|
||||
WaitForSingleObject(thread, INFINITE);
|
||||
freerdp_context_free(instance);
|
||||
freerdp_free(instance);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -656,12 +656,9 @@ static void tf_peer_suppress_output(rdpContext* context, BYTE allow, RECTANGLE_1
|
||||
|
||||
static void* test_peer_mainloop(void* arg)
|
||||
{
|
||||
int i;
|
||||
int fds;
|
||||
int max_fds;
|
||||
int rcount;
|
||||
void* rfds[32];
|
||||
fd_set rfds_set;
|
||||
HANDLE handles[32];
|
||||
DWORD count;
|
||||
DWORD status;
|
||||
testPeerContext* context;
|
||||
freerdp_peer* client = (freerdp_peer*) arg;
|
||||
|
||||
@ -704,61 +701,18 @@ static void* test_peer_mainloop(void* arg)
|
||||
|
||||
while (1)
|
||||
{
|
||||
rcount = 0;
|
||||
count = 0;
|
||||
handles[count++] = client->GetEventHandle(client);
|
||||
handles[count++] = WTSVirtualChannelManagerGetEventHandle(context->vcm);
|
||||
|
||||
memset(rfds, 0, sizeof(rfds));
|
||||
if (client->GetFileDescriptor(client, rfds, &rcount) != TRUE)
|
||||
status = WaitForMultipleObjects(count, handles, FALSE, INFINITE);
|
||||
|
||||
if (status == WAIT_FAILED)
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
|
||||
WLog_ERR(TAG, "WaitForMultipleObjects failed (errno: %d)", errno);
|
||||
break;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
/* winsock's select() only works with sockets ! */
|
||||
WTSVirtualChannelManagerGetFileDescriptor(context->vcm, rfds, &rcount);
|
||||
#endif
|
||||
|
||||
max_fds = 0;
|
||||
FD_ZERO(&rfds_set);
|
||||
|
||||
for (i = 0; i < rcount; i++)
|
||||
{
|
||||
fds = (int)(long)(rfds[i]);
|
||||
|
||||
if (fds > max_fds)
|
||||
max_fds = fds;
|
||||
|
||||
FD_SET(fds, &rfds_set);
|
||||
}
|
||||
|
||||
if (max_fds == 0)
|
||||
break;
|
||||
|
||||
if (select(max_fds + 1, &rfds_set, NULL, NULL, NULL) == -1)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
/* error codes set by windows sockets are not made available through errno ! */
|
||||
int wsa_error = WSAGetLastError();
|
||||
if (!((wsa_error == WSAEWOULDBLOCK) ||
|
||||
(wsa_error == WSAEINPROGRESS) ||
|
||||
(wsa_error == WSAEINTR)))
|
||||
{
|
||||
WLog_ERR(TAG, "select failed (WSAGetLastError: %d)", wsa_error);
|
||||
break;
|
||||
}
|
||||
#else
|
||||
/* these are not really errors */
|
||||
if (!((errno == EAGAIN) ||
|
||||
(errno == EWOULDBLOCK) ||
|
||||
(errno == EINPROGRESS) ||
|
||||
(errno == EINTR))) /* signal occurred */
|
||||
{
|
||||
WLog_ERR(TAG, "select failed (errno: %d)", errno);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (client->CheckFileDescriptor(client) != TRUE)
|
||||
break;
|
||||
|
||||
@ -784,51 +738,26 @@ static void test_peer_accepted(freerdp_listener* instance, freerdp_peer* client)
|
||||
|
||||
static void test_server_mainloop(freerdp_listener* instance)
|
||||
{
|
||||
int i;
|
||||
int fds;
|
||||
int max_fds;
|
||||
int rcount;
|
||||
void* rfds[32];
|
||||
fd_set rfds_set;
|
||||
HANDLE handles[32];
|
||||
DWORD count;
|
||||
DWORD status;
|
||||
|
||||
while (1)
|
||||
{
|
||||
rcount = 0;
|
||||
count = 0;
|
||||
|
||||
memset(rfds, 0, sizeof(rfds));
|
||||
if (instance->GetFileDescriptor(instance, rfds, &rcount) != TRUE)
|
||||
if (instance->GetEventHandles(instance, handles, &count))
|
||||
{
|
||||
WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
|
||||
WLog_ERR(TAG, "Failed to get FreeRDP event handles");
|
||||
break;
|
||||
}
|
||||
|
||||
max_fds = 0;
|
||||
FD_ZERO(&rfds_set);
|
||||
status = WaitForMultipleObjects(count, handles, FALSE, INFINITE);
|
||||
|
||||
for (i = 0; i < rcount; i++)
|
||||
if (WAIT_FAILED == status)
|
||||
{
|
||||
fds = (int)(long)(rfds[i]);
|
||||
|
||||
if (fds > max_fds)
|
||||
max_fds = fds;
|
||||
|
||||
FD_SET(fds, &rfds_set);
|
||||
}
|
||||
|
||||
if (max_fds == 0)
|
||||
WLog_ERR(TAG, "select failed");
|
||||
break;
|
||||
|
||||
if (select(max_fds + 1, &rfds_set, NULL, NULL, NULL) == -1)
|
||||
{
|
||||
/* these are not really errors */
|
||||
if (!((errno == EAGAIN) ||
|
||||
(errno == EWOULDBLOCK) ||
|
||||
(errno == EINPROGRESS) ||
|
||||
(errno == EINTR))) /* signal occurred */
|
||||
{
|
||||
WLog_ERR(TAG, "select failed");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (instance->CheckFileDescriptor(instance) != TRUE)
|
||||
|
Loading…
Reference in New Issue
Block a user