diff --git a/include/freerdp/channels/channels.h b/include/freerdp/channels/channels.h index 0f72bd278..3f2187a2d 100644 --- a/include/freerdp/channels/channels.h +++ b/include/freerdp/channels/channels.h @@ -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, diff --git a/include/freerdp/channels/wtsvc.h b/include/freerdp/channels/wtsvc.h index 9626c5852..4011e5dfa 100644 --- a/include/freerdp/channels/wtsvc.h +++ b/include/freerdp/channels/wtsvc.h @@ -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); diff --git a/include/freerdp/freerdp.h b/include/freerdp/freerdp.h index 973b7b6ec..0deb3dea8 100644 --- a/include/freerdp/freerdp.h +++ b/include/freerdp/freerdp.h @@ -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); diff --git a/include/freerdp/listener.h b/include/freerdp/listener.h index 755ac46ea..520bba7bc 100644 --- a/include/freerdp/listener.h +++ b/include/freerdp/listener.h @@ -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; diff --git a/include/freerdp/peer.h b/include/freerdp/peer.h index 3f2e2ddc5..2dcd91a4f 100644 --- a/include/freerdp/peer.h +++ b/include/freerdp/peer.h @@ -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; diff --git a/libfreerdp/core/client.c b/libfreerdp/core/client.c index 6b7c48a00..7ab65c586 100644 --- a/libfreerdp/core/client.c +++ b/libfreerdp/core/client.c @@ -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) { diff --git a/libfreerdp/core/freerdp.c b/libfreerdp/core/freerdp.c index 04c7e049a..58d50a61a 100644 --- a/libfreerdp/core/freerdp.c +++ b/libfreerdp/core/freerdp.c @@ -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) { diff --git a/libfreerdp/core/listener.c b/libfreerdp/core/listener.c index 22fc98126..bd5b0c9f6 100644 --- a/libfreerdp/core/listener.c +++ b/libfreerdp/core/listener.c @@ -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; diff --git a/libfreerdp/core/peer.c b/libfreerdp/core/peer.c index ae4094cbc..31c9a6966 100644 --- a/libfreerdp/core/peer.c +++ b/libfreerdp/core/peer.c @@ -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; diff --git a/libfreerdp/core/server.c b/libfreerdp/core/server.c index 880597797..9e854c500 100644 --- a/libfreerdp/core/server.c +++ b/libfreerdp/core/server.c @@ -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) { diff --git a/libfreerdp/core/transport.c b/libfreerdp/core/transport.c index 074296aa3..be96b00f3 100644 --- a/libfreerdp/core/transport.c +++ b/libfreerdp/core/transport.c @@ -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) { diff --git a/libfreerdp/core/transport.h b/libfreerdp/core/transport.h index e45deec19..7bc092eb0 100644 --- a/libfreerdp/core/transport.h +++ b/libfreerdp/core/transport.h @@ -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, diff --git a/server/Mac/mf_peer.c b/server/Mac/mf_peer.c index 5f0535c47..873e47629 100644 --- a/server/Mac/mf_peer.c +++ b/server/Mac/mf_peer.c @@ -28,6 +28,7 @@ #include #include +#include #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; diff --git a/server/Mac/mfreerdp.c b/server/Mac/mfreerdp.c index cd45131f1..661653def 100644 --- a/server/Mac/mfreerdp.c +++ b/server/Mac/mfreerdp.c @@ -34,6 +34,7 @@ #include #include +#include #include #include @@ -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) diff --git a/server/Windows/wf_interface.c b/server/Windows/wf_interface.c index 7a2417ab8..f28f70fe7 100644 --- a/server/Windows/wf_interface.c +++ b/server/Windows/wf_interface.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -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) { diff --git a/server/Windows/wf_peer.c b/server/Windows/wf_peer.c index 748398199..7b5fe50fb 100644 --- a/server/Windows/wf_peer.c +++ b/server/Windows/wf_peer.c @@ -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); diff --git a/server/shadow/Win/win_rdp.c b/server/shadow/Win/win_rdp.c index 21c37eb6c..beb5ceaf1 100644 --- a/server/shadow/Win/win_rdp.c +++ b/server/shadow/Win/win_rdp.c @@ -23,6 +23,8 @@ #include #include #include +#include + #include #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;