libguac  0.6.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Data Structures | Functions
socket.h File Reference

Defines the guac_socket object and functionss for using and manipulating it. More...

#include <stdint.h>
#include <unistd.h>

Go to the source code of this file.

Data Structures

struct  guac_socket
 The core I/O object of Guacamole. More...

Functions

guac_socketguac_socket_open (int fd)
 Allocates and initializes a new guac_socket object with the given open file descriptor.
ssize_t guac_socket_write_int (guac_socket *socket, int64_t i)
 Writes the given unsigned int to the given guac_socket object.
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_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.
ssize_t guac_socket_flush_base64 (guac_socket *socket)
 Flushes the base64 buffer, writing padding characters as necessary.
ssize_t guac_socket_flush (guac_socket *socket)
 Flushes the write buffer.
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.
void guac_socket_close (guac_socket *socket)
 Frees resources allocated to the given guac_socket object.

Detailed Description

Defines the guac_socket object and functionss for using and manipulating it.

Function Documentation

void guac_socket_close ( guac_socket socket)

Frees resources allocated to the given guac_socket object.

Note that this implicitly flush all buffers, but will NOT close the associated file descriptor.

Parameters
socketThe guac_socket object to close.
ssize_t guac_socket_flush ( guac_socket socket)

Flushes the write buffer.

If an error occurs while writing, a non-zero value is returned, and guac_error is set appropriately.

Parameters
socketThe guac_socket object to flush
Returns
Zero on success, or non-zero if an error occurs during flush.
ssize_t guac_socket_flush_base64 ( guac_socket socket)

Flushes the base64 buffer, writing padding characters as necessary.

If an error occurs while writing, a non-zero value is returned, and guac_error is set appropriately.

Parameters
socketThe guac_socket object to flush
Returns
Zero on success, or non-zero if an error occurs during flush.
guac_socket* guac_socket_open ( int  fd)

Allocates and initializes a new guac_socket object with the given open file descriptor.

If an error occurs while allocating the guac_socket object, NULL is returned, and guac_error is set appropriately.

Parameters
fdAn open file descriptor that this guac_socket object should manage.
Returns
A newly allocated guac_socket object associated with the given file descriptor, or NULL if an error occurs while allocating the guac_socket object.
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.

If an error occurs while waiting, a negative value is returned, and guac_error is set appropriately.

If a timeout occurs while waiting, zero value is returned, and guac_error is set to GUAC_STATUS_INPUT_TIMEOUT.

Parameters
socketThe guac_socket object to wait for.
usec_timeoutThe maximum number of microseconds to wait for data, or -1 to potentially wait forever.
Returns
Positive on success, zero if the timeout elapsed and no data is available, negative on error.
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.

The data written may be buffered until the buffer is flushed automatically or manually. Beware that because base64 data is buffered on top of the write buffer already used, a call to guac_socket_flush_base64() must be made before non-base64 writes (or writes of an independent block of base64 data) can be made.

If an error occurs while writing, a non-zero value is returned, and guac_error is set appropriately.

Parameters
socketThe guac_socket object to write to.
bufA buffer containing the data to write.
countThe number of bytes to write.
Returns
Zero on success, or non-zero if an error occurs while writing.
ssize_t guac_socket_write_int ( guac_socket socket,
int64_t  i 
)

Writes the given unsigned int to the given guac_socket object.

The data written may be buffered until the buffer is flushed automatically or manually.

If an error occurs while writing, a non-zero value is returned, and guac_error is set appropriately.

Parameters
socketThe guac_socket object to write to.
iThe unsigned int to write.
Returns
Zero on success, or non-zero if an error occurs while writing.
ssize_t guac_socket_write_string ( guac_socket socket,
const char *  str 
)

Writes the given string to the given guac_socket object.

The data written may be buffered until the buffer is flushed automatically or manually. Note that if the string can contain characters used internally by the Guacamole protocol (commas, semicolons, or backslashes) it will need to be escaped.

If an error occurs while writing, a non-zero value is returned, and guac_error is set appropriately.

Parameters
socketThe guac_socket object to write to.
strThe string to write.
Returns
Zero on success, or non-zero if an error occurs while writing.