summaryrefslogtreecommitdiffstats
path: root/src/fastd.h
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-02-27 21:28:40 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-02-27 21:28:40 +0100
commite2bcecad821f841ac40d0e0939f5805f8d142700 (patch)
tree9225c3b6d783f67043ac980bd01a8c13e8454fb4 /src/fastd.h
parent13306fc146b4839d511287f29df8572a80bf8914 (diff)
downloadfastd-e2bcecad821f841ac40d0e0939f5805f8d142700.tar
fastd-e2bcecad821f841ac40d0e0939f5805f8d142700.zip
Use custom buffers instead of struct iovec
Diffstat (limited to 'src/fastd.h')
-rw-r--r--src/fastd.h23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/fastd.h b/src/fastd.h
index 16be512..db0190d 100644
--- a/src/fastd.h
+++ b/src/fastd.h
@@ -48,6 +48,13 @@ typedef enum _fastd_loglevel {
LOG_DEBUG,
} fastd_loglevel;
+typedef struct _fastd_buffer {
+ void *base;
+ size_t len;
+
+ void (*free)(void *free_p);
+ void *free_p;
+} fastd_buffer;
typedef enum _fastd_protocol {
PROTOCOL_ETHERNET,
@@ -90,8 +97,8 @@ typedef struct _fastd_method {
void (*method_init)(fastd_context *ctx, const fastd_peer *peer);
- void (*method_handle_recv)(fastd_context *ctx, const fastd_peer *peer, struct iovec buffer);
- void (*method_send)(fastd_context *ctx, const fastd_peer *peer, struct iovec buffer);
+ void (*method_handle_recv)(fastd_context *ctx, const fastd_peer *peer, fastd_buffer buffer);
+ void (*method_send)(fastd_context *ctx, const fastd_peer *peer, fastd_buffer buffer);
} fastd_method;
typedef struct _fastd_config {
@@ -134,6 +141,18 @@ struct _fastd_context {
#define exit_errno(context, message) exit_fatal(context, "%s: %s", message, strerror(errno))
+static inline fastd_buffer fastd_buffer_alloc(size_t len, size_t head_space) {
+ uint8_t *ptr = malloc(head_space+len);
+ return (fastd_buffer){ .base = ptr, .len = len, .free = free, .free_p = ptr+head_space };
+}
+
+static inline void fastd_buffer_free(fastd_buffer buffer) {
+ if (buffer.free) {
+ buffer.free(buffer.free_p);
+ }
+}
+
+
static inline size_t fastd_max_packet_size(const fastd_context *ctx) {
switch (ctx->conf->protocol) {
case PROTOCOL_ETHERNET: