Move pipes to terminal scope.

This commit is contained in:
Michael Jumper 2013-05-21 22:02:11 -07:00
parent 225377f197
commit 5a0b8b2ea7
6 changed files with 49 additions and 41 deletions

View File

@ -79,16 +79,6 @@ typedef struct ssh_guac_client_data {
*/
int mouse_mask;
/**
* Pipe which will be used to provide STDOUT to the SSH client.
*/
int stdout_pipe_fd[2];
/**
* Pipe which will be used to provide STDIN to the SSH client.
*/
int stdin_pipe_fd[2];
/**
* The cached I-bar cursor.
*/

View File

@ -75,6 +75,22 @@ struct guac_terminal {
*/
pthread_mutex_t lock;
/**
* Pipe which should be written to (and read from) to provide output to
* this terminal. Another thread should read from this pipe when writing
* data to the terminal. It would make sense for the terminal to provide
* this thread, but for simplicity, that logic is left to the guac
* message handler (to give the message handler something to block with).
*/
int stdout_pipe_fd[2];
/**
* Pipe which will be the source of user input. When a terminal code
* generates synthesized user input, that data will be written to
* this pipe.
*/
int stdin_pipe_fd[2];
/**
* The relative offset of the display. A positive value indicates that
* many rows have been scrolled into view, zero indicates that no

View File

@ -101,20 +101,6 @@ int guac_client_init(guac_client* client, int argc, char** argv) {
guac_socket_flush(socket);
/* Open STDOUT pipe */
if (pipe(client_data->stdout_pipe_fd)) {
guac_error = GUAC_STATUS_SEE_ERRNO;
guac_error_message = "Unable to open pipe for STDOUT";
return 1;
}
/* Open STDIN pipe */
if (pipe(client_data->stdin_pipe_fd)) {
guac_error = GUAC_STATUS_SEE_ERRNO;
guac_error_message = "Unable to open pipe for STDIN";
return 1;
}
/* Set basic handlers */
client->handle_messages = ssh_guac_client_handle_messages;
client->clipboard_handler = ssh_guac_client_clipboard_handler;

View File

@ -61,7 +61,7 @@ int ssh_guac_client_handle_messages(guac_client* client) {
char buffer[8192];
int ret_val;
int fd = client_data->stdout_pipe_fd[0];
int fd = client_data->term->stdout_pipe_fd[0];
struct timeval timeout;
fd_set fds;
@ -158,7 +158,7 @@ int ssh_guac_client_mouse_handler(guac_client* client, int x, int y, int mask) {
int length = strlen(client_data->clipboard_data);
if (length)
return write(client_data->stdin_pipe_fd[1],
return write(term->stdin_pipe_fd[1],
client_data->clipboard_data, length);
}
@ -229,7 +229,7 @@ int ssh_guac_client_key_handler(guac_client* client, int keysym, int pressed) {
guac_terminal* term = client_data->term;
/* Get write end of STDIN pipe */
int fd = client_data->stdin_pipe_fd[1];
int fd = term->stdin_pipe_fd[1];
/* Hide mouse cursor if not already hidden */
if (client_data->current_cursor != client_data->blank_cursor) {
@ -354,18 +354,9 @@ int ssh_guac_client_free_handler(guac_client* client) {
ssh_guac_client_data* guac_client_data = (ssh_guac_client_data*) client->data;
/* Close terminal output pipe */
close(guac_client_data->stdout_pipe_fd[1]);
close(guac_client_data->stdout_pipe_fd[0]);
/* Close user input pipe */
close(guac_client_data->stdin_pipe_fd[1]);
close(guac_client_data->stdin_pipe_fd[0]);
pthread_join(guac_client_data->client_thread, NULL);
/* Free terminal */
guac_terminal_free(guac_client_data->term);
pthread_join(guac_client_data->client_thread, NULL);
/* Free clipboard data */
free(guac_client_data->clipboard_data);

View File

@ -81,8 +81,8 @@ static char* prompt(guac_client* client, const char* title, char* str, int size,
char in_byte;
/* Get STDIN and STDOUT */
int stdin_fd = client_data->stdin_pipe_fd[0];
int stdout_fd = client_data->stdout_pipe_fd[1];
int stdin_fd = client_data->term->stdin_pipe_fd[0];
int stdout_fd = client_data->term->stdout_pipe_fd[1];
/* Print title */
__write_all(stdout_fd, title, strlen(title));
@ -137,7 +137,7 @@ void* ssh_input_thread(void* data) {
char buffer[8192];
int bytes_read;
int stdin_fd = client_data->stdin_pipe_fd[0];
int stdin_fd = client_data->term->stdin_pipe_fd[0];
/* Write all data read */
while ((bytes_read = read(stdin_fd, buffer, sizeof(buffer))) > 0)
@ -156,7 +156,7 @@ void* ssh_client_thread(void* data) {
char buffer[8192];
int bytes_read = -1234;
int stdout_fd = client_data->stdout_pipe_fd[1];
int stdout_fd = client_data->term->stdout_pipe_fd[1];
pthread_t input_thread;

View File

@ -46,6 +46,7 @@
#include <guacamole/socket.h>
#include <guacamole/protocol.h>
#include <guacamole/client.h>
#include <guacamole/error.h>
#include "types.h"
#include "buffer.h"
@ -95,6 +96,22 @@ guac_terminal* guac_terminal_create(guac_client* client,
term->text_selected = false;
/* Open STDOUT pipe */
if (pipe(term->stdout_pipe_fd)) {
guac_error = GUAC_STATUS_SEE_ERRNO;
guac_error_message = "Unable to open pipe for STDOUT";
free(term);
return NULL;
}
/* Open STDIN pipe */
if (pipe(term->stdin_pipe_fd)) {
guac_error = GUAC_STATUS_SEE_ERRNO;
guac_error_message = "Unable to open pipe for STDIN";
free(term);
return NULL;
}
/* Size display */
guac_terminal_display_resize(term->display,
term->term_width, term->term_height);
@ -108,6 +125,14 @@ guac_terminal* guac_terminal_create(guac_client* client,
void guac_terminal_free(guac_terminal* term) {
/* Close terminal output pipe */
close(term->stdout_pipe_fd[1]);
close(term->stdout_pipe_fd[0]);
/* Close user input pipe */
close(term->stdin_pipe_fd[1]);
close(term->stdin_pipe_fd[0]);
/* Free display */
guac_terminal_display_free(term->display);