Skip to content

Commit f4f8bf9

Browse files
committed
dlt-receive: Synchronize file's in-core state with storage device
Add fsync check to ensure consistency between console payload and DLT file Signed-off-by: Mike Konstantakos <[email protected]>
1 parent 48a867c commit f4f8bf9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/console/dlt-receive.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
#include "dlt-control-common.h"
8989

9090
#define DLT_RECEIVE_ECU_ID "RECV"
91+
#define FSYNC_BYTE_THRESHOLD (1000 * 1000)
9192

9293
DltClient dltclient;
9394

@@ -641,6 +642,7 @@ int dlt_receive_message_callback(DltMessage *message, void *data)
641642
{
642643
DltReceiveData *dltdata;
643644
static char text[DLT_RECEIVE_BUFSIZE];
645+
static uint32_t bytes_since_last_fsync = 0;
644646

645647
struct iovec iov[2];
646648
int bytes_written;
@@ -711,11 +713,20 @@ int dlt_receive_message_callback(DltMessage *message, void *data)
711713
bytes_written = (int)writev(dltdata->ohandle, iov, 2);
712714

713715
dltdata->totalbytes += bytes_written;
716+
bytes_since_last_fsync += bytes_written;
714717

715718
if (0 > bytes_written) {
716719
printf("dlt_receive_message_callback: writev(dltdata->ohandle, iov, 2); returned an error!");
717720
return -1;
718721
}
722+
else if (bytes_since_last_fsync >= FSYNC_BYTE_THRESHOLD) {
723+
if (fsync(dltdata->ohandle) < 0) {
724+
printf("dlt_receive_message_callback: fsync failed!");
725+
}
726+
else {
727+
bytes_since_last_fsync = 0;
728+
}
729+
}
719730
}
720731
}
721732

0 commit comments

Comments
 (0)