Added deprecation to *get_fds functions

This commit is contained in:
Armin Novak 2021-08-24 15:04:58 +02:00 committed by akallabeth
parent 724c6f8192
commit 9c7ec3888a
17 changed files with 115 additions and 148 deletions

View File

@ -39,9 +39,11 @@ extern "C"
PVIRTUALCHANNELENTRYEX entryEx, void* data);
FREERDP_API int freerdp_channels_load_plugin(rdpChannels* channels, rdpSettings* settings,
const char* name, void* data);
FREERDP_API BOOL freerdp_channels_get_fds(rdpChannels* channels, freerdp* instance,
#if defined(WITH_FREERDP_DEPRECATED)
FREERDP_API WINPR_DEPRECATED_VAR("Use freerdp_channels_get_event_handle", BOOL freerdp_channels_get_fds(rdpChannels* channels, freerdp* instance,
void** read_fds, int* read_count, void** write_fds,
int* write_count);
#endif
FREERDP_API BOOL freerdp_channels_check_fds(rdpChannels* channels, freerdp* instance);
FREERDP_API void* freerdp_channels_get_static_channel_interface(rdpChannels* channels,

View File

@ -55,9 +55,11 @@ extern "C"
/**
* WTSVirtualChannelManager functions are FreeRDP extensions to the API.
*/
FREERDP_API void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer, void** fds,
int* fds_count);
#if defined(WITH_FREERDP_DEPRECATED)
FREERDP_API WINPR_DEPRECATED_VAR(
"Use WTSVirtualChannelManagerGetEventHandle",
void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer, void** fds, int* fds_count));
#endif
FREERDP_API BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer);
FREERDP_API BOOL WTSVirtualChannelManagerCheckFileDescriptorEx(HANDLE hServer, BOOL autoOpen);
FREERDP_API HANDLE WTSVirtualChannelManagerGetEventHandle(HANDLE hServer);

View File

@ -509,8 +509,12 @@ settings but before rdp_client_connect() to have it executed after the
FREERDP_API UINT freerdp_channels_attach(freerdp* instance);
FREERDP_API UINT freerdp_channels_detach(freerdp* instance);
FREERDP_API BOOL freerdp_get_fds(freerdp* instance, void** rfds, int* rcount, void** wfds,
int* wcount);
#if defined(WITH_FREERDP_DEPRECATED)
FREERDP_API WINPR_DEPRECATED_VAR("Use freerdp_get_event_handles",
BOOL freerdp_get_fds(freerdp* instance, void** rfds,
int* rcount, void** wfds, int* wcount));
#endif
FREERDP_API BOOL freerdp_check_fds(freerdp* instance);
FREERDP_API DWORD freerdp_get_event_handles(rdpContext* context, HANDLE* events, DWORD count);

View File

@ -36,8 +36,10 @@ extern "C"
UINT16 port);
typedef BOOL (*psListenerOpenLocal)(freerdp_listener* instance, const char* path);
typedef BOOL (*psListenerOpenFromSocket)(freerdp_listener* instance, int fd);
#if defined(WITH_FREERDP_DEPRECATED)
typedef BOOL (*psListenerGetFileDescriptor)(freerdp_listener* instance, void** rfds,
int* rcount);
#endif
typedef DWORD (*psListenerGetEventHandles)(freerdp_listener* instance, HANDLE* events,
DWORD nCount);
typedef BOOL (*psListenerCheckFileDescriptor)(freerdp_listener* instance);
@ -55,7 +57,11 @@ extern "C"
psListenerOpen Open;
psListenerOpenLocal OpenLocal;
#if defined(WITH_FREERDP_DEPRECATED)
psListenerGetFileDescriptor GetFileDescriptor;
#else
void* reserved;
#endif
psListenerGetEventHandles GetEventHandles;
psListenerCheckFileDescriptor CheckFileDescriptor;
psListenerClose Close;

View File

