@@ -442,9 +442,23 @@ void FileStorageStreamReader_read(
442442 struct FileStorageStreamReader * stream_reader =
443443 (struct FileStorageStreamReader * ) stream_reader_data ;
444444 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+ }
448462 int read_samples = 0 ;
449463 /*
450464 * The value of the sample selector's max samples could be
@@ -461,12 +475,21 @@ void FileStorageStreamReader_read(
461475 * count = 0 ;
462476 return ;
463477 }
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+ */
466482 do {
467483 FileStorageStreamReader_addSampleToData (stream_reader );
468- FileStorageStreamReader_readSample (stream_reader );
469484 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+ }
470493 } while (stream_reader -> current_timestamp <= timestamp_limit
471494 && read_samples < max_samples );
472495 /* The number of taken samples is the current length of the data sequence */
@@ -583,6 +606,7 @@ int FileStorageStreamReader_initialize(
583606 /* Bootstrap the take loop: read the first sample */
584607 if (!FileStorageStreamReader_readSample (stream_reader )) {
585608 printf ("Failed to get first sample from file, maybe EOF was reached\n" );
609+ return FALSE;
586610 }
587611
588612 RTI_RecordingServiceStorageStreamReader_initialize (
0 commit comments