libguac  0.9.9
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 #ifndef _GUAC_SOCKET_H
24 #define _GUAC_SOCKET_H
25 
32 #include "socket-constants.h"
33 #include "socket-fntypes.h"
34 #include "socket-types.h"
35 #include "timestamp-types.h"
36 
37 #include <pthread.h>
38 #include <stdint.h>
39 #include <unistd.h>
40 
41 struct guac_socket {
42 
46  void* data;
47 
52 
59 
65 
70 
75 
81 
85  int __ready;
86 
91  int __ready_buf[3];
92 
96  int __written;
97 
102  char __out_buf[GUAC_SOCKET_OUTPUT_BUFFER_SIZE];
103 
108  char* __instructionbuf_unparsed_start;
109 
113  char* __instructionbuf_unparsed_end;
114 
120  char __instructionbuf[32768];
121 
126  int __threadsafe_instructions;
127 
132  pthread_mutex_t __instruction_write_lock;
133 
137  pthread_mutex_t __buffer_lock;
138 
142  int __keep_alive_enabled;
143 
147  pthread_t __keep_alive_thread;
148 
149 };
150 
159 
165 void guac_socket_free(guac_socket* socket);
166 
177 
188 
197 
205 
214 
223 
237 
252 guac_socket* guac_socket_nest(guac_socket* parent, int index);
253 
266 ssize_t guac_socket_write_int(guac_socket* socket, int64_t i);
267 
282 ssize_t guac_socket_write_string(guac_socket* socket, const char* str);
283 
300 ssize_t guac_socket_write_base64(guac_socket* socket, const void* buf, size_t count);
301 
314 ssize_t guac_socket_write(guac_socket* socket, const void* buf, size_t count);
315 
329 ssize_t guac_socket_read(guac_socket* socket, void* buf, size_t count);
330 
340 ssize_t guac_socket_flush_base64(guac_socket* socket);
341 
351 ssize_t guac_socket_flush(guac_socket* socket);
352 
369 int guac_socket_select(guac_socket* socket, int usec_timeout);
370 
371 #endif
372 
guac_socket_state
Possible current states of a guac_socket.
Definition: socket-types.h:41
guac_socket * guac_socket_nest(guac_socket *parent, int index)
Allocates and initializes a new guac_socket which writes all data via nest instructions to the given ...
ssize_t guac_socket_flush_base64(guac_socket *socket)
Flushes the base64 buffer, writing padding characters as necessary.
guac_socket_free_handler * free_handler
Handler which will be called when the socket is free'd (closed).
Definition: socket.h:69
Type definitions related to the guac_socket object.
void guac_socket_instruction_begin(guac_socket *socket)
Marks the beginning of a Guacamole protocol instruction.
Constants related to the guac_socket object.
#define GUAC_SOCKET_OUTPUT_BUFFER_SIZE
The number of bytes to buffer within each socket before flushing.
Definition: socket-constants.h:35
The core I/O object of Guacamole.
Definition: socket.h:41
void guac_socket_update_buffer_begin(guac_socket *socket)
Marks the beginning of a socket's buffer modification.
Function type definitions related to the guac_socket object.
void guac_socket_free(guac_socket *socket)
Frees the given guac_socket and all associated resources.
guac_socket * guac_socket_open(int fd)
Allocates and initializes a new guac_socket object with the given open file descriptor.
ssize_t guac_socket_write_string(guac_socket *socket, const char *str)
Writes the given string to the given guac_socket object.
ssize_t guac_socket_write_handler(guac_socket *socket, const void *buf, size_t count)
Generic write handler for socket write operations, modeled after the standard POSIX write() function...
Definition: socket-fntypes.h:59
guac_socket_write_handler * write_handler
Handler which will be called whenever data is written to this socket.
Definition: socket.h:58
ssize_t guac_socket_write_base64(guac_socket *socket, const void *buf, size_t count)
Writes the given binary data to the given guac_socket object as base64- encoded data.
void guac_socket_require_threadsafe(guac_socket *socket)
Declares that the given socket must behave in a threadsafe way.
guac_socket_state state
The current state of this guac_socket.
Definition: socket.h:74
void guac_socket_update_buffer_end(guac_socket *socket)
Marks the end of a socket's buffer modification.
ssize_t guac_socket_read(guac_socket *socket, void *buf, size_t count)
Attempts to read data from the socket, filling up to the specified number of bytes in the given buffe...
ssize_t guac_socket_write(guac_socket *socket, const void *buf, size_t count)
Writes the given data to the specified socket.
int64_t guac_timestamp
An arbitrary timestamp denoting a relative time value in milliseconds.
Definition: timestamp-types.h:37
guac_timestamp last_write_timestamp
The timestamp associated with the time the last block of data was written to this guac_socket...
Definition: socket.h:80
void guac_socket_instruction_end(guac_socket *socket)
Marks the end of a Guacamole protocol instruction.
guac_socket * guac_socket_alloc()
Allocates a new, completely blank guac_socket.
int guac_socket_select(guac_socket *socket, int usec_timeout)
Waits for input to be available on the given guac_socket object until the specified timeout elapses...
int guac_socket_free_handler(guac_socket *socket)
Generic handler for the closing of a socket, modeled after the standard POSIX close() function...
Definition: socket-fntypes.h:83
guac_socket_select_handler * select_handler
Handler which will be called whenever guac_socket_select is invoked on this socket.
Definition: socket.h:64
void guac_socket_require_keep_alive(guac_socket *socket)
Declares that the given socket must automatically send a keep-alive ping to ensure neither side of th...
ssize_t guac_socket_flush(guac_socket *socket)
Flushes the write buffer.
ssize_t guac_socket_write_int(guac_socket *socket, int64_t i)
Writes the given unsigned int to the given guac_socket object.
void * data
Arbitrary socket-specific data.
Definition: socket.h:46
int guac_socket_select_handler(guac_socket *socket, int usec_timeout)
Generic handler for socket select operations, similar to the POSIX select() function.
Definition: socket-fntypes.h:73
ssize_t guac_socket_read_handler(guac_socket *socket, void *buf, size_t count)
Generic read handler for socket read operations, modeled after the standard POSIX read() function...
Definition: socket-fntypes.h:46
guac_socket_read_handler * read_handler
Handler which will be called when data needs to be read from the socket.
Definition: socket.h:51
Type definitions related to Guacamole protocol timestamps.