MXS-2495 Cleanup GWBUF interface
All GWBUF macros that address a single link in a chain are now simple wrappers for equivalent gwbuf_link-functions. Next step is to drop the macros and replace their use with calls to the functions.
This commit is contained in:
@ -133,42 +133,58 @@ struct GWBUF
|
|||||||
* Macros to access the data in the buffers
|
* Macros to access the data in the buffers
|
||||||
*/
|
*/
|
||||||
/*< First valid, unconsumed byte in the buffer */
|
/*< First valid, unconsumed byte in the buffer */
|
||||||
#define GWBUF_DATA(b) ((uint8_t*)(b)->start)
|
inline uint8_t* gwbuf_link_data(GWBUF* b)
|
||||||
|
{
|
||||||
|
return static_cast<uint8_t*>(b->start);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const uint8_t* gwbuf_link_data(const GWBUF* b)
|
||||||
|
{
|
||||||
|
return static_cast<uint8_t*>(b->start);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define GWBUF_DATA(b) gwbuf_link_data(b)
|
||||||
|
|
||||||
/*< Number of bytes in the individual buffer */
|
/*< Number of bytes in the individual buffer */
|
||||||
#define GWBUF_LENGTH(b) ((size_t)((char*)(b)->end - (char*)(b)->start))
|
inline size_t gwbuf_link_length(const GWBUF* b)
|
||||||
|
{
|
||||||
|
return (size_t)((char*)b->end - (char*)b->start);
|
||||||
|
}
|
||||||
|
|
||||||
/*< Return the byte at offset byte from the start of the unconsumed portion of the buffer */
|
#define GWBUF_LENGTH(b) gwbuf_link_length(b)
|
||||||
#define GWBUF_DATA_CHAR(b, byte) (GWBUF_LENGTH(b) < ((byte) + 1) ? -1 : *(((char*)(b)->start) + 4))
|
|
||||||
|
|
||||||
/*< Check that the data in a buffer has the SQL marker*/
|
|
||||||
#define GWBUF_IS_SQL(b) (0x03 == GWBUF_DATA_CHAR(b, 4))
|
|
||||||
|
|
||||||
/*< Check whether the buffer is contiguous*/
|
/*< Check whether the buffer is contiguous*/
|
||||||
#define GWBUF_IS_CONTIGUOUS(b) (((b) == NULL) || ((b)->next == NULL))
|
#define GWBUF_IS_CONTIGUOUS(b) (((b) == NULL) || ((b)->next == NULL))
|
||||||
|
|
||||||
/*< True if all bytes in the buffer have been consumed */
|
/*< True if all bytes in the buffer have been consumed */
|
||||||
#define GWBUF_EMPTY(b) ((char*)(b)->start >= (char*)(b)->end)
|
inline bool gwbuf_link_empty(const GWBUF* b)
|
||||||
|
{
|
||||||
|
return ((char*)b->start >= (char*)b->end);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define GWBUF_EMPTY(b) gwbuf_link_empty(b)
|
||||||
|
|
||||||
/*< Consume a number of bytes in the buffer */
|
/*< Consume a number of bytes in the buffer */
|
||||||
#define GWBUF_CONSUME(b, \
|
inline void gwbuf_link_consume(GWBUF* b, unsigned int bytes)
|
||||||
bytes) ((b)->start = bytes \
|
{
|
||||||
> ((char*)(b)->end \
|
b->start = bytes > ((char*)b->end - (char*)b->start) ? b->end : (void*)((char*)b->start + bytes);
|
||||||
- (char*)(b)->start) ? (b)->end : (void*)((char*)(b)->start + (bytes)));
|
}
|
||||||
|
|
||||||
/*< Check if a given pointer is within the buffer */
|
#define GWBUF_CONSUME(b, bytes) gwbuf_link_consume(b, bytes)
|
||||||
#define GWBUF_POINTER_IN_BUFFER \
|
|
||||||
(ptr, b) \
|
|
||||||
((char*)(ptr) >= (char*)(b)->start && (char*)(ptr) < (char*)(b)->end)
|
|
||||||
|
|
||||||
/*< Consume a complete buffer */
|
inline void gwbuf_link_rtrim(GWBUF* b, unsigned int bytes)
|
||||||
#define GWBUF_CONSUME_ALL(b) gwbuf_consume((b), GWBUF_LENGTH((b)))
|
{
|
||||||
|
b->end = bytes > ((char*)b->end - (char*)b->start) ? b->start : (void*)((char*)b->end - bytes);
|
||||||
|
}
|
||||||
|
|
||||||
#define GWBUF_RTRIM(b, bytes) \
|
#define GWBUF_RTRIM(b, bytes) gwbuf_link_rtrim(b, bytes)
|
||||||
((b)->end = bytes > ((char*)(b)->end - (char*)(b)->start) ? (b)->start \
|
|
||||||
: (void*)((char*)(b)->end - (bytes)));
|
inline uint32_t gwbuf_type(const GWBUF* b)
|
||||||
|
{
|
||||||
|
return b->gwbuf_type;
|
||||||
|
}
|
||||||
|
#define GWBUF_TYPE(b) gwbuf_type(b)
|
||||||
|
|
||||||
#define GWBUF_TYPE(b) (b)->gwbuf_type
|
|
||||||
/*<
|
/*<
|
||||||
* Function prototypes for the API to maniplate the buffers
|
* Function prototypes for the API to maniplate the buffers
|
||||||
*/
|
*/
|
||||||
|
@ -39,6 +39,12 @@
|
|||||||
#include <maxscale/buffer.hh>
|
#include <maxscale/buffer.hh>
|
||||||
#include <maxscale/hint.h>
|
#include <maxscale/hint.h>
|
||||||
|
|
||||||
|
/*< Return the byte at offset byte from the start of the unconsumed portion of the buffer */
|
||||||
|
#define GWBUF_DATA_CHAR(b, byte) (GWBUF_LENGTH(b) < ((byte) + 1) ? -1 : *(((char*)(b)->start) + 4))
|
||||||
|
|
||||||
|
/*< Check that the data in a buffer has the SQL marker*/
|
||||||
|
#define GWBUF_IS_SQL(b) (0x03 == GWBUF_DATA_CHAR(b, 4))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate predefined test data
|
* Generate predefined test data
|
||||||
*
|
*
|
||||||
|
@ -593,7 +593,7 @@ void test_large_packets()
|
|||||||
{
|
{
|
||||||
GWBUF* buffer = gwbuf_append(create_buffer(0x00ffffff), create_buffer(i));
|
GWBUF* buffer = gwbuf_append(create_buffer(0x00ffffff), create_buffer(i));
|
||||||
mxb_assert(gwbuf_length(buffer) == 0xffffffUL + i + 8);
|
mxb_assert(gwbuf_length(buffer) == 0xffffffUL + i + 8);
|
||||||
GWBUF_RTRIM(buffer->next, 1)
|
GWBUF_RTRIM(buffer->next, 1);
|
||||||
GWBUF* complete = modutil_get_complete_packets(&buffer);
|
GWBUF* complete = modutil_get_complete_packets(&buffer);
|
||||||
mxb_assert_message(buffer, "Incomplete buffer is not NULL");
|
mxb_assert_message(buffer, "Incomplete buffer is not NULL");
|
||||||
mxb_assert_message(complete, "The complete buffer is not NULL");
|
mxb_assert_message(complete, "The complete buffer is not NULL");
|
||||||
|
@ -729,7 +729,7 @@ static inline bool collecting_resultset(MySQLProtocol* proto, uint64_t capabilit
|
|||||||
*/
|
*/
|
||||||
static inline bool not_ok_packet(const GWBUF* buffer)
|
static inline bool not_ok_packet(const GWBUF* buffer)
|
||||||
{
|
{
|
||||||
uint8_t* data = GWBUF_DATA(buffer);
|
const uint8_t* data = GWBUF_DATA(buffer);
|
||||||
|
|
||||||
return data[4] != MYSQL_REPLY_OK
|
return data[4] != MYSQL_REPLY_OK
|
||||||
|| // Should be more than 7 bytes of payload
|
|| // Should be more than 7 bytes of payload
|
||||||
|
Reference in New Issue
Block a user