libguac 1.5.5
Loading...
Searching...
No Matches
Data Structures | Functions
socket.h File Reference

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

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_alloc ()
 Allocates a new, completely blank guac_socket.
 
void guac_socket_free (guac_socket *socket)
 Frees the given guac_socket and all associated resources.
 
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 the socket times out while the socket is open.
 
void guac_socket_instruction_begin (guac_socket *socket)
 Marks the beginning of a Guacamole protocol instruction.
 
void guac_socket_instruction_end (guac_socket *socket)
 Marks the end of a Guacamole protocol instruction.
 
guac_socketguac_socket_open (int fd)
 Allocates and initializes a new guac_socket object with the given open file descriptor.
 
guac_socketguac_socket_nest (guac_socket *parent, int index)
 Allocates and initializes a new guac_socket which writes all data via nest instructions to the given existing, open guac_socket.
 
guac_socketguac_socket_tee (guac_socket *primary, guac_socket *secondary)
 Allocates and initializes a new guac_socket which delegates all socket operations to the given primary socket, while simultaneously duplicating all written data to the secondary socket.
 
guac_socketguac_socket_broadcast (guac_client *client)
 Allocates and initializes a new guac_socket which duplicates all instructions written across the sockets of each connected user of the given guac_client.
 
guac_socketguac_socket_broadcast_pending (guac_client *client)
 Allocates and initializes a new guac_socket which duplicates all instructions written across the sockets of each pending connected user of the given guac_client.
 
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_write (guac_socket *socket, const void *buf, size_t count)
 Writes the given data to the specified socket.
 
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 buffer.
 
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.
 

Detailed Description

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

Function Documentation

◆ guac_socket_alloc()

guac_socket * guac_socket_alloc ( )

Allocates a new, completely blank guac_socket.

This guac_socket will do absolutely nothing when used unless its handlers are defined.

Returns
A newly-allocated guac_socket, or NULL if the guac_socket could not be allocated.

◆ guac_socket_broadcast()

guac_socket * guac_socket_broadcast ( guac_client * client)

Allocates and initializes a new guac_socket which duplicates all instructions written across the sockets of each connected user of the given guac_client.

The returned socket is a write-only socket. Attempts to read from the socket will fail. If a write occurs while no users are connected, that write will simply be dropped.

Return values (error codes) from each user's socket will not affect the in-progress write, but each failing user will be forcibly stopped with guac_user_stop().

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

Parameters
clientThe client associated with the group of connected users across which duplicates of all instructions should be written.
Returns
A write-only guac_socket object which broadcasts copies of all instructions written across all non-pending connected users of the given guac_client, or NULL if an error occurs while allocating the guac_socket object.

◆ guac_socket_broadcast_pending()

guac_socket * guac_socket_broadcast_pending ( guac_client * client)

Allocates and initializes a new guac_socket which duplicates all instructions written across the sockets of each pending connected user of the given guac_client.

The returned socket is a write-only socket. Attempts to read from the socket will fail. If a write occurs while no users are connected, that write will simply be dropped.

Return values (error codes) from each user's socket will not affect the in-progress write, but each failing user will be forcibly stopped with guac_user_stop().

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

Parameters
clientThe client associated with the group of pending users across which duplicates of all instructions should be written.
Returns
A write-only guac_socket object which broadcasts copies of all instructions written across all pending connected users of the given guac_client, or NULL if an error occurs while allocating the guac_socket object.

◆ guac_socket_flush()

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.

◆ guac_socket_flush_base64()

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_free()

void guac_socket_free ( guac_socket * socket)

Frees the given guac_socket and all associated resources.

Parameters
socketThe guac_socket to free.

◆ guac_socket_instruction_begin()

void guac_socket_instruction_begin ( guac_socket * socket)

Marks the beginning of a Guacamole protocol instruction.

Parameters
socketThe guac_socket beginning an instruction.

◆ guac_socket_instruction_end()

void guac_socket_instruction_end ( guac_socket * socket)

Marks the end of a Guacamole protocol instruction.

Parameters
socketThe guac_socket ending an instruction.

◆ guac_socket_nest()

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 existing, open guac_socket.

Freeing the returned guac_socket has no effect on the underlying, nested guac_socket.

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

Deprecated
The "nest" instruction and the corresponding guac_socket implementation are no longer necessary, having been replaced by the streaming instructions ("blob", "ack", "end"). Code using nested sockets or the "nest" instruction should instead write to a normal socket directly.
Parameters
parentThe guac_socket this new guac_socket should write nest instructions to.
indexThe stream index to use for the written nest instructions.
Returns
A newly allocated guac_socket object associated with the given guac_socket and stream index, or NULL if an error occurs while allocating the guac_socket object.

◆ guac_socket_open()

guac_socket * guac_socket_open ( int fd)

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

The file descriptor will be automatically closed when the allocated guac_socket is freed.

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.

◆ guac_socket_read()

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 buffer.

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

Parameters
socketThe guac_socket to read from.
bufThe buffer to read bytes into.
countThe maximum number of bytes to read.
Returns
The number of bytes read, or non-zero if an error occurs while reading.

◆ guac_socket_require_keep_alive()

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 the socket times out while the socket is open.

This ping will take the form of a "nop" instruction.

Parameters
socketThe guac_socket to declare as requiring an automatic keep-alive ping.

◆ guac_socket_select()

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.

◆ guac_socket_tee()

guac_socket * guac_socket_tee ( guac_socket * primary,
guac_socket * secondary )

Allocates and initializes a new guac_socket which delegates all socket operations to the given primary socket, while simultaneously duplicating all written data to the secondary socket.

Freeing the returned guac_socket will free both primary and secondary sockets.

Return values (error codes) will come only from the primary socket. Locks (like those used by guac_socket_instruction_begin() and guac_socket_instruction_end()) will affect only the primary socket.

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

Parameters
primaryThe primary guac_socket to which all socket operations should be delegated. The error codes returned by socket operations, if any, will always come from this socket. This socket will also be the only socket locked when instructions begin (or unlocked when instructions end).
secondaryThe secondary guac_socket to which all data written to the primary guac_socket should be copied. If an error prevents the write from succeeding, that error will be ignored. Only errors from the primary guac_socket will be acknowledged.
Returns
A newly allocated guac_socket object associated with the given primary and secondary sockets, or NULL if an error occurs while allocating the guac_socket object.

◆ guac_socket_write()

ssize_t guac_socket_write ( guac_socket * socket,
const void * buf,
size_t count )

Writes the given data to the specified socket.

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.
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.

◆ guac_socket_write_base64()

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.

◆ guac_socket_write_int()

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.

◆ guac_socket_write_string()

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.

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.