summaryrefslogtreecommitdiff
path: root/src/lib/shm_rdrbuff.c
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2017-04-26 11:57:56 +0200
committerdimitri staessens <[email protected]>2017-04-26 12:01:52 +0200
commite2c8623e66d66f4b9c8619349d11375a32ac2134 (patch)
tree4e4d3b4f8da805ca9f0f0733977ff678c064660f /src/lib/shm_rdrbuff.c
parentea16fc664673d65c0e3e51591258be4d3b8be406 (diff)
downloadouroboros-e2c8623e66d66f4b9c8619349d11375a32ac2134.tar.gz
ouroboros-e2c8623e66d66f4b9c8619349d11375a32ac2134.zip
lib: Add call to reserve blocks in rdrbuff
This adds a call ipcp_sdb_reserve to reserve memory in the rdrbuff without directly writing to a flow. The ipcp_flow_del function was renamed to ipcp_sdb_release. The functions operating on sdbs are moved to their own header.
Diffstat (limited to 'src/lib/shm_rdrbuff.c')
-rw-r--r--src/lib/shm_rdrbuff.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/lib/shm_rdrbuff.c b/src/lib/shm_rdrbuff.c
index 9dffdf74..ed9c3847 100644
--- a/src/lib/shm_rdrbuff.c
+++ b/src/lib/shm_rdrbuff.c
@@ -24,6 +24,7 @@
#include <ouroboros/config.h>
#include <ouroboros/errno.h>
#include <ouroboros/shm_rdrbuff.h>
+#include <ouroboros/shm_du_buff.h>
#include <ouroboros/time_utils.h>
#include <pthread.h>
@@ -333,7 +334,6 @@ ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb,
ssize_t sz = size + sizeof(*sdb);
assert(rdrb);
- assert(data);
#ifndef SHM_RDRB_MULTI_BLOCK
if (sz > SHM_RDRB_BLOCK_SIZE)
@@ -392,7 +392,8 @@ ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb,
sdb->du_head = headspace;
sdb->du_tail = sdb->du_head + len;
- memcpy(((uint8_t *) (sdb + 1)) + headspace, data, len);
+ if (data != NULL)
+ memcpy(((uint8_t *) (sdb + 1)) + headspace, data, len);
return sdb->idx;
}
@@ -412,7 +413,6 @@ ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb,
ssize_t sz = size + sizeof(*sdb);
assert(rdrb);
- assert(data);
#ifndef SHM_RDRB_MULTI_BLOCK
if (sz > SHM_RDRB_BLOCK_SIZE)
@@ -472,7 +472,9 @@ ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb,
sdb->size = size;
sdb->du_head = headspace;
sdb->du_tail = sdb->du_head + len;
- memcpy(((uint8_t *) (sdb + 1)) + headspace, data, len);
+
+ if (data != NULL)
+ memcpy(((uint8_t *) (sdb + 1)) + headspace, data, len);
return sdb->idx;
}
@@ -495,7 +497,8 @@ ssize_t shm_rdrbuff_read(uint8_t ** dst,
return len;
}
-struct shm_du_buff * shm_rdrbuff_get(struct shm_rdrbuff * rdrb, size_t idx)
+struct shm_du_buff * shm_rdrbuff_get(struct shm_rdrbuff * rdrb,
+ size_t idx)
{
struct shm_du_buff * sdb;
@@ -507,7 +510,8 @@ struct shm_du_buff * shm_rdrbuff_get(struct shm_rdrbuff * rdrb, size_t idx)
return sdb;
}
-int shm_rdrbuff_remove(struct shm_rdrbuff * rdrb, size_t idx)
+int shm_rdrbuff_remove(struct shm_rdrbuff * rdrb,
+ size_t idx)
{
assert(rdrb);
assert(idx < (SHM_BUFFER_SIZE));
@@ -609,3 +613,12 @@ void shm_du_buff_tail_release(struct shm_du_buff * sdb,
sdb->du_tail -= size;
}
+
+void shm_du_buff_truncate(struct shm_du_buff * sdb,
+ size_t len)
+{
+ assert(sdb);
+ assert(len <= sdb->size);
+
+ sdb->du_tail -= sdb->size - len;
+}