libguac  0.9.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
socket.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 Glyptodon LLC
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 
24 #ifndef _GUAC_SOCKET_H
25 #define _GUAC_SOCKET_H
26 
33 #include "timestamp.h"
34 
35 #include <pthread.h>
36 #include <stdint.h>
37 #include <unistd.h>
38 
42 #define GUAC_SOCKET_OUTPUT_BUFFER_SIZE 8192
43 
48 #define GUAC_SOCKET_KEEP_ALIVE_INTERVAL 5000
49 
50 typedef struct guac_socket guac_socket;
51 
62 typedef ssize_t guac_socket_read_handler(guac_socket* socket,
63  void* buf, size_t count);
64 
75 typedef ssize_t guac_socket_write_handler(guac_socket* socket,
76  const void* buf, size_t count);
77 
89 typedef int guac_socket_select_handler(guac_socket* socket, int usec_timeout);
90 
100 
104 typedef enum guac_socket_state {
105 
110 
115 
117 
122 struct guac_socket {
123 
127  void* data;
128 
133 
140 
146 
151 
156 
162 
166  int __ready;
167 
172  int __ready_buf[3];
173 
177  int __written;
178 
183  char __out_buf[GUAC_SOCKET_OUTPUT_BUFFER_SIZE];
184 
189  char* __instructionbuf_unparsed_start;
190 
194  char* __instructionbuf_unparsed_end;
195 
201  char __instructionbuf[32768];
202 
207  int __threadsafe_instructions;
208 
213  pthread_mutex_t __instruction_write_lock;
214 
218  pthread_mutex_t __buffer_lock;
219 
223  int __keep_alive_enabled;
224 
228  pthread_t __keep_alive_thread;
229 
230 };
231 
240 
246 void guac_socket_free(guac_socket* socket);
247 
258 
269 
278 
286 
295 
304 
318 
333 guac_socket* guac_socket_nest(guac_socket* parent, int index);
334 
347 ssize_t guac_socket_write_int(guac_socket* socket, int64_t i);
348 
363 ssize_t guac_socket_write_string(guac_socket* socket, const char* str);
364 
381 ssize_t guac_socket_write_base64(guac_socket* socket, const void* buf, size_t count);
382 
395 ssize_t guac_socket_write(guac_socket* socket, const void* buf, size_t count);
396 
410 ssize_t guac_socket_read(guac_socket* socket, void* buf, size_t count);
411 
421 ssize_t guac_socket_flush_base64(guac_socket* socket);
422 
432 ssize_t guac_socket_flush(guac_socket* socket);
433 
450 int guac_socket_select(guac_socket* socket, int usec_timeout);
451 
452 #endif
453