Skip to content

Commit 72659d0

Browse files
committed
guacamole: remove keep alive thread
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
1 parent fc47abc commit 72659d0

File tree

6 files changed

+0
-100
lines changed

6 files changed

+0
-100
lines changed

guacamole/src/libguac/guacamole/protocol.h

-12
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,6 @@ int guac_protocol_send_error(guac_socket* socket, const char* error,
120120
int guac_protocol_send_mouse(guac_socket* socket, int x, int y,
121121
int button_mask, guac_timestamp timestamp);
122122

123-
/**
124-
* Sends a nop instruction (null-operation) over the given guac_socket
125-
* connection.
126-
*
127-
* If an error occurs sending the instruction, a non-zero value is
128-
* returned, and guac_error is set appropriately.
129-
*
130-
* @param socket The guac_socket connection to use.
131-
* @return Zero on success, non-zero on error.
132-
*/
133-
int guac_protocol_send_nop(guac_socket* socket);
134-
135123
/**
136124
* Sends a sync instruction over the given guac_socket connection. The
137125
* current time in milliseconds should be passed in as the timestamp.

guacamole/src/libguac/guacamole/socket-constants.h

-6
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,5 @@
3131
*/
3232
#define GUAC_SOCKET_OUTPUT_BUFFER_SIZE 8192
3333

34-
/**
35-
* The number of milliseconds to wait between keep-alive pings on a socket
36-
* with keep-alive enabled.
37-
*/
38-
#define GUAC_SOCKET_KEEP_ALIVE_INTERVAL 5000
39-
4034
#endif
4135

guacamole/src/libguac/guacamole/socket.h

-19
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,6 @@ struct guac_socket {
103103
*/
104104
int __ready_buf[3];
105105

106-
/**
107-
* Whether automatic keep-alive is enabled.
108-
*/
109-
int __keep_alive_enabled;
110-
111-
/**
112-
* The keep-alive thread.
113-
*/
114-
pthread_t __keep_alive_thread;
115-
116106
};
117107

118108
/**
@@ -131,15 +121,6 @@ guac_socket* guac_socket_alloc();
131121
*/
132122
void guac_socket_free(guac_socket* socket);
133123

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

144125
/**
145126
* Marks the beginning of a Guacamole protocol instruction.

guacamole/src/libguac/protocol.c

-12
Original file line numberDiff line numberDiff line change
@@ -420,18 +420,6 @@ int guac_protocol_send_name(guac_socket* socket, const char* name) {
420420

421421
}
422422

423-
int guac_protocol_send_nop(guac_socket* socket) {
424-
425-
int ret_val;
426-
427-
guac_socket_instruction_begin(socket);
428-
ret_val = guac_socket_write_string(socket, "3.nop;");
429-
guac_socket_instruction_end(socket);
430-
431-
return ret_val;
432-
433-
}
434-
435423
int guac_protocol_send_pipe(guac_socket* socket, const guac_stream* stream,
436424
const char* mimetype, const char* name) {
437425

guacamole/src/libguac/socket.c

-48
Original file line numberDiff line numberDiff line change
@@ -42,38 +42,6 @@ char __guac_socket_BASE64_CHARACTERS[64] = {
4242
'8', '9', '+', '/'
4343
};
4444

45-
static void* __guac_socket_keep_alive_thread(void* data) {
46-
47-
/* Calculate sleep interval */
48-
struct timespec interval;
49-
interval.tv_sec = GUAC_SOCKET_KEEP_ALIVE_INTERVAL / 1000;
50-
interval.tv_nsec = (GUAC_SOCKET_KEEP_ALIVE_INTERVAL % 1000) * 1000000L;
51-
52-
/* Socket keep-alive loop */
53-
guac_socket* socket = (guac_socket*) data;
54-
while (socket->state == GUAC_SOCKET_OPEN) {
55-
56-
/* Send NOP keep-alive if it's been a while since the last output */
57-
guac_timestamp timestamp = guac_timestamp_current();
58-
if (timestamp - socket->last_write_timestamp >
59-
GUAC_SOCKET_KEEP_ALIVE_INTERVAL) {
60-
61-
/* Send NOP */
62-
if (guac_protocol_send_nop(socket)
63-
|| guac_socket_flush(socket))
64-
break;
65-
66-
}
67-
68-
/* Sleep until next keep-alive check */
69-
nanosleep(&interval, NULL);
70-
71-
}
72-
73-
return NULL;
74-
75-
}
76-
7745
static ssize_t __guac_socket_write(guac_socket* socket,
7846
const void* buf, size_t count) {
7947

@@ -150,9 +118,6 @@ guac_socket* guac_socket_alloc() {
150118
socket->state = GUAC_SOCKET_OPEN;
151119
socket->last_write_timestamp = guac_timestamp_current();
152120

153-
/* No keep alive ping by default */
154-
socket->__keep_alive_enabled = 0;
155-
156121
/* No handlers yet */
157122
socket->read_handler = NULL;
158123
socket->write_handler = NULL;
@@ -166,15 +131,6 @@ guac_socket* guac_socket_alloc() {
166131

167132
}
168133

169-
void guac_socket_require_keep_alive(guac_socket* socket) {
170-
171-
/* Start keep-alive thread */
172-
socket->__keep_alive_enabled = 1;
173-
pthread_create(&(socket->__keep_alive_thread), NULL,
174-
__guac_socket_keep_alive_thread, (void*) socket);
175-
176-
}
177-
178134
void guac_socket_instruction_begin(guac_socket* socket) {
179135

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

205-
/* Wait for keep-alive, if enabled */
206-
if (socket->__keep_alive_enabled)
207-
pthread_join(socket->__keep_alive_thread, NULL);
208-
209161
free(socket);
210162
}
211163

guacamole/src/protocols/vnc/vnc.c

-3
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,6 @@ void* guac_vnc_client_thread(void* data) {
164164
"clipboard encoding: '%s'.", settings->clipboard_encoding);
165165
}
166166

167-
/* Ensure connection is kept alive during lengthy connects */
168-
guac_socket_require_keep_alive(client->socket);
169-
170167
/* Set up libvncclient logging */
171168
rfbClientLog = guac_vnc_client_log_info;
172169
rfbClientErr = guac_vnc_client_log_error;

0 commit comments

Comments
 (0)