25
25
#include "guacamole/socket.h"
26
26
#include "wait-fd.h"
27
27
28
+ #include <pthread.h>
28
29
#include <stdlib.h>
29
30
30
31
#include <openssl/ssl.h>
@@ -97,10 +98,42 @@ static int __guac_socket_ssl_free_handler(guac_socket* socket) {
97
98
/* Close file descriptor */
98
99
close (data -> fd );
99
100
101
+ pthread_mutex_destroy (& (data -> socket_lock ));
102
+
100
103
guac_mem_free (data );
101
104
return 0 ;
102
105
}
103
106
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
+
104
137
guac_socket * guac_socket_open_secure (SSL_CTX * context , int fd ) {
105
138
106
139
/* Create new SSL structure */
@@ -129,6 +162,11 @@ guac_socket* guac_socket_open_secure(SSL_CTX* context, int fd) {
129
162
return NULL ;
130
163
}
131
164
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
+
132
170
/* Store file descriptor as socket data */
133
171
data -> fd = fd ;
134
172
socket -> data = data ;
@@ -138,6 +176,8 @@ guac_socket* guac_socket_open_secure(SSL_CTX* context, int fd) {
138
176
socket -> write_handler = __guac_socket_ssl_write_handler ;
139
177
socket -> select_handler = __guac_socket_ssl_select_handler ;
140
178
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 ;
141
181
142
182
return socket ;
143
183
0 commit comments