Reindent server/core/buffer.c

This commit is contained in:
Johan Wikman
2015-11-30 10:55:21 +02:00
parent 73e2d9950c
commit 17760bb3e6
2 changed files with 503 additions and 495 deletions

View File

@ -56,8 +56,7 @@
static HASHTABLE *buffer_hashtable = NULL; static HASHTABLE *buffer_hashtable = NULL;
#endif #endif
static buffer_object_t* gwbuf_remove_buffer_object( static buffer_object_t* gwbuf_remove_buffer_object(GWBUF* buf,
GWBUF* buf,
buffer_object_t* bufobj); buffer_object_t* bufobj);
#if defined(BUFFER_TRACE) #if defined(BUFFER_TRACE)
@ -87,7 +86,7 @@ SHARED_BUF *sbuf;
/* Allocate the buffer header */ /* Allocate the buffer header */
if ((rval = (GWBUF *)malloc(sizeof(GWBUF))) == NULL) if ((rval = (GWBUF *)malloc(sizeof(GWBUF))) == NULL)
{ {
goto retblock;; goto retblock;
} }
/* Allocate the shared data buffer */ /* Allocate the shared data buffer */
@ -241,7 +240,6 @@ void
gwbuf_free(GWBUF *buf) gwbuf_free(GWBUF *buf)
{ {
BUF_PROPERTY *prop; BUF_PROPERTY *prop;
buffer_object_t *bo; buffer_object_t *bo;
CHK_GWBUF(buf); CHK_GWBUF(buf);
@ -325,8 +323,7 @@ GWBUF *rval;
* *
* @return head of the cloned list or NULL if the list was empty. * @return head of the cloned list or NULL if the list was empty.
*/ */
GWBUF* gwbuf_clone_all( GWBUF* gwbuf_clone_all(GWBUF* buf)
GWBUF* buf)
{ {
GWBUF* rval; GWBUF* rval;
GWBUF* clonebuf; GWBUF* clonebuf;
@ -349,8 +346,7 @@ GWBUF* gwbuf_clone_all(
} }
GWBUF *gwbuf_clone_portion( GWBUF *gwbuf_clone_portion(GWBUF *buf,
GWBUF *buf,
size_t start_offset, size_t start_offset,
size_t length) size_t length)
{ {
@ -384,7 +380,6 @@ GWBUF *gwbuf_clone_portion(
gwbuf_add_to_hashtable(clonebuf); gwbuf_add_to_hashtable(clonebuf);
#endif #endif
return clonebuf; return clonebuf;
} }
/** /**
@ -393,9 +388,7 @@ GWBUF *gwbuf_clone_portion(
* Return NULL if conversion between types is not supported or due lacking * Return NULL if conversion between types is not supported or due lacking
* type information. * type information.
*/ */
GWBUF *gwbuf_clone_transform( GWBUF *gwbuf_clone_transform(GWBUF *head, gwbuf_type_t targettype)
GWBUF * head,
gwbuf_type_t targettype)
{ {
gwbuf_type_t src_type; gwbuf_type_t src_type;
GWBUF* clonebuf; GWBUF* clonebuf;
@ -417,8 +410,7 @@ GWBUF *gwbuf_clone_transform(
if (GWBUF_TYPE_PLAINSQL == targettype) if (GWBUF_TYPE_PLAINSQL == targettype)
{ {
/** Crete reference to string part of buffer */ /** Crete reference to string part of buffer */
clonebuf = gwbuf_clone_portion( clonebuf = gwbuf_clone_portion(head,
head,
5, 5,
GWBUF_LENGTH(head) - 5); GWBUF_LENGTH(head) - 5);
ss_dassert(clonebuf != NULL); ss_dassert(clonebuf != NULL);
@ -454,9 +446,13 @@ GWBUF *
gwbuf_append(GWBUF *head, GWBUF *tail) gwbuf_append(GWBUF *head, GWBUF *tail)
{ {
if (!head) if (!head)
{
return tail; return tail;
}
if (!tail) if (!tail)
{
return head; return head;
}
CHK_GWBUF(head); CHK_GWBUF(head);
head->tail->next = tail; head->tail->next = tail;
head->tail = tail->tail; head->tail = tail->tail;
@ -493,7 +489,9 @@ GWBUF *rval = head;
{ {
rval = head->next; rval = head->next;
if (head->next) if (head->next)
{
head->next->tail = head->tail; head->next->tail = head->tail;
}
gwbuf_free(head); gwbuf_free(head);
} }
@ -603,8 +601,7 @@ void gwbuf_set_type(
* @param data Object data * @param data Object data
* @param donefun_dp Clean-up function to be executed before buffer is freed. * @param donefun_dp Clean-up function to be executed before buffer is freed.
*/ */
void gwbuf_add_buffer_object( void gwbuf_add_buffer_object(GWBUF* buf,
GWBUF* buf,
bufobj_id_t id, bufobj_id_t id,
void* data, void* data,
void (*donefun_fp)(void *)) void (*donefun_fp)(void *))
@ -650,9 +647,7 @@ void gwbuf_add_buffer_object(
* *
* @return Searched buffer object or NULL if not found * @return Searched buffer object or NULL if not found
*/ */
void* gwbuf_get_buffer_object_data( void* gwbuf_get_buffer_object_data(GWBUF* buf, bufobj_id_t id)
GWBUF* buf,
bufobj_id_t id)
{ {
buffer_object_t* bo; buffer_object_t* bo;
@ -676,9 +671,7 @@ void* gwbuf_get_buffer_object_data(
/** /**
* @return pointer to next buffer object or NULL * @return pointer to next buffer object or NULL
*/ */
static buffer_object_t* gwbuf_remove_buffer_object( static buffer_object_t* gwbuf_remove_buffer_object(GWBUF* buf, buffer_object_t* bufobj)
GWBUF* buf,
buffer_object_t* bufobj)
{ {
buffer_object_t* next; buffer_object_t* next;
@ -689,8 +682,6 @@ static buffer_object_t* gwbuf_remove_buffer_object(
return next; return next;
} }
/** /**
* Add a property to a buffer. * Add a property to a buffer.
* *
@ -735,10 +726,14 @@ BUF_PROPERTY *prop;
spinlock_acquire(&buf->gwbuf_lock); spinlock_acquire(&buf->gwbuf_lock);
prop = buf->properties; prop = buf->properties;
while (prop && strcmp(prop->name, name) != 0) while (prop && strcmp(prop->name, name) != 0)
{
prop = prop->next; prop = prop->next;
}
spinlock_release(&buf->gwbuf_lock); spinlock_release(&buf->gwbuf_lock);
if (prop) if (prop)
{
return prop->value; return prop->value;
}
return NULL; return NULL;
} }
@ -757,9 +752,13 @@ char *ptr;
int len; int len;
if (orig == NULL) if (orig == NULL)
{
return NULL; return NULL;
}
if (orig->next == NULL) if (orig->next == NULL)
{
return orig; return orig;
}
if ((newbuf = gwbuf_alloc(gwbuf_length(orig))) != NULL) if ((newbuf = gwbuf_alloc(gwbuf_length(orig))) != NULL)
{ {
@ -795,7 +794,9 @@ HINT *ptr;
{ {
ptr = buf->hint; ptr = buf->hint;
while (ptr->next) while (ptr->next)
{
ptr = ptr->next; ptr = ptr->next;
}
ptr->next = hint; ptr->next = hint;
} }
else else

View File

@ -60,7 +60,8 @@ EXTERN_C_BLOCK_BEGIN
* contents. This may be added at any point during the processing of the * contents. This may be added at any point during the processing of the
* data, especially in the protocol stage of the processing. * data, especially in the protocol stage of the processing.
*/ */
typedef struct buf_property { typedef struct buf_property
{
char *name; char *name;
char *value; char *value;
struct buf_property *next; struct buf_property *next;
@ -91,7 +92,8 @@ typedef enum
* shared between multiple GWBUF's without the need to make multiple copies * shared between multiple GWBUF's without the need to make multiple copies
* but still maintain separate data pointers. * but still maintain separate data pointers.
*/ */
typedef struct { typedef struct
{
unsigned char *data; /*< Physical memory that was allocated */ unsigned char *data; /*< Physical memory that was allocated */
int refcount; /*< Reference count on the buffer */ int refcount; /*< Reference count on the buffer */
} SHARED_BUF; } SHARED_BUF;
@ -117,7 +119,8 @@ typedef enum
typedef struct buffer_object_st buffer_object_t; typedef struct buffer_object_st buffer_object_t;
struct buffer_object_st { struct buffer_object_st
{
bufobj_id_t bo_id; bufobj_id_t bo_id;
void* bo_data; void* bo_data;
void (*bo_donefun_fp)(void *); 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 * flexible data pointers is designed to minimise the need for data to
* be copied within the gateway. * be copied within the gateway.
*/ */
typedef struct gwbuf { typedef struct gwbuf
{
SPINLOCK gwbuf_lock; SPINLOCK gwbuf_lock;
struct gwbuf *next; /*< Next buffer in a linked chain of buffers */ struct gwbuf *next; /*< Next buffer in a linked chain of buffers */
struct gwbuf *tail; /*< Last 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))); #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 */ /*< 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 */ /*< Consume a complete buffer */
#define GWBUF_CONSUME_ALL(b) gwbuf_consume((b), GWBUF_LENGTH((b))) #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 #define GWBUF_TYPE(b) (b)->gwbuf_type
/*< /*<