@ -35,7 +35,9 @@ typedef BOOL (*psPeerContextNew)(freerdp_peer* peer, rdpContext* context);
typedef void (*psPeerContextFree)(freerdp_peer* peer, rdpContext* context);
typedef BOOL (*psPeerInitialize)(freerdp_peer* peer);
#if defined(WITH_FREERDP_DEPRECATED)
typedef BOOL (*psPeerGetFileDescriptor)(freerdp_peer* peer, void** rfds, int* rcount);
#endif
typedef HANDLE (*psPeerGetEventHandle)(freerdp_peer* peer);
typedef DWORD (*psPeerGetEventHandles)(freerdp_peer* peer, HANDLE* events, DWORD count);
typedef HANDLE (*psPeerGetReceiveEventHandle)(freerdp_peer* peer);
@ -98,7 +100,11 @@ struct rdp_freerdp_peer
psPeerContextFree ContextFree;
psPeerInitialize Initialize;
#if defined(WITH_FREERDP_DEPRECATED)
psPeerGetFileDescriptor GetFileDescriptor;
#else
void* reserved;
#endif
psPeerGetEventHandle GetEventHandle;
psPeerGetReceiveEventHandle GetReceiveEventHandle;
psPeerCheckFileDescriptor CheckFileDescriptor;

View File

@ -632,6 +632,7 @@ static int freerdp_channels_process_sync(rdpChannels* channels, freerdp* instanc
/**
* called only from main thread
*/
#if defined(WITH_FREERDP_DEPRECATED)
BOOL freerdp_channels_get_fds(rdpChannels* channels, freerdp* instance, void** read_fds,
int* read_count, void** write_fds, int* write_count)
{
@ -646,6 +647,7 @@ BOOL freerdp_channels_get_fds(rdpChannels* channels, freerdp* instance, void** r
return TRUE;
}
#endif
void* freerdp_channels_get_static_channel_interface(rdpChannels* channels, const char* name)
{

View File

@ -243,6 +243,7 @@ BOOL freerdp_abort_connect(freerdp* instance)
return SetEvent(instance->context->abortEvent);
}
#if defined(WITH_FREERDP_DEPRECATED)
BOOL freerdp_get_fds(freerdp* instance, void** rfds, int* rcount, void** wfds, int* wcount)
{
rdpRdp* rdp;
@ -256,6 +257,7 @@ BOOL freerdp_get_fds(freerdp* instance, void** rfds, int* rcount, void** wfds, i
transport_get_fds(rdp->transport, rfds, rcount);
return TRUE;
}
#endif
BOOL freerdp_check_fds(freerdp* instance)
{

View File

@ -259,6 +259,7 @@ static void freerdp_listener_close(freerdp_listener* instance)
listener->num_sockfds = 0;
}
#if defined(WITH_FREERDP_DEPRECATED)
static BOOL freerdp_listener_get_fds(freerdp_listener* instance, void** rfds, int* rcount)
{
int index;
@ -275,6 +276,7 @@ static BOOL freerdp_listener_get_fds(freerdp_listener* instance, void** rfds, in
return TRUE;
}
#endif
static DWORD freerdp_listener_get_event_handles(freerdp_listener* instance, HANDLE* events,
DWORD nCount)
@ -414,7 +416,9 @@ freerdp_listener* freerdp_listener_new(void)
instance->Open = freerdp_listener_open;
instance->OpenLocal = freerdp_listener_open_local;
instance->OpenFromSocket = freerdp_listener_open_from_socket;
#if defined(WITH_FREERDP_DEPRECATED)
instance->GetFileDescriptor = freerdp_listener_get_fds;
#endif
instance->GetEventHandles = freerdp_listener_get_event_handles;
instance->CheckFileDescriptor = freerdp_listener_check_fds;
instance->Close = freerdp_listener_close;

View File

@ -261,6 +261,7 @@ static BOOL freerdp_peer_initialize(freerdp_peer* client)
return TRUE;
}
#if defined(WITH_FREERDP_DEPRECATED)
static BOOL freerdp_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount)
{
rdpTransport* transport;
@ -273,6 +274,7 @@ static BOOL freerdp_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount)
transport_get_fds(transport, rfds, rcount);
return TRUE;
}
#endif
static HANDLE freerdp_peer_get_event_handle(freerdp_peer* client)
{
@ -1011,7 +1013,9 @@ freerdp_peer* freerdp_peer_new(int sockfd)
client->sockfd = sockfd;
client->ContextSize = sizeof(rdpContext);
client->Initialize = freerdp_peer_initialize;
#if defined(WITH_FREERDP_DEPRECATED)
client->GetFileDescriptor = freerdp_peer_get_fds;
#endif
client->GetEventHandle = freerdp_peer_get_event_handle;
client->GetEventHandles = freerdp_peer_get_event_handles;
client->CheckFileDescriptor = freerdp_peer_check_fds;

View File

@ -462,6 +462,7 @@ static BOOL WTSReceiveChannelData(freerdp_peer* client, UINT16 channelId, const
return TRUE;
}
#if defined(WITH_FREERDP_DEPRECATED)
void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer, void** fds, int* fds_count)
{
void* fd;
@ -493,6 +494,7 @@ void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer, void** fds, int*
#endif
}
#endif
static BOOL WTSVirtualChannelManagerOpen(WTSVirtualChannelManager* vcm)
{

View File

@ -1049,6 +1049,7 @@ DWORD transport_get_event_handles(rdpTransport* transport, HANDLE* events, DWORD
return nCount;
}
#if defined(WITH_FREERDP_DEPRECATED)
void transport_get_fds(rdpTransport* transport, void** rfds, int* rcount)
{
DWORD index;
@ -1069,6 +1070,7 @@ void transport_get_fds(rdpTransport* transport, void** rfds, int* rcount)
rfds[nCount] = GetEventWaitObject(transport->rereadEvent);
}
#endif
BOOL transport_is_write_blocked(rdpTransport* transport)
{

View File

@ -67,7 +67,9 @@ FREERDP_LOCAL BOOL transport_accept_nla(rdpTransport* transport);
FREERDP_LOCAL int transport_read_pdu(rdpTransport* transport, wStream* s);
FREERDP_LOCAL int transport_write(rdpTransport* transport, wStream* s);
#if defined(WITH_FREERDP_DEPRECATED)
FREERDP_LOCAL void transport_get_fds(rdpTransport* transport, void** rfds, int* rcount);
#endif
FREERDP_LOCAL int transport_check_fds(rdpTransport* transport);
FREERDP_LOCAL DWORD transport_get_event_handles(rdpTransport* transport, HANDLE* events,

View File

@ -28,6 +28,7 @@
#include <freerdp/codec/color.h>
#include <winpr/crt.h>
#include <winpr/assert.h>
#include "mf_peer.h"
#include "mf_info.h"
@ -318,15 +319,12 @@ static BOOL mf_peer_suppress_output(rdpContext* context, BYTE allow, const RECTA
static void* mf_peer_main_loop(void* arg)
{
int i;
int fds;
int max_fds;
int rcount;
void* rfds[32];
fd_set rfds_set;
mfPeerContext* context;
freerdp_peer* client = (freerdp_peer*)arg;
memset(rfds, 0, sizeof(rfds));
WINPR_ASSERT(client);
WINPR_ASSERT(client->settings);
WINPR_ASSERT(client->input);
if (!mf_peer_init(client))
{
@ -363,45 +361,25 @@ static void* mf_peer_main_loop(void* arg)
while (1)
{
rcount = 0;
DWORD status;
HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 };
DWORD count = client->GetEventHandles(handles, ARRAYSIZE(handles));
if (client->GetFileDescriptor(client, rfds, &rcount) != TRUE)
if ((count == 0) || (count == MAXIMUM_WAIT_OBJECTS))
{
WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
break;
}
if (mf_peer_get_fds(client, rfds, &rcount) != TRUE)
handles[count++] = WTSVirtualChannelManagerGetEventHandle(context->vcm);
status = WaitForMultipleObjects(handles, count, FALSE, INFINITE);
if (status == WAIT_FAILED)
{
WLog_ERR(TAG, "WaitForMultipleObjects failed");
break;
}
WTSVirtualChannelManagerGetFileDescriptor(context->vcm, rfds, &rcount);
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)
{
/* these are not really errors */
if (!((errno == EAGAIN) || (errno == EWOULDBLOCK) || (errno == EINPROGRESS) ||
(errno == EINTR))) /* signal occurred */
{
break;
}
}
if (client->CheckFileDescriptor(client) != TRUE)
{
break;

View File

@ -34,6 +34,7 @@
#include <winpr/crt.h>
#include <winpr/wtsapi.h>
#include <winpr/assert.h>
#include <freerdp/freerdp.h>
#include <freerdp/constants.h>
@ -45,48 +46,27 @@
static void mf_server_main_loop(freerdp_listener* instance)
{
int i;
int fds;
int max_fds;
int rcount;
void* rfds[32];
fd_set rfds_set;
memset(rfds, 0, sizeof(rfds));
WINPR_ASSERT(instance);
WINPR_ASSERT(instance->GetEventHandles);
WINPR_ASSERT(instance->CheckFileDescriptor);
while (1)
{
rcount = 0;
DWORD status;
HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 };
DWORD count = instance->GetEventHandles(instance, handles, ARRAYSIZE(handles));
if (instance->GetFileDescriptor(instance, rfds, &rcount) != TRUE)
if (count == 0)
{
WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
break;
}
max_fds = 0;
FD_ZERO(&rfds_set);
for (i = 0; i < rcount; i++)
status = WaitForMultipleObjects(handles, count, FALSE, INFINITE);
if (status == WAIT_FAILED)
{
fds = (int)(long)(rfds[i]);
if (fds > max_fds)
max_fds = fds;
FD_SET(fds, &rfds_set);
}
if (max_fds == 0)
WLog_ERR(TAG, "WaitForMultipleObjects 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 */
{
break;
}
}
if (instance->CheckFileDescriptor(instance) != TRUE)

View File

@ -25,6 +25,7 @@
#include <winpr/tchar.h>
#include <winpr/windows.h>
#include <winpr/winsock.h>
#include <winpr/assert.h>
#include <freerdp/freerdp.h>
#include <freerdp/listener.h>
@ -87,11 +88,6 @@ void set_screen_id(int id)
static DWORD WINAPI wf_server_main_loop(LPVOID lpParam)
{
int i, fds;
int rcount;
int max_fds;
void* rfds[32];
fd_set rfds_set;
freerdp_listener* instance;
wfInfo* wfi;
@ -104,36 +100,29 @@ static DWORD WINAPI wf_server_main_loop(LPVOID lpParam)
wfi->force_all_disconnect = FALSE;
ZeroMemory(rfds, sizeof(rfds));
instance = (freerdp_listener*)lpParam;
WINPR_ASSERT(instance);
WINPR_ASSERT(instance->GetEventHandles);
WINPR_ASSERT(instance->CheckFileDescriptor);
while (wfi->force_all_disconnect == FALSE)
{
rcount = 0;
DWORD status;
HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 };
DWORD count = instance->GetEventHandles(instance, handles, ARRAYSIZE(handles));
if (instance->GetFileDescriptor(instance, rfds, &rcount) != TRUE)
if (count == 0)
{
WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
break;
}
max_fds = 0;
FD_ZERO(&rfds_set);
for (i = 0; i < rcount; i++)
status = WaitForMultipleObjects(handles, count, FALSE, INFINITE);
if (status == WAIT_FAILED)
{
fds = (int)(long)(rfds[i]);
if (fds > max_fds)
max_fds = fds;
FD_SET(fds, &rfds_set);
}
if (max_fds == 0)
WLog_ERR(TAG, "WaitForMultipleObjects failed");
break;
select(max_fds + 1, &rfds_set, NULL, NULL, NULL);
}
if (instance->CheckFileDescriptor(instance) != TRUE)
{

View File

@ -167,43 +167,35 @@ BOOL wf_peer_accepted(freerdp_listener* instance, freerdp_peer* client)
static DWORD WINAPI wf_peer_socket_listener(LPVOID lpParam)
{
int i, fds;
int rcount;
int max_fds;
void* rfds[32];
fd_set rfds_set;
wfPeerContext* context;
freerdp_peer* client = (freerdp_peer*)lpParam;
ZeroMemory(rfds, sizeof(rfds));
WINPR_ASSERT(client);
WINPR_ASSERT(client->GetEventHandles);
WINPR_ASSERT(client->CheckFileDescriptor);
context = (wfPeerContext*)client->context;
WINPR_ASSERT(context);
while (1)
{
rcount = 0;
DWORD status;
HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 };
DWORD count = client->GetEventHandles(client, handles, ARRAYSIZE(handles));
if (client->GetFileDescriptor(client, rfds, &rcount) != TRUE)
if (count == 0)
{
WLog_ERR(TAG, "Failed to get peer file descriptor");
WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
break;
}
max_fds = 0;
FD_ZERO(&rfds_set);
for (i = 0; i < rcount; i++)
status = WaitForMultipleObjects(handles, count, FALSE, INFINITE);
if (status == WAIT_FAILED)
{
fds = (int)(long)(rfds[i]);
if (fds > max_fds)
max_fds = fds;
FD_SET(fds, &rfds_set);
WLog_ERR(TAG, "WaitForMultipleObjects failed");
break;
}
if (max_fds == 0)
break;
select(max_fds + 1, &rfds_set, NULL, NULL, NULL);
SetEvent(context->socketEvent);
WaitForSingleObject(context->socketSemaphore, INFINITE);

View File

@ -23,6 +23,8 @@
#include <winpr/crt.h>
#include <winpr/assert.h>
#include <winpr/print.h>
#include <winpr/assert.h>
#include <freerdp/log.h>
#include "win_rdp.h"
@ -156,21 +158,19 @@ static BOOL shw_post_connect(freerdp* instance)
static DWORD WINAPI shw_client_thread(LPVOID arg)
{
int index;
int rcount;
int wcount;
BOOL bSuccess;
void* rfds[32];
void* wfds[32];
int fds_count;
HANDLE fds[64];
shwContext* shw;
rdpContext* context;
rdpChannels* channels;
freerdp* instance = (freerdp*)arg;
ZeroMemory(rfds, sizeof(rfds));
ZeroMemory(wfds, sizeof(wfds));
WINPR_ASSERT(instance);
context = (rdpContext*)instance->context;
WINPR_ASSERT(context);
shw = (shwContext*)context;
bSuccess = freerdp_connect(instance);
WLog_INFO(TAG, "freerdp_connect: %d", bSuccess);
@ -180,34 +180,24 @@ static DWORD WINAPI shw_client_thread(LPVOID arg)
return 0;
}
channels = instance->context->channels;
channels = context->channels;
WINPR_ASSERT(channels);
while (1)
{
rcount = 0;
wcount = 0;
DWORD status;
HANDLE handles[MAXIMUM_WAIT_OBJECTS] = { 0 };
DWORD count = freerdp_get_event_handles(instance, handles, ARRAYSIZE(handles));
if (!freerdp_get_fds(instance, rfds, &rcount, wfds, &wcount))
if ((count == 0) || (count == MAXIMUM_WAIT_OBJECTS))
{
WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
WLog_ERR(TAG, "Failed to get FreeRDP event handles");
break;
}
if (!freerdp_channels_get_fds(channels, instance, rfds, &rcount, wfds, &wcount))
{
WLog_ERR(TAG, "Failed to get channels file descriptor");
break;
}
handles[count++] = freerdp_channels_get_event_handle(instance);
fds_count = 0;
for (index = 0; index < rcount; index++)
fds[fds_count++] = rfds[index];
for (index = 0; index < wcount; index++)
fds[fds_count++] = wfds[index];
if (MsgWaitForMultipleObjects(fds_count, fds, FALSE, 1000, QS_ALLINPUT) == WAIT_FAILED)
if (MsgWaitForMultipleObjects(count, handles, FALSE, 1000, QS_ALLINPUT) == WAIT_FAILED)
{
WLog_ERR(TAG, "MsgWaitForMultipleObjects failure: 0x%08lX", GetLastError());
break;