Reindent server/core/buffer.c
This commit is contained in:
@ -56,8 +56,7 @@
|
||||
static HASHTABLE *buffer_hashtable = NULL;
|
||||
#endif
|
||||
|
||||
static buffer_object_t* gwbuf_remove_buffer_object(
|
||||
GWBUF* buf,
|
||||
static buffer_object_t* gwbuf_remove_buffer_object(GWBUF* buf,
|
||||
buffer_object_t* bufobj);
|
||||
|
||||
#if defined(BUFFER_TRACE)
|
||||
@ -81,13 +80,13 @@ static void gwbuf_remove_from_hashtable(GWBUF *buf);
|
||||
GWBUF *
|
||||
gwbuf_alloc(unsigned int size)
|
||||
{
|
||||
GWBUF *rval;
|
||||
SHARED_BUF *sbuf;
|
||||
GWBUF *rval;
|
||||
SHARED_BUF *sbuf;
|
||||
|
||||
/* Allocate the buffer header */
|
||||
if ((rval = (GWBUF *)malloc(sizeof(GWBUF))) == NULL)
|
||||
{
|
||||
goto retblock;;
|
||||
goto retblock;
|
||||
}
|
||||
|
||||
/* Allocate the shared data buffer */
|
||||
@ -150,8 +149,8 @@ gwbuf_add_to_hashtable(GWBUF *buf)
|
||||
char **strings;
|
||||
char *tracetext;
|
||||
|
||||
size = backtrace (array, 16);
|
||||
strings = backtrace_symbols (array, size);
|
||||
size = backtrace(array, 16);
|
||||
strings = backtrace_symbols(array, size);
|
||||
total = (2 * size) + 1;
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
@ -171,7 +170,7 @@ gwbuf_add_to_hashtable(GWBUF *buf)
|
||||
if (NULL == buffer_hashtable)
|
||||
{
|
||||
buffer_hashtable = hashtable_alloc(10000, bhashfn, bcmpfn);
|
||||
hashtable_memory_fns(buffer_hashtable,NULL,NULL,NULL,(HASHMEMORYFN)free);
|
||||
hashtable_memory_fns(buffer_hashtable, NULL, NULL, NULL, (HASHMEMORYFN)free);
|
||||
}
|
||||
hashtable_add(buffer_hashtable, buf, (void *)tracetext);
|
||||
}
|
||||
@ -240,9 +239,8 @@ dprintAllBuffers(void *pdcb)
|
||||
void
|
||||
gwbuf_free(GWBUF *buf)
|
||||
{
|
||||
BUF_PROPERTY *prop;
|
||||
|
||||
buffer_object_t* bo;
|
||||
BUF_PROPERTY *prop;
|
||||
buffer_object_t *bo;
|
||||
|
||||
CHK_GWBUF(buf);
|
||||
if (atomic_add(&buf->sbuf->refcount, -1) == 1)
|
||||
@ -291,7 +289,7 @@ BUF_PROPERTY *prop;
|
||||
GWBUF *
|
||||
gwbuf_clone(GWBUF *buf)
|
||||
{
|
||||
GWBUF *rval;
|
||||
GWBUF *rval;
|
||||
|
||||
if ((rval = (GWBUF *)calloc(1,sizeof(GWBUF))) == NULL)
|
||||
{
|
||||
@ -325,8 +323,7 @@ GWBUF *rval;
|
||||
*
|
||||
* @return head of the cloned list or NULL if the list was empty.
|
||||
*/
|
||||
GWBUF* gwbuf_clone_all(
|
||||
GWBUF* buf)
|
||||
GWBUF* gwbuf_clone_all(GWBUF* buf)
|
||||
{
|
||||
GWBUF* rval;
|
||||
GWBUF* clonebuf;
|
||||
@ -349,8 +346,7 @@ GWBUF* gwbuf_clone_all(
|
||||
}
|
||||
|
||||
|
||||
GWBUF *gwbuf_clone_portion(
|
||||
GWBUF *buf,
|
||||
GWBUF *gwbuf_clone_portion(GWBUF *buf,
|
||||
size_t start_offset,
|
||||
size_t length)
|
||||
{
|
||||
@ -384,7 +380,6 @@ GWBUF *gwbuf_clone_portion(
|
||||
gwbuf_add_to_hashtable(clonebuf);
|
||||
#endif
|
||||
return clonebuf;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -393,9 +388,7 @@ GWBUF *gwbuf_clone_portion(
|
||||
* Return NULL if conversion between types is not supported or due lacking
|
||||
* type information.
|
||||
*/
|
||||
GWBUF *gwbuf_clone_transform(
|
||||
GWBUF * head,
|
||||
gwbuf_type_t targettype)
|
||||
GWBUF *gwbuf_clone_transform(GWBUF *head, gwbuf_type_t targettype)
|
||||
{
|
||||
gwbuf_type_t src_type;
|
||||
GWBUF* clonebuf;
|
||||
@ -417,10 +410,9 @@ GWBUF *gwbuf_clone_transform(
|
||||
if (GWBUF_TYPE_PLAINSQL == targettype)
|
||||
{
|
||||
/** Crete reference to string part of buffer */
|
||||
clonebuf = gwbuf_clone_portion(
|
||||
head,
|
||||
clonebuf = gwbuf_clone_portion(head,
|
||||
5,
|
||||
GWBUF_LENGTH(head)-5);
|
||||
GWBUF_LENGTH(head) - 5);
|
||||
ss_dassert(clonebuf != NULL);
|
||||
/** Overwrite the type with new format */
|
||||
gwbuf_set_type(clonebuf, targettype);
|
||||
@ -454,9 +446,13 @@ GWBUF *
|
||||
gwbuf_append(GWBUF *head, GWBUF *tail)
|
||||
{
|
||||
if (!head)
|
||||
{
|
||||
return tail;
|
||||
if(!tail)
|
||||
}
|
||||
if (!tail)
|
||||
{
|
||||
return head;
|
||||
}
|
||||
CHK_GWBUF(head);
|
||||
head->tail->next = tail;
|
||||
head->tail = tail->tail;
|
||||
@ -483,7 +479,7 @@ gwbuf_append(GWBUF *head, GWBUF *tail)
|
||||
GWBUF *
|
||||
gwbuf_consume(GWBUF *head, unsigned int length)
|
||||
{
|
||||
GWBUF *rval = head;
|
||||
GWBUF *rval = head;
|
||||
|
||||
CHK_GWBUF(head);
|
||||
GWBUF_CONSUME(head, length);
|
||||
@ -493,7 +489,9 @@ GWBUF *rval = head;
|
||||
{
|
||||
rval = head->next;
|
||||
if (head->next)
|
||||
{
|
||||
head->next->tail = head->tail;
|
||||
}
|
||||
|
||||
gwbuf_free(head);
|
||||
}
|
||||
@ -511,7 +509,7 @@ GWBUF *rval = head;
|
||||
unsigned int
|
||||
gwbuf_length(GWBUF *head)
|
||||
{
|
||||
int rval = 0;
|
||||
int rval = 0;
|
||||
|
||||
if (head)
|
||||
{
|
||||
@ -563,7 +561,7 @@ gwbuf_trim(GWBUF *buf, unsigned int n_bytes)
|
||||
GWBUF *
|
||||
gwbuf_rtrim(GWBUF *head, unsigned int n_bytes)
|
||||
{
|
||||
GWBUF *rval = head;
|
||||
GWBUF *rval = head;
|
||||
CHK_GWBUF(head);
|
||||
GWBUF_RTRIM(head, n_bytes);
|
||||
CHK_GWBUF(head);
|
||||
@ -603,8 +601,7 @@ void gwbuf_set_type(
|
||||
* @param data Object data
|
||||
* @param donefun_dp Clean-up function to be executed before buffer is freed.
|
||||
*/
|
||||
void gwbuf_add_buffer_object(
|
||||
GWBUF* buf,
|
||||
void gwbuf_add_buffer_object(GWBUF* buf,
|
||||
bufobj_id_t id,
|
||||
void* data,
|
||||
void (*donefun_fp)(void *))
|
||||
@ -650,9 +647,7 @@ void gwbuf_add_buffer_object(
|
||||
*
|
||||
* @return Searched buffer object or NULL if not found
|
||||
*/
|
||||
void* gwbuf_get_buffer_object_data(
|
||||
GWBUF* buf,
|
||||
bufobj_id_t id)
|
||||
void* gwbuf_get_buffer_object_data(GWBUF* buf, bufobj_id_t id)
|
||||
{
|
||||
buffer_object_t* bo;
|
||||
|
||||
@ -676,9 +671,7 @@ void* gwbuf_get_buffer_object_data(
|
||||
/**
|
||||
* @return pointer to next buffer object or NULL
|
||||
*/
|
||||
static buffer_object_t* gwbuf_remove_buffer_object(
|
||||
GWBUF* buf,
|
||||
buffer_object_t* bufobj)
|
||||
static buffer_object_t* gwbuf_remove_buffer_object(GWBUF* buf, buffer_object_t* bufobj)
|
||||
{
|
||||
buffer_object_t* next;
|
||||
|
||||
@ -689,8 +682,6 @@ static buffer_object_t* gwbuf_remove_buffer_object(
|
||||
return next;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Add a property to a buffer.
|
||||
*
|
||||
@ -702,7 +693,7 @@ static buffer_object_t* gwbuf_remove_buffer_object(
|
||||
int
|
||||
gwbuf_add_property(GWBUF *buf, char *name, char *value)
|
||||
{
|
||||
BUF_PROPERTY *prop;
|
||||
BUF_PROPERTY *prop;
|
||||
|
||||
if ((prop = malloc(sizeof(BUF_PROPERTY))) == NULL)
|
||||
{
|
||||
@ -730,15 +721,19 @@ BUF_PROPERTY *prop;
|
||||
char *
|
||||
gwbuf_get_property(GWBUF *buf, char *name)
|
||||
{
|
||||
BUF_PROPERTY *prop;
|
||||
BUF_PROPERTY *prop;
|
||||
|
||||
spinlock_acquire(&buf->gwbuf_lock);
|
||||
prop = buf->properties;
|
||||
while (prop && strcmp(prop->name, name) != 0)
|
||||
{
|
||||
prop = prop->next;
|
||||
}
|
||||
spinlock_release(&buf->gwbuf_lock);
|
||||
if (prop)
|
||||
{
|
||||
return prop->value;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -752,14 +747,18 @@ BUF_PROPERTY *prop;
|
||||
GWBUF *
|
||||
gwbuf_make_contiguous(GWBUF *orig)
|
||||
{
|
||||
GWBUF *newbuf;
|
||||
char *ptr;
|
||||
int len;
|
||||
GWBUF *newbuf;
|
||||
char *ptr;
|
||||
int len;
|
||||
|
||||
if(orig == NULL)
|
||||
if (orig == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (orig->next == NULL)
|
||||
{
|
||||
return orig;
|
||||
}
|
||||
|
||||
if ((newbuf = gwbuf_alloc(gwbuf_length(orig))) != NULL)
|
||||
{
|
||||
@ -788,14 +787,16 @@ int len;
|
||||
int
|
||||
gwbuf_add_hint(GWBUF *buf, HINT *hint)
|
||||
{
|
||||
HINT *ptr;
|
||||
HINT *ptr;
|
||||
|
||||
spinlock_acquire(&buf->gwbuf_lock);
|
||||
if (buf->hint)
|
||||
{
|
||||
ptr = buf->hint;
|
||||
while (ptr->next)
|
||||
{
|
||||
ptr = ptr->next;
|
||||
}
|
||||
ptr->next = hint;
|
||||
}
|
||||
else
|
||||
|
@ -60,7 +60,8 @@ EXTERN_C_BLOCK_BEGIN
|
||||
* contents. This may be added at any point during the processing of the
|
||||
* data, especially in the protocol stage of the processing.
|
||||
*/
|
||||
typedef struct buf_property {
|
||||
typedef struct buf_property
|
||||
{
|
||||
char *name;
|
||||
char *value;
|
||||
struct buf_property *next;
|
||||
@ -91,7 +92,8 @@ typedef enum
|
||||
* shared between multiple GWBUF's without the need to make multiple copies
|
||||
* but still maintain separate data pointers.
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
unsigned char *data; /*< Physical memory that was allocated */
|
||||
int refcount; /*< Reference count on the buffer */
|
||||
} SHARED_BUF;
|
||||
@ -117,7 +119,8 @@ typedef enum
|
||||
|
||||
typedef struct buffer_object_st buffer_object_t;
|
||||
|
||||
struct buffer_object_st {
|
||||
struct buffer_object_st
|
||||
{
|
||||
bufobj_id_t bo_id;
|
||||
void* bo_data;
|
||||
void (*bo_donefun_fp)(void *);
|
||||
@ -133,7 +136,8 @@ struct buffer_object_st {
|
||||
* flexible data pointers is designed to minimise the need for data to
|
||||
* be copied within the gateway.
|
||||
*/
|
||||
typedef struct gwbuf {
|
||||
typedef struct gwbuf
|
||||
{
|
||||
SPINLOCK gwbuf_lock;
|
||||
struct gwbuf *next; /*< Next buffer in a linked chain of buffers */
|
||||
struct gwbuf *tail; /*< Last buffer in a linked chain of buffers */
|
||||
@ -169,12 +173,15 @@ typedef struct gwbuf {
|
||||
#define GWBUF_CONSUME(b, bytes) ((b)->start = bytes > ((char *)(b)->end - (char *)(b)->start) ? (b)->end : (void *)((char *)(b)->start + (bytes)));
|
||||
|
||||
/*< Check if a given pointer is within the buffer */
|
||||
#define GWBUF_POINTER_IN_BUFFER (ptr, b) ((char *)(ptr) >= (char *)(b)->start && (char *)(ptr) < (char *)(b)->end)
|
||||
#define GWBUF_POINTER_IN_BUFFER (ptr, b)\
|
||||
((char *)(ptr) >= (char *)(b)->start && (char *)(ptr) < (char *)(b)->end)
|
||||
|
||||
/*< Consume a complete buffer */
|
||||
#define GWBUF_CONSUME_ALL(b) gwbuf_consume((b), GWBUF_LENGTH((b)))
|
||||
|
||||
#define GWBUF_RTRIM(b, bytes) ((b)->end = bytes > ((char *)(b)->end - (char *)(b)->start) ? (b)->start : (void *)((char *)(b)->end - (bytes)));
|
||||
#define GWBUF_RTRIM(b, bytes)\
|
||||
((b)->end = bytes > ((char *)(b)->end - (char *)(b)->start) ? (b)->start : \
|
||||
(void *)((char *)(b)->end - (bytes)));
|
||||
|
||||
#define GWBUF_TYPE(b) (b)->gwbuf_type
|
||||
/*<
|
||||
|
Reference in New Issue
Block a user