libfreerdp-core: add event handle support to listener
This commit is contained in:
parent
1fab70504f
commit
1d2bedd95d
@ -34,6 +34,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 (*psListenerGetFileDescriptor)(freerdp_listener* instance, void** rfds, int* rcount);
|
||||
typedef int (*psListenerGetEventHandles)(freerdp_listener* instance, HANDLE* events, DWORD* nCount);
|
||||
typedef BOOL (*psListenerCheckFileDescriptor)(freerdp_listener* instance);
|
||||
typedef void (*psListenerClose)(freerdp_listener* instance);
|
||||
typedef void (*psPeerAccepted)(freerdp_listener* instance, freerdp_peer* client);
|
||||
@ -50,6 +51,7 @@ struct rdp_freerdp_listener
|
||||
psListenerOpen Open;
|
||||
psListenerOpenLocal OpenLocal;
|
||||
psListenerGetFileDescriptor GetFileDescriptor;
|
||||
psListenerGetEventHandles GetEventHandles;
|
||||
psListenerCheckFileDescriptor CheckFileDescriptor;
|
||||
psListenerClose Close;
|
||||
|
||||
|
@ -156,7 +156,9 @@ static BOOL freerdp_listener_open(freerdp_listener* instance, const char* bind_a
|
||||
continue;
|
||||
}
|
||||
|
||||
listener->sockfds[listener->num_sockfds++] = sockfd;
|
||||
listener->sockfds[listener->num_sockfds] = sockfd;
|
||||
listener->events[listener->num_sockfds] = CreateFileDescriptorEvent(NULL, FALSE, FALSE, sockfd);
|
||||
listener->num_sockfds++;
|
||||
|
||||
if (ai->ai_family == AF_INET)
|
||||
sin_addr = &(((struct sockaddr_in*) ai->ai_addr)->sin_addr);
|
||||
@ -211,7 +213,9 @@ static BOOL freerdp_listener_open_local(freerdp_listener* instance, const char*
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
listener->sockfds[listener->num_sockfds++] = sockfd;
|
||||
listener->sockfds[listener->num_sockfds] = sockfd;
|
||||
listener->events[listener->num_sockfds] = CreateFileDescriptorEvent(NULL, FALSE, FALSE, sockfd);
|
||||
listener->num_sockfds++;
|
||||
|
||||
fprintf(stderr, "Listening on socket %s.\n", addr.sun_path);
|
||||
|
||||
@ -237,21 +241,38 @@ static void freerdp_listener_close(freerdp_listener* instance)
|
||||
|
||||
static BOOL freerdp_listener_get_fds(freerdp_listener* instance, void** rfds, int* rcount)
|
||||
{
|
||||
int i;
|
||||
int index;
|
||||
rdpListener* listener = (rdpListener*) instance->listener;
|
||||
|
||||
if (listener->num_sockfds < 1)
|
||||
return FALSE;
|
||||
|
||||
for (i = 0; i < listener->num_sockfds; i++)
|
||||
for (index = 0; index < listener->num_sockfds; index++)
|
||||
{
|
||||
rfds[*rcount] = (void*)(long)(listener->sockfds[i]);
|
||||
rfds[*rcount] = (void*)(long)(listener->sockfds[index]);
|
||||
(*rcount)++;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int freerdp_listener_get_event_handles(freerdp_listener* instance, HANDLE* events, DWORD* nCount)
|
||||
{
|
||||
int index;
|
||||
rdpListener* listener = (rdpListener*) instance->listener;
|
||||
|
||||
if (listener->num_sockfds < 1)
|
||||
return -1;
|
||||
|
||||
for (index = 0; index < listener->num_sockfds; index++)
|
||||
{
|
||||
events[*nCount] = listener->events[index];
|
||||
(*nCount)++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static BOOL freerdp_listener_check_fds(freerdp_listener* instance)
|
||||
{
|
||||
int i;
|
||||
@ -327,6 +348,7 @@ freerdp_listener* freerdp_listener_new(void)
|
||||
instance->Open = freerdp_listener_open;
|
||||
instance->OpenLocal = freerdp_listener_open_local;
|
||||
instance->GetFileDescriptor = freerdp_listener_get_fds;
|
||||
instance->GetEventHandles = freerdp_listener_get_event_handles;
|
||||
instance->CheckFileDescriptor = freerdp_listener_check_fds;
|
||||
instance->Close = freerdp_listener_close;
|
||||
|
||||
|
@ -23,14 +23,21 @@
|
||||
typedef struct rdp_listener rdpListener;
|
||||
|
||||
#include "rdp.h"
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/synch.h>
|
||||
|
||||
#include <freerdp/listener.h>
|
||||
|
||||
#define MAX_LISTENER_HANDLES 5
|
||||
|
||||
struct rdp_listener
|
||||
{
|
||||
freerdp_listener* instance;
|
||||
|
||||
int sockfds[5];
|
||||
int num_sockfds;
|
||||
int sockfds[MAX_LISTENER_HANDLES];
|
||||
HANDLE events[MAX_LISTENER_HANDLES];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user