Skip to content

Commit

Permalink
guacamole: remove keep alive thread
Browse files Browse the repository at this point in the history
This is because the connection is maintained by websocket, a keep alive thread is not necessary
anymore.

nop command can also be removed.

Update #3
  • Loading branch information
changkun committed Dec 7, 2021
1 parent fc47abc commit 72659d0
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 100 deletions.
12 changes: 0 additions & 12 deletions guacamole/src/libguac/guacamole/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,6 @@ int guac_protocol_send_error(guac_socket* socket, const char* error,
int guac_protocol_send_mouse(guac_socket* socket, int x, int y,
int button_mask, guac_timestamp timestamp);

/**
* Sends a nop instruction (null-operation) over the given guac_socket
* connection.
*
* If an error occurs sending the instruction, a non-zero value is
* returned, and guac_error is set appropriately.
*
* @param socket The guac_socket connection to use.
* @return Zero on success, non-zero on error.
*/
int guac_protocol_send_nop(guac_socket* socket);

/**
* Sends a sync instruction over the given guac_socket connection. The
* current time in milliseconds should be passed in as the timestamp.
Expand Down
6 changes: 0 additions & 6 deletions guacamole/src/libguac/guacamole/socket-constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,5 @@
*/
#define GUAC_SOCKET_OUTPUT_BUFFER_SIZE 8192

/**
* The number of milliseconds to wait between keep-alive pings on a socket
* with keep-alive enabled.
*/
#define GUAC_SOCKET_KEEP_ALIVE_INTERVAL 5000

#endif

19 changes: 0 additions & 19 deletions guacamole/src/libguac/guacamole/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,6 @@ struct guac_socket {
*/
int __ready_buf[3];

/**
* Whether automatic keep-alive is enabled.
*/
int __keep_alive_enabled;

/**
* The keep-alive thread.
*/
pthread_t __keep_alive_thread;

};

/**
Expand All @@ -131,15 +121,6 @@ guac_socket* guac_socket_alloc();
*/
void guac_socket_free(guac_socket* socket);

/**
* Declares that the given socket must automatically send a keep-alive ping
* to ensure neither side of the socket times out while the socket is open.
* This ping will take the form of a "nop" instruction.
*
* @param socket
* The guac_socket to declare as requiring an automatic keep-alive ping.
*/
void guac_socket_require_keep_alive(guac_socket* socket);

/**
* Marks the beginning of a Guacamole protocol instruction.
Expand Down
12 changes: 0 additions & 12 deletions guacamole/src/libguac/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,18 +420,6 @@ int guac_protocol_send_name(guac_socket* socket, const char* name) {

}

int guac_protocol_send_nop(guac_socket* socket) {

int ret_val;

guac_socket_instruction_begin(socket);
ret_val = guac_socket_write_string(socket, "3.nop;");
guac_socket_instruction_end(socket);

return ret_val;

}

int guac_protocol_send_pipe(guac_socket* socket, const guac_stream* stream,
const char* mimetype, const char* name) {

Expand Down
48 changes: 0 additions & 48 deletions guacamole/src/libguac/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,38 +42,6 @@ char __guac_socket_BASE64_CHARACTERS[64] = {
'8', '9', '+', '/'
};

static void* __guac_socket_keep_alive_thread(void* data) {

/* Calculate sleep interval */
struct timespec interval;
interval.tv_sec = GUAC_SOCKET_KEEP_ALIVE_INTERVAL / 1000;
interval.tv_nsec = (GUAC_SOCKET_KEEP_ALIVE_INTERVAL % 1000) * 1000000L;

/* Socket keep-alive loop */
guac_socket* socket = (guac_socket*) data;
while (socket->state == GUAC_SOCKET_OPEN) {

/* Send NOP keep-alive if it's been a while since the last output */
guac_timestamp timestamp = guac_timestamp_current();
if (timestamp - socket->last_write_timestamp >
GUAC_SOCKET_KEEP_ALIVE_INTERVAL) {

/* Send NOP */
if (guac_protocol_send_nop(socket)
|| guac_socket_flush(socket))
break;

}

/* Sleep until next keep-alive check */
nanosleep(&interval, NULL);

}

return NULL;

}

static ssize_t __guac_socket_write(guac_socket* socket,
const void* buf, size_t count) {

Expand Down Expand Up @@ -150,9 +118,6 @@ guac_socket* guac_socket_alloc() {
socket->state = GUAC_SOCKET_OPEN;
socket->last_write_timestamp = guac_timestamp_current();

/* No keep alive ping by default */
socket->__keep_alive_enabled = 0;

/* No handlers yet */
socket->read_handler = NULL;
socket->write_handler = NULL;
Expand All @@ -166,15 +131,6 @@ guac_socket* guac_socket_alloc() {

}

void guac_socket_require_keep_alive(guac_socket* socket) {

/* Start keep-alive thread */
socket->__keep_alive_enabled = 1;
pthread_create(&(socket->__keep_alive_thread), NULL,
__guac_socket_keep_alive_thread, (void*) socket);

}

void guac_socket_instruction_begin(guac_socket* socket) {

/* Call instruction begin handler if defined */
Expand Down Expand Up @@ -202,10 +158,6 @@ void guac_socket_free(guac_socket* socket) {
/* Mark as closed */
socket->state = GUAC_SOCKET_CLOSED;

/* Wait for keep-alive, if enabled */
if (socket->__keep_alive_enabled)
pthread_join(socket->__keep_alive_thread, NULL);

free(socket);
}

Expand Down
3 changes: 0 additions & 3 deletions guacamole/src/protocols/vnc/vnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ void* guac_vnc_client_thread(void* data) {
"clipboard encoding: '%s'.", settings->clipboard_encoding);
}

/* Ensure connection is kept alive during lengthy connects */
guac_socket_require_keep_alive(client->socket);

/* Set up libvncclient logging */
rfbClientLog = guac_vnc_client_log_info;
rfbClientErr = guac_vnc_client_log_error;
Expand Down

0 comments on commit 72659d0

Please sign in to comment.