@@ -442,9 +442,23 @@ void FileStorageStreamReader_read(
442
442
struct FileStorageStreamReader * stream_reader =
443
443
(struct FileStorageStreamReader * ) stream_reader_data ;
444
444
int i = 0 ;
445
- long long timestamp_limit =
446
- (long long ) selector -> time_range_end .sec * NANOSECS_PER_SEC
447
- + selector -> time_range_end .nanosec ;
445
+ /*
446
+ * If the last sample was already provided and we are at the end of the file
447
+ * we will skip the read operation in order to finalize the execution.
448
+ */
449
+ if (stream_reader -> current_timestamp == INT64_MAX
450
+ && feof (stream_reader -> file_record .file )) {
451
+ * count = 0 ;
452
+ return ;
453
+ }
454
+ DDS_LongLong timestamp_limit ;
455
+ if (selector -> time_range_end .sec == DDS_TIME_MAX .sec
456
+ && selector -> time_range_end .nanosec == DDS_TIME_MAX .nanosec ) {
457
+ timestamp_limit = selector -> time_range_end .sec ;
458
+ } else {
459
+ timestamp_limit = selector -> time_range_end .sec * NANOSECS_PER_SEC ;
460
+ timestamp_limit += selector -> time_range_end .nanosec ;
461
+ }
448
462
int read_samples = 0 ;
449
463
/*
450
464
* The value of the sample selector's max samples could be
@@ -461,12 +475,21 @@ void FileStorageStreamReader_read(
461
475
* count = 0 ;
462
476
return ;
463
477
}
464
- /* Add the currently read sample and sample info values to the taken data
465
- * and info collections (sequences) */
478
+ /*
479
+ * Add the currently read sample and sample info values to the taken data
480
+ * and info collections (sequences)
481
+ */
466
482
do {
467
483
FileStorageStreamReader_addSampleToData (stream_reader );
468
- FileStorageStreamReader_readSample (stream_reader );
469
484
read_samples ++ ;
485
+ /*
486
+ * if we reach the end of the file or we cant read a proper sample,
487
+ * we dont add that sample on this iteration but we should send the
488
+ * previous samples
489
+ */
490
+ if (FileStorageStreamReader_readSample (stream_reader ) == FALSE) {
491
+ break ;
492
+ }
470
493
} while (stream_reader -> current_timestamp <= timestamp_limit
471
494
&& read_samples < max_samples );
472
495
/* The number of taken samples is the current length of the data sequence */
@@ -583,6 +606,7 @@ int FileStorageStreamReader_initialize(
583
606
/* Bootstrap the take loop: read the first sample */
584
607
if (!FileStorageStreamReader_readSample (stream_reader )) {
585
608
printf ("Failed to get first sample from file, maybe EOF was reached\n" );
609
+ return FALSE;
586
610
}
587
611
588
612
RTI_RecordingServiceStorageStreamReader_initialize (
0 commit comments