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 (*psListenerOpen)(freerdp_listener* instance, const char* bind_address, UINT16 port);
|
||||||
typedef BOOL (*psListenerOpenLocal)(freerdp_listener* instance, const char* path);
|
typedef BOOL (*psListenerOpenLocal)(freerdp_listener* instance, const char* path);
|
||||||
typedef BOOL (*psListenerGetFileDescriptor)(freerdp_listener* instance, void** rfds, int* rcount);
|
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 BOOL (*psListenerCheckFileDescriptor)(freerdp_listener* instance);
|
||||||
typedef void (*psListenerClose)(freerdp_listener* instance);
|
typedef void (*psListenerClose)(freerdp_listener* instance);
|
||||||
typedef void (*psPeerAccepted)(freerdp_listener* instance, freerdp_peer* client);
|
typedef void (*psPeerAccepted)(freerdp_listener* instance, freerdp_peer* client);
|
||||||
@ -50,6 +51,7 @@ struct rdp_freerdp_listener
|
|||||||
psListenerOpen Open;
|
psListenerOpen Open;
|
||||||
psListenerOpenLocal OpenLocal;
|
psListenerOpenLocal OpenLocal;
|
||||||
psListenerGetFileDescriptor GetFileDescriptor;
|
psListenerGetFileDescriptor GetFileDescriptor;
|
||||||
|
psListenerGetEventHandles GetEventHandles;
|
||||||
psListenerCheckFileDescriptor CheckFileDescriptor;
|
psListenerCheckFileDescriptor CheckFileDescriptor;
|
||||||
psListenerClose Close;
|
psListenerClose Close;
|
||||||
|
|
||||||
|
@ -156,7 +156,9 @@ static BOOL freerdp_listener_open(freerdp_listener* instance, const char* bind_a
|
|||||||
continue;
|
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)
|
if (ai->ai_family == AF_INET)
|
||||||
sin_addr = &(((struct sockaddr_in*) ai->ai_addr)->sin_addr);
|
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;
|
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);
|
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)
|
static BOOL freerdp_listener_get_fds(freerdp_listener* instance, void** rfds, int* rcount)
|
||||||
{
|
{
|
||||||
int i;
|
int index;
|
||||||
rdpListener* listener = (rdpListener*) instance->listener;
|
rdpListener* listener = (rdpListener*) instance->listener;
|
||||||
|
|
||||||
if (listener->num_sockfds < 1)
|
if (listener->num_sockfds < 1)
|
||||||
return FALSE;
|
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)++;
|
(*rcount)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
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)
|
static BOOL freerdp_listener_check_fds(freerdp_listener* instance)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -327,6 +348,7 @@ freerdp_listener* freerdp_listener_new(void)
|
|||||||
instance->Open = freerdp_listener_open;
|
instance->Open = freerdp_listener_open;
|
||||||
instance->OpenLocal = freerdp_listener_open_local;
|
instance->OpenLocal = freerdp_listener_open_local;
|
||||||
instance->GetFileDescriptor = freerdp_listener_get_fds;
|
instance->GetFileDescriptor = freerdp_listener_get_fds;
|
||||||
|
instance->GetEventHandles = freerdp_listener_get_event_handles;
|
||||||
instance->CheckFileDescriptor = freerdp_listener_check_fds;
|
instance->CheckFileDescriptor = freerdp_listener_check_fds;
|
||||||
instance->Close = freerdp_listener_close;
|
instance->Close = freerdp_listener_close;
|
||||||
|
|
||||||
|
@ -23,14 +23,21 @@
|
|||||||
typedef struct rdp_listener rdpListener;
|
typedef struct rdp_listener rdpListener;
|
||||||
|
|
||||||
#include "rdp.h"
|
#include "rdp.h"
|
||||||
|
|
||||||
|
#include <winpr/crt.h>
|
||||||
|
#include <winpr/synch.h>
|
||||||
|
|
||||||
#include <freerdp/listener.h>
|
#include <freerdp/listener.h>
|
||||||
|
|
||||||
|
#define MAX_LISTENER_HANDLES 5
|
||||||
|
|
||||||
struct rdp_listener
|
struct rdp_listener
|
||||||
{
|
{
|
||||||
freerdp_listener* instance;
|
freerdp_listener* instance;
|
||||||
|
|
||||||
int sockfds[5];
|
|
||||||
int num_sockfds;
|
int num_sockfds;
|
||||||
|
int sockfds[MAX_LISTENER_HANDLES];
|
||||||
|
HANDLE events[MAX_LISTENER_HANDLES];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user