GUACAMOLE-249: Migrate wait mechanism to event handle interface.
This commit is contained in:
parent
17045d5d3a
commit
b89ed7ff15
@ -380,78 +380,30 @@ static int rdp_guac_client_wait_for_messages(guac_client* client,
|
|||||||
|
|
||||||
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
|
||||||
freerdp* rdp_inst = rdp_client->rdp_inst;
|
freerdp* rdp_inst = rdp_client->rdp_inst;
|
||||||
rdpChannels* channels = rdp_inst->context->channels;
|
|
||||||
|
|
||||||
int result;
|
HANDLE handles[GUAC_RDP_MAX_FILE_DESCRIPTORS];
|
||||||
int index;
|
int num_handles = freerdp_get_event_handles(rdp_inst->context, handles,
|
||||||
|
GUAC_RDP_MAX_FILE_DESCRIPTORS);
|
||||||
|
|
||||||
/* List of all file descriptors which we may read data from */
|
/* Wait for data and construct a reasonable frame */
|
||||||
void* read_fds[GUAC_RDP_MAX_FILE_DESCRIPTORS];
|
int result = WaitForMultipleObjects(num_handles, handles, FALSE,
|
||||||
int read_count = 0;
|
timeout_msecs);
|
||||||
|
|
||||||
/* List of all file descriptors which data may be written to. These will
|
/* Translate WaitForMultipleObjects() return values */
|
||||||
* ultimately be ignored, but FreeRDP requires that both read and write
|
switch (result) {
|
||||||
* file descriptors be retrieved simultaneously. */
|
|
||||||
void* write_fds[GUAC_RDP_MAX_FILE_DESCRIPTORS];
|
|
||||||
int write_count = 0;
|
|
||||||
|
|
||||||
struct pollfd fds[GUAC_RDP_MAX_FILE_DESCRIPTORS];
|
/* Timeout elapsed before wait could complete */
|
||||||
|
case WAIT_TIMEOUT:
|
||||||
/* Get RDP file descriptors */
|
|
||||||
if (!freerdp_get_fds(rdp_inst, read_fds, &read_count,
|
|
||||||
write_fds, &write_count)) {
|
|
||||||
guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR,
|
|
||||||
"Unable to read RDP file descriptors.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Get RDP channel file descriptors */
|
|
||||||
if (!freerdp_channels_get_fds(channels, rdp_inst, read_fds, &read_count,
|
|
||||||
write_fds, &write_count)) {
|
|
||||||
guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR,
|
|
||||||
"Unable to read RDP channel file descriptors.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If no file descriptors, error */
|
|
||||||
if (read_count == 0) {
|
|
||||||
guac_client_abort(client, GUAC_PROTOCOL_STATUS_SERVER_ERROR,
|
|
||||||
"No file descriptors associated with RDP connection.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Populate poll() array of read file descriptors */
|
|
||||||
for (index = 0; index < read_count; index++) {
|
|
||||||
|
|
||||||
struct pollfd* current = &fds[index];
|
|
||||||
|
|
||||||
/* Init poll() array element with RDP file descriptor */
|
|
||||||
current->fd = (int)(long) (read_fds[index]);
|
|
||||||
current->events = POLLIN;
|
|
||||||
current->revents = 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait until data can be read from RDP file descriptors */
|
|
||||||
result = poll(fds, read_count, timeout_msecs);
|
|
||||||
if (result < 0) {
|
|
||||||
|
|
||||||
/* If error ignorable, pretend timout occurred */
|
|
||||||
if (errno == EAGAIN
|
|
||||||
|| errno == EWOULDBLOCK
|
|
||||||
|| errno == EINPROGRESS
|
|
||||||
|| errno == EINTR)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Otherwise, return as error */
|
/* Attempt to wait failed due to an error */
|
||||||
guac_client_abort(client, GUAC_PROTOCOL_STATUS_UPSTREAM_UNAVAILABLE,
|
case WAIT_FAILED:
|
||||||
"Error waiting for file descriptor.");
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return wait result */
|
/* Wait was successful */
|
||||||
return result;
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -535,7 +487,6 @@ static int guac_rdp_handle_connection(guac_client* client) {
|
|||||||
|
|
||||||
/* Connection complete */
|
/* Connection complete */
|
||||||
rdp_client->rdp_inst = rdp_inst;
|
rdp_client->rdp_inst = rdp_inst;
|
||||||
rdpChannels* channels = rdp_inst->context->channels;
|
|
||||||
|
|
||||||
guac_timestamp last_frame_end = guac_timestamp_current();
|
guac_timestamp last_frame_end = guac_timestamp_current();
|
||||||
|
|
||||||
@ -568,8 +519,7 @@ static int guac_rdp_handle_connection(guac_client* client) {
|
|||||||
pthread_mutex_lock(&(rdp_client->rdp_lock));
|
pthread_mutex_lock(&(rdp_client->rdp_lock));
|
||||||
|
|
||||||
/* Check the libfreerdp fds */
|
/* Check the libfreerdp fds */
|
||||||
if (!freerdp_check_fds(rdp_inst)
|
if (!freerdp_check_event_handles(rdp_inst->context)) {
|
||||||
|| !freerdp_channels_check_fds(channels, rdp_inst)) {
|
|
||||||
|
|
||||||
/* Flag connection failure */
|
/* Flag connection failure */
|
||||||
wait_result = -1;
|
wait_result = -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user