diff options
author | Dimitri Staessens <dimitri@ouroboros.rocks> | 2020-05-03 15:52:42 +0200 |
---|---|---|
committer | Sander Vrijders <sander@ouroboros.rocks> | 2020-05-04 11:01:47 +0200 |
commit | 567f7dc6f68f8c246f821918de22423b035ef50e (patch) | |
tree | 7ebbd7c889e4786e8761ae851d3b2314faa174d3 /src/lib/dev.c | |
parent | 65054fafc577cd326832fb4f673ecadd93c778e2 (diff) | |
download | ouroboros-567f7dc6f68f8c246f821918de22423b035ef50e.tar.gz ouroboros-567f7dc6f68f8c246f821918de22423b035ef50e.zip |
lib: Refactor FRCT
This is a small refactor of FRCT because I found some things a bit
hard to read. I tried to refactor frcti_rcv to always queue the
packet, but that causes unnecessarily retaking the lock when calling
queued_pdu and thus returning idx is a tiny bit faster.
Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks>
Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'src/lib/dev.c')
-rw-r--r-- | src/lib/dev.c | 59 |
1 files changed, 26 insertions, 33 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c index e8989a48..efd08146 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -1102,29 +1102,25 @@ ssize_t flow_read(int fd, idx = flow->part_idx; if (idx < 0) { idx = frcti_queued_pdu(flow->frcti); - if (idx < 0) { - do { - idx = noblock ? shm_rbuff_read(rb) : - shm_rbuff_read_b(rb, abstime); - if (idx < 0) - return idx; - - sdb = shm_rdrbuff_get(ai.rdrb, idx); - if (flow->qs.ber == 0 && chk_crc(sdb) != 0) { - shm_rdrbuff_remove(ai.rdrb, idx); - continue; - } - - pthread_rwlock_wrlock(&ai.lock); - if (flow->qs.cypher_s > 0) - if (crypt_decrypt(flow, sdb) < 0) { - pthread_rwlock_unlock(&ai.lock); - shm_rdrbuff_remove(ai.rdrb, - idx); - return -ENOMEM; - } - pthread_rwlock_unlock(&ai.lock); - } while (frcti_rcv(flow->frcti, sdb) != 0); + while (idx < 0) { + idx = noblock ? shm_rbuff_read(rb) : + shm_rbuff_read_b(rb, abstime); + if (idx < 0) + return idx; + + sdb = shm_rdrbuff_get(ai.rdrb, idx); + if (flow->qs.ber == 0 && chk_crc(sdb) != 0) { + shm_rdrbuff_remove(ai.rdrb, idx); + continue; + } + + if (flow->qs.cypher_s > 0 + && crypt_decrypt(flow, sdb) < 0) { + shm_rdrbuff_remove(ai.rdrb, idx); + return -ENOMEM; + } + + idx = frcti_rcv(flow->frcti, sdb); } } @@ -1528,22 +1524,19 @@ int ipcp_flow_read(int fd, pthread_rwlock_unlock(&ai.lock); - if (flow->frcti != NULL) { - idx = frcti_queued_pdu(flow->frcti); - if (idx >= 0) { - *sdb = shm_rdrbuff_get(ai.rdrb, idx); - return 0; - } - } - - do { + idx = frcti_queued_pdu(flow->frcti); + while (idx < 0) { idx = shm_rbuff_read(rb); if (idx < 0) return idx; *sdb = shm_rdrbuff_get(ai.rdrb, idx); if (flow->qs.ber == 0 && chk_crc(*sdb) != 0) continue; - } while (frcti_rcv(flow->frcti, *sdb) != 0); + + idx = frcti_rcv(flow->frcti, *sdb); + } + + *sdb = shm_rdrbuff_get(ai.rdrb, idx); return 0; } |