summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2020-10-10 15:34:26 +0200
committerSander Vrijders <sander@ouroboros.rocks>2020-10-11 14:24:05 +0200
commitec242f45e6980fb5b0139d3429a88795b82f0c13 (patch)
treef157b4601bd0d745430d83cd1be4f46f609b2ff9 /src/lib
parent21dec0f30da7eecf965a3b088c9646029354b431 (diff)
downloadouroboros-ec242f45e6980fb5b0139d3429a88795b82f0c13.tar.gz
ouroboros-ec242f45e6980fb5b0139d3429a88795b82f0c13.zip
lib: Refactor flow_write
Refactor flow_write cleanup. Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks> Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/dev.c31
1 files changed, 11 insertions, 20 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c
index ed377367..3bc060bf 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -1068,28 +1068,14 @@ ssize_t flow_write(int fd,
pthread_rwlock_rdlock(&ai.lock);
- if (frcti_snd(flow->frcti, sdb) < 0) {
- pthread_rwlock_unlock(&ai.lock);
- shm_rdrbuff_remove(ai.rdrb, idx);
- return -ENOMEM;
- }
-
- if (flow->qs.cypher_s > 0) {
- if (crypt_encrypt(flow, sdb) < 0) {
- pthread_rwlock_unlock(&ai.lock);
- shm_rdrbuff_remove(ai.rdrb, idx);
- return -ENOMEM;
- }
- }
-
- pthread_rwlock_unlock(&ai.lock);
+ if (frcti_snd(flow->frcti, sdb) < 0)
+ goto enomem;
- if (flow->qs.ber == 0 && add_crc(sdb) != 0) {
- shm_rdrbuff_remove(ai.rdrb, idx);
- return -ENOMEM;
- }
+ if (flow->qs.cypher_s > 0 && crypt_encrypt(flow, sdb) < 0)
+ goto enomem;
- pthread_rwlock_rdlock(&ai.lock);
+ if (flow->qs.ber == 0 && add_crc(sdb) != 0)
+ goto enomem;
if (flags & FLOWFWNOBLOCK)
ret = shm_rbuff_write(flow->tx_rb, idx);
@@ -1104,6 +1090,11 @@ ssize_t flow_write(int fd,
pthread_rwlock_unlock(&ai.lock);
return ret < 0 ? (ssize_t) ret : (ssize_t) count;
+
+ enomem:
+ pthread_rwlock_unlock(&ai.lock);
+ shm_rdrbuff_remove(ai.rdrb, idx);
+ return -ENOMEM;
}
ssize_t flow_read(int fd,