Skip to content

Commit

Permalink
dlt-receive: Synchronize file's in-core state with storage device
Browse files Browse the repository at this point in the history
Add fsync check to ensure consistency between console payload and DLT file

Signed-off-by: Mike Konstantakos <[email protected]>
  • Loading branch information
Laximas committed Feb 12, 2024
1 parent 48a867c commit f4f8bf9
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/console/dlt-receive.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
#include "dlt-control-common.h"

#define DLT_RECEIVE_ECU_ID "RECV"
#define FSYNC_BYTE_THRESHOLD (1000 * 1000)

DltClient dltclient;

Expand Down Expand Up @@ -641,6 +642,7 @@ int dlt_receive_message_callback(DltMessage *message, void *data)
{
DltReceiveData *dltdata;
static char text[DLT_RECEIVE_BUFSIZE];
static uint32_t bytes_since_last_fsync = 0;

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

dltdata->totalbytes += bytes_written;
bytes_since_last_fsync += bytes_written;

if (0 > bytes_written) {
printf("dlt_receive_message_callback: writev(dltdata->ohandle, iov, 2); returned an error!");
return -1;
}
else if (bytes_since_last_fsync >= FSYNC_BYTE_THRESHOLD) {
if (fsync(dltdata->ohandle) < 0) {
printf("dlt_receive_message_callback: fsync failed!");
}
else {
bytes_since_last_fsync = 0;
}
}
}
}

Expand Down

0 comments on commit f4f8bf9

Please sign in to comment.