@@ -466,8 +466,7 @@ line_buffer::set_fd(auto_fd& fd)
466466 if (this ->lb_file_time < 0 ) {
467467 this ->lb_file_time = 0 ;
468468 }
469- this ->lb_compressed_offset
470- = lseek (this ->lb_fd , 0 , SEEK_CUR);
469+ this ->lb_compressed_offset = 0 ;
471470 if (!hdr.empty ()) {
472471 this ->lb_header = std::move (hdr);
473472 }
@@ -638,6 +637,7 @@ line_buffer::load_next_buffer()
638637 start + this ->lb_alt_buffer .value ().size (),
639638 this ->lb_alt_buffer .value ().available ());
640639 this ->lb_compressed_offset = gi->get_source_offset ();
640+ ensure (this ->lb_compressed_offset >= 0 );
641641 if (rc != -1
642642 && rc < (ssize_t ) this ->lb_alt_buffer .value ().available ()
643643 && (start + (ssize_t ) this ->lb_alt_buffer .value ().size () + rc
@@ -703,7 +703,7 @@ line_buffer::load_next_buffer()
703703 rc = BZ2_bzread (bz_file,
704704 this ->lb_alt_buffer ->end (),
705705 this ->lb_alt_buffer ->available ());
706- this ->lb_compressed_offset = lseek (bzfd, 0 , SEEK_SET) ;
706+ this ->lb_compressed_offset = 0 ;
707707 BZ2_bzclose (bz_file);
708708
709709 if (rc != -1
@@ -849,8 +849,8 @@ line_buffer::fill_range(file_off_t start,
849849 {
850850 /* Cache already has the data, nothing to do. */
851851 retval = true ;
852- if (!lnav::pid::in_child && this ->lb_seekable && this -> lb_buffer . full ()
853- && !this ->lb_loader_file_offset )
852+ if (this -> lb_do_preloading && !lnav::pid::in_child && this ->lb_seekable
853+ && this -> lb_buffer . full () && !this ->lb_loader_file_offset )
854854 {
855855 // log_debug("loader available start=%d", start);
856856 auto last_lf_iter = std::find (
@@ -911,6 +911,7 @@ line_buffer::fill_range(file_off_t start,
911911 this ->lb_file_offset + this ->lb_buffer .size (),
912912 this ->lb_buffer .available ());
913913 this ->lb_compressed_offset = gi->get_source_offset ();
914+ ensure (this ->lb_compressed_offset >= 0 );
914915 if (rc != -1 && (rc < (ssize_t ) this ->lb_buffer .available ())) {
915916 this ->lb_file_size
916917 = (this ->lb_file_offset + this ->lb_buffer .size () + rc);
@@ -974,7 +975,7 @@ line_buffer::fill_range(file_off_t start,
974975 rc = BZ2_bzread (bz_file,
975976 this ->lb_buffer .end (),
976977 this ->lb_buffer .available ());
977- this ->lb_compressed_offset = lseek (bzfd, 0 , SEEK_SET) ;
978+ this ->lb_compressed_offset = 0 ;
978979 BZ2_bzclose (bz_file);
979980
980981 if (rc != -1 && (rc < (ssize_t ) this ->lb_buffer .available ())) {
@@ -1063,8 +1064,8 @@ line_buffer::fill_range(file_off_t start,
10631064 break ;
10641065 }
10651066
1066- if (!lnav::pid::in_child && this ->lb_seekable && this -> lb_buffer . full ()
1067- && !this ->lb_loader_file_offset )
1067+ if (this -> lb_do_preloading && !lnav::pid::in_child && this ->lb_seekable
1068+ && this -> lb_buffer . full () && !this ->lb_loader_file_offset )
10681069 {
10691070 // log_debug("loader available2 start=%d", start);
10701071 auto last_lf_iter = std::find (
@@ -1591,3 +1592,31 @@ line_buffer::cleanup_cache()
15911592 }
15921593 });
15931594}
1595+
1596+ void
1597+ line_buffer::send_initial_load ()
1598+ {
1599+ if (!this ->lb_seekable ) {
1600+ log_warning (" file is not seekable, not doing preload" );
1601+ return ;
1602+ }
1603+
1604+ if (this ->lb_loader_future .valid ()) {
1605+ log_warning (" preload is already active" );
1606+ return ;
1607+ }
1608+
1609+ log_debug (" sending initial load" );
1610+ if (!this ->lb_alt_buffer ) {
1611+ // log_debug("allocating new buffer!");
1612+ this ->lb_alt_buffer = auto_buffer::alloc (this ->lb_buffer .capacity ());
1613+ }
1614+ this ->lb_loader_file_offset = 0 ;
1615+ auto prom = std::make_shared<std::promise<bool >>();
1616+ this ->lb_loader_future = prom->get_future ();
1617+ this ->lb_stats .s_requested_preloads += 1 ;
1618+ isc::to<io_looper&, io_looper_tag>().send (
1619+ [this , prom](auto & ioloop) mutable {
1620+ prom->set_value (this ->load_next_buffer ());
1621+ });
1622+ }
0 commit comments