Add pool and stream alloc/free.
This commit is contained in:
parent
cd23eac4ee
commit
31729bf62d
@ -45,6 +45,7 @@
|
|||||||
#include "layer.h"
|
#include "layer.h"
|
||||||
#include "pool.h"
|
#include "pool.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
#include "stream.h"
|
||||||
#include "timestamp.h"
|
#include "timestamp.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -352,18 +353,24 @@ struct guac_client {
|
|||||||
guac_client_log_handler* log_error_handler;
|
guac_client_log_handler* log_error_handler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pool of buffer indices. Buffers are simply layers with negative indices. Note that
|
* Pool of buffer indices. Buffers are simply layers with negative indices.
|
||||||
* because guac_pool always gives non-negative indices starting at 0, the output of
|
* Note that because guac_pool always gives non-negative indices starting
|
||||||
* this guac_pool will be adjusted.
|
* at 0, the output of this guac_pool will be adjusted.
|
||||||
*/
|
*/
|
||||||
guac_pool* __buffer_pool;
|
guac_pool* __buffer_pool;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pool of layer indices. Note that because guac_pool always gives non-negative indices
|
* Pool of layer indices. Note that because guac_pool always gives
|
||||||
* starting at 0, the output of this guac_pool will be adjusted.
|
* non-negative indices starting at 0, the output of this guac_pool will
|
||||||
|
* be adjusted.
|
||||||
*/
|
*/
|
||||||
guac_pool* __layer_pool;
|
guac_pool* __layer_pool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pool of stream indices.
|
||||||
|
*/
|
||||||
|
guac_pool* __stream_pool;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -488,6 +495,25 @@ void guac_client_free_buffer(guac_client* client, guac_layer* layer);
|
|||||||
*/
|
*/
|
||||||
void guac_client_free_layer(guac_client* client, guac_layer* layer);
|
void guac_client_free_layer(guac_client* client, guac_layer* layer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocates a new stream. An arbitrary index is automatically assigned
|
||||||
|
* if no previously-allocated stream is available for use.
|
||||||
|
*
|
||||||
|
* @param client The proxy client to allocate the layer buffer for.
|
||||||
|
* @return The next available stream, or a newly allocated stream.
|
||||||
|
*/
|
||||||
|
guac_stream* guac_client_alloc_stream(guac_client* client);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the given stream to the pool of available streams, such that it
|
||||||
|
* can be reused by any subsequent call to guac_client_alloc_stream().
|
||||||
|
*
|
||||||
|
* @param client The proxy client to return the buffer to.
|
||||||
|
* @param stream The stream to return to the pool of available stream.
|
||||||
|
*/
|
||||||
|
void guac_client_free_stream(guac_client* client, guac_stream* stream);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default Guacamole client layer, layer 0.
|
* The default Guacamole client layer, layer 0.
|
||||||
*/
|
*/
|
||||||
|
@ -88,13 +88,33 @@ void guac_client_free_buffer(guac_client* client, guac_layer* layer) {
|
|||||||
void guac_client_free_layer(guac_client* client, guac_layer* layer) {
|
void guac_client_free_layer(guac_client* client, guac_layer* layer) {
|
||||||
|
|
||||||
/* Release index to pool */
|
/* Release index to pool */
|
||||||
guac_pool_free_int(client->__layer_pool, layer->index - 1);
|
guac_pool_free_int(client->__layer_pool, layer->index);
|
||||||
|
|
||||||
/* Free layer */
|
/* Free layer */
|
||||||
free(layer);
|
free(layer);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
guac_stream* guac_client_alloc_stream(guac_client* client) {
|
||||||
|
|
||||||
|
/* Init new stream */
|
||||||
|
guac_stream* allocd_stream = malloc(sizeof(guac_stream));
|
||||||
|
allocd_stream->index = guac_pool_next_int(client->__stream_pool);
|
||||||
|
|
||||||
|
return allocd_stream;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void guac_client_free_stream(guac_client* client, guac_stream* stream) {
|
||||||
|
|
||||||
|
/* Release index to pool */
|
||||||
|
guac_pool_free_int(client->__stream_pool, stream->index - 1);
|
||||||
|
|
||||||
|
/* Free stream */
|
||||||
|
free(stream);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
guac_client* guac_client_alloc() {
|
guac_client* guac_client_alloc() {
|
||||||
|
|
||||||
/* Allocate new client */
|
/* Allocate new client */
|
||||||
@ -117,6 +137,9 @@ guac_client* guac_client_alloc() {
|
|||||||
client->__buffer_pool = guac_pool_alloc(GUAC_BUFFER_POOL_INITIAL_SIZE);
|
client->__buffer_pool = guac_pool_alloc(GUAC_BUFFER_POOL_INITIAL_SIZE);
|
||||||
client->__layer_pool = guac_pool_alloc(GUAC_BUFFER_POOL_INITIAL_SIZE);
|
client->__layer_pool = guac_pool_alloc(GUAC_BUFFER_POOL_INITIAL_SIZE);
|
||||||
|
|
||||||
|
/* Allocate stream pool */
|
||||||
|
client->__stream_pool = guac_pool_alloc(0);
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user