diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-02-28 22:40:53 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-02-28 22:40:53 +0100 |
commit | 6390442c477b603d87680f8b415c1ec0dfaa9ebf (patch) | |
tree | c5f6c6a5415add9548ad0c17ce051bcaa3b8eb15 /src/fastd.h | |
parent | 35742ca05a8826541207faaa9584708da5485d95 (diff) | |
download | fastd-6390442c477b603d87680f8b415c1ec0dfaa9ebf.tar fastd-6390442c477b603d87680f8b415c1ec0dfaa9ebf.zip |
Rework buffer structure
Diffstat (limited to 'src/fastd.h')
-rw-r--r-- | src/fastd.h | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/fastd.h b/src/fastd.h index 59fdf90..90df868 100644 --- a/src/fastd.h +++ b/src/fastd.h @@ -50,10 +50,10 @@ typedef enum _fastd_loglevel { typedef struct _fastd_buffer { void *base; - size_t len; + size_t base_len; - void (*free)(void *free_p); - void *free_p; + void *data; + size_t len; } fastd_buffer; typedef enum _fastd_protocol { @@ -142,15 +142,14 @@ struct _fastd_context { #define exit_errno(context, message) exit_error(context, "%s: %s", message, strerror(errno)) -static inline fastd_buffer fastd_buffer_alloc(size_t len, size_t head_space) { +static inline fastd_buffer fastd_buffer_alloc(size_t len, size_t head_space, size_t tail_space) { + size_t base_len = head_space+len+tail_space; uint8_t *ptr = malloc(head_space+len); - return (fastd_buffer){ .base = ptr, .len = len, .free = free, .free_p = ptr+head_space }; + return (fastd_buffer){ .base = ptr, .base_len = base_len, .data = ptr+head_space, .len = len }; } static inline void fastd_buffer_free(fastd_buffer buffer) { - if (buffer.free) { - buffer.free(buffer.free_p); - } + free(buffer.base); } |