summaryrefslogtreecommitdiff
path: root/src/lib/dev.c
diff options
context:
space:
mode:
authorSander Vrijders <[email protected]>2017-08-22 17:38:44 +0200
committerSander Vrijders <[email protected]>2017-08-22 17:38:44 +0200
commit743c2f69744fe3f0dac11e467a92ff5e4d80280b (patch)
tree5cd831f6a777d9be5d14e8aff1a66897d8163e19 /src/lib/dev.c
parentfb771c0cf876ad58c50551b90dacc0b5689dae05 (diff)
downloadouroboros-743c2f69744fe3f0dac11e467a92ff5e4d80280b.tar.gz
ouroboros-743c2f69744fe3f0dac11e467a92ff5e4d80280b.zip
lib: Fix CRC check and add frct_clear
This adds the CRC check by default on outgoing SDUs. It fixes some errors in the serialization and deserialization of the SDU. frct_clear was added to avoid bad initialization of the array of FRCT instances.
Diffstat (limited to 'src/lib/dev.c')
-rw-r--r--src/lib/dev.c43
1 files changed, 30 insertions, 13 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c
index 52a56097..a5caad3c 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -247,26 +247,41 @@ static int finalize_write(int fd,
static int frcti_init(int fd)
{
- ai.frcti[fd].used = true;
+ struct frcti * frcti;
+
+ frcti = &(ai.frcti[fd]);
- ai.frcti[fd].snd_drf = true;
- ai.frcti[fd].snd_lwe = 0;
- ai.frcti[fd].snd_rwe = 0;
+ frcti->used = true;
- ai.frcti[fd].rcv_drf = true;
- ai.frcti[fd].rcv_lwe = 0;
- ai.frcti[fd].rcv_rwe = 0;
+ frcti->snd_drf = true;
+ frcti->snd_lwe = 0;
+ frcti->snd_rwe = 0;
+
+ frcti->rcv_drf = true;
+ frcti->rcv_lwe = 0;
+ frcti->rcv_rwe = 0;
+
+ frcti->conf_flags = CONF_ERROR_CHECK;
return 0;
}
-static void frcti_fini(int fd)
+static void frcti_clear(int fd)
{
struct frcti * frcti;
frcti = &(ai.frcti[fd]);
frcti->used = false;
+ frcti->snd_inact = NULL;
+ frcti->rcv_inact = NULL;
+}
+
+static void frcti_fini(int fd)
+{
+ struct frcti * frcti;
+
+ frcti = &(ai.frcti[fd]);
/* FIXME: We actually need to wait until these timers become NULL. */
if (frcti->snd_inact != NULL)
@@ -274,6 +289,8 @@ static void frcti_fini(int fd)
if (frcti->rcv_inact != NULL)
timerwheel_stop(ai.tw, frcti->rcv_inact);
+
+ frcti_clear(fd);
}
static int frcti_configure(int fd,
@@ -405,14 +422,14 @@ static ssize_t frcti_read(int fd)
if (frct_pci_des(sdb, &pci, frcti->conf_flags & CONF_ERROR_CHECK)) {
pthread_rwlock_unlock(&ai.lock);
shm_rdrbuff_remove(ai.rdrb, idx);
- return -1;
+ return -EAGAIN;
}
/* We don't accept packets when there is no inactivity timer. */
if (frcti->rcv_drf && !(pci.flags & FLAG_DATA_RUN)) {
pthread_rwlock_unlock(&ai.lock);
shm_rdrbuff_remove(ai.rdrb, idx);
- return -1;
+ return -EAGAIN;
}
/*
@@ -436,7 +453,7 @@ static ssize_t frcti_read(int fd)
if (frcti->rcv_inact == NULL) {
pthread_rwlock_unlock(&ai.lock);
shm_rdrbuff_remove(ai.rdrb, idx);
- return -1;
+ return -EAGAIN;
}
frcti->rcv_drf = false;
@@ -444,7 +461,7 @@ static ssize_t frcti_read(int fd)
if (timerwheel_restart(ai.tw, frcti->rcv_inact, 3 * MPL)) {
pthread_rwlock_unlock(&ai.lock);
shm_rdrbuff_remove(ai.rdrb, idx);
- return -1;
+ return -EAGAIN;
}
}
@@ -507,7 +524,7 @@ static void flow_fini(int fd)
shm_flow_set_close(ai.flows[fd].set);
if (ai.frcti[fd].used)
- frcti_fini(fd);
+ frcti_clear(fd);
flow_clear(fd);
}