Skip to content

Commit c96c5ab

Browse files
committed
Merge 1.5.5 changes back to master.
2 parents 14ca1b1 + 06a9aa9 commit c96c5ab

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/libguac/guacamole/socket-ssl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "socket-types.h"
3232

3333
#include <openssl/ssl.h>
34+
#include <pthread.h>
3435

3536
/**
3637
* SSL socket-specific data.
@@ -54,6 +55,12 @@ typedef struct guac_socket_ssl_data {
5455
*/
5556
SSL* ssl;
5657

58+
/**
59+
* Lock that is acquired when an instruction is being written, and released
60+
* when the instruction is finished being written.
61+
*/
62+
pthread_mutex_t socket_lock;
63+
5764
} guac_socket_ssl_data;
5865

5966
/**

src/libguac/socket-ssl.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "guacamole/socket.h"
2626
#include "wait-fd.h"
2727

28+
#include <pthread.h>
2829
#include <stdlib.h>
2930

3031
#include <openssl/ssl.h>
@@ -97,10 +98,42 @@ static int __guac_socket_ssl_free_handler(guac_socket* socket) {
9798
/* Close file descriptor */
9899
close(data->fd);
99100

101+
pthread_mutex_destroy(&(data->socket_lock));
102+
100103
guac_mem_free(data);
101104
return 0;
102105
}
103106

107+
/**
108+
* Acquires exclusive access to the given socket.
109+
*
110+
* @param socket
111+
* The guac_socket to which exclusive access is requested.
112+
*/
113+
static void __guac_socket_ssl_lock_handler(guac_socket* socket) {
114+
115+
guac_socket_ssl_data* data = (guac_socket_ssl_data*) socket->data;
116+
117+
/* Acquire exclusive access to the socket */
118+
pthread_mutex_lock(&(data->socket_lock));
119+
120+
}
121+
122+
/**
123+
* Releases exclusive access to the given socket.
124+
*
125+
* @param socket
126+
* The guac_socket to which exclusive access is released.
127+
*/
128+
static void __guac_socket_ssl_unlock_handler(guac_socket* socket) {
129+
130+
guac_socket_ssl_data* data = (guac_socket_ssl_data*) socket->data;
131+
132+
/* Relinquish exclusive access to the socket */
133+
pthread_mutex_unlock(&(data->socket_lock));
134+
135+
}
136+
104137
guac_socket* guac_socket_open_secure(SSL_CTX* context, int fd) {
105138

106139
/* Create new SSL structure */
@@ -129,6 +162,11 @@ guac_socket* guac_socket_open_secure(SSL_CTX* context, int fd) {
129162
return NULL;
130163
}
131164

165+
pthread_mutexattr_t lock_attributes;
166+
pthread_mutexattr_init(&lock_attributes);
167+
pthread_mutexattr_setpshared(&lock_attributes, PTHREAD_PROCESS_SHARED);
168+
pthread_mutex_init(&(data->socket_lock), &lock_attributes);
169+
132170
/* Store file descriptor as socket data */
133171
data->fd = fd;
134172
socket->data = data;
@@ -138,6 +176,8 @@ guac_socket* guac_socket_open_secure(SSL_CTX* context, int fd) {
138176
socket->write_handler = __guac_socket_ssl_write_handler;
139177
socket->select_handler = __guac_socket_ssl_select_handler;
140178
socket->free_handler = __guac_socket_ssl_free_handler;
179+
socket->lock_handler = __guac_socket_ssl_lock_handler;
180+
socket->unlock_handler = __guac_socket_ssl_unlock_handler;
141181

142182
return socket;
143183

0 commit comments

Comments
 (0)