From fca4374919388ebeb7d6831a7d5d90c9cb401833 Mon Sep 17 00:00:00 2001 From: David FORT Date: Tue, 7 Apr 2015 15:18:07 +0200 Subject: [PATCH] Add the ability to have listener from an existing socket --- include/freerdp/listener.h | 2 ++ libfreerdp/core/listener.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/freerdp/listener.h b/include/freerdp/listener.h index e502a41..95a0379 100644 --- a/include/freerdp/listener.h +++ b/include/freerdp/listener.h @@ -33,6 +33,7 @@ extern "C" { typedef BOOL (*psListenerOpen)(freerdp_listener* instance, const char* bind_address, UINT16 port); typedef BOOL (*psListenerOpenLocal)(freerdp_listener* instance, const char* path); +typedef BOOL (*psListenerOpenFromSocket)(freerdp_listener* instance, int fd); typedef BOOL (*psListenerGetFileDescriptor)(freerdp_listener* instance, void** rfds, int* rcount); typedef DWORD (*psListenerGetEventHandles)(freerdp_listener* instance, HANDLE* events, DWORD nCount); typedef BOOL (*psListenerCheckFileDescriptor)(freerdp_listener* instance); @@ -56,6 +57,7 @@ struct rdp_freerdp_listener psListenerClose Close; psPeerAccepted PeerAccepted; + psListenerOpenFromSocket OpenFromSocket; }; FREERDP_API freerdp_listener* freerdp_listener_new(void); diff --git a/libfreerdp/core/listener.c b/libfreerdp/core/listener.c index 3b6a0da..10095b9 100644 --- a/libfreerdp/core/listener.c +++ b/libfreerdp/core/listener.c @@ -231,6 +231,27 @@ static BOOL freerdp_listener_open_local(freerdp_listener* instance, const char* #endif } +static BOOL freerdp_listener_open_from_socket(freerdp_listener* instance, int fd) +{ +#ifndef _WIN32 + rdpListener* listener = (rdpListener*) instance->listener; + + if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) + return FALSE; + + listener->sockfds[listener->num_sockfds] = fd; + listener->events[listener->num_sockfds] = CreateFileDescriptorEvent(NULL, FALSE, FALSE, fd); + if (!listener->events[listener->num_sockfds]) + return FALSE; + + listener->num_sockfds++; + + WLog_INFO(TAG, "Listening on socket %d.", fd); +#endif + return TRUE; + +} + static void freerdp_listener_close(freerdp_listener* instance) { int i; @@ -375,6 +396,7 @@ freerdp_listener* freerdp_listener_new(void) instance->Open = freerdp_listener_open; instance->OpenLocal = freerdp_listener_open_local; + instance->OpenFromSocket = freerdp_listener_open_from_socket; instance->GetFileDescriptor = freerdp_listener_get_fds; instance->GetEventHandles = freerdp_listener_get_event_handles; instance->CheckFileDescriptor = freerdp_listener_check_fds; -- 2.7.4