From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 748051F55F for ; Sun, 10 Sep 2023 09:46:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1694339202; bh=UTM3iBMqQ2QsEt1kklie20MEGhGdrWgooJ86YEjiKpg=; h=From:To:Subject:Date:From; b=4NtAHmmwtoZF98XV5xxTUlKUY1WLCZsq/NQRU6zbYnFn8AKClHg9WVnBIdnQ40I1+ EZMSNxSNKkdlsE6vJO3cfVQyaUsbVN0cRPsrihh8mde7193gcTD331Ciw2zOpu3GXw Hso+A9G2LNBrLBzaibJw2XlVcDiPNsPCNHUZCEcE= From: Eric Wong To: spew@80x24.org Subject: [PATCH] replace time(2) with gettimeofday(2) Date: Sun, 10 Sep 2023 09:46:42 +0000 Message-ID: <20230910094642.1096382-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Worth it for accuracy? *sigh* --- lib/PublicInbox/HTTP.pm | 3 ++- lib/PublicInbox/Import.pm | 6 +++--- lib/PublicInbox/LeiLsMailSource.pm | 3 ++- lib/PublicInbox/NNTP.pm | 11 +++++++++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm index ca162939..da61d4ed 100644 --- a/lib/PublicInbox/HTTP.pm +++ b/lib/PublicInbox/HTTP.pm @@ -29,6 +29,7 @@ use HTTP::Date qw(time2str); use PublicInbox::DS qw(msg_more); use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT); use PublicInbox::Tmpfile; +use Time::HiRes qw(gettimeofday); use constant { CHUNK_START => -1, # [a-f0-9]+\r\n CHUNK_END => -2, # \r\n @@ -53,7 +54,7 @@ open(my $null_io, '<', '/dev/null') or die "open /dev/null: $!"; my $http_date; my $prev = 0; sub http_date () { - my $now = time; + my ($now) = gettimeofday; $now == $prev ? $http_date : ($http_date = time2str($prev = $now)); } diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm index 59462e9a..8136c86a 100644 --- a/lib/PublicInbox/Import.pm +++ b/lib/PublicInbox/Import.pm @@ -18,6 +18,7 @@ use PublicInbox::ContentHash qw(content_digest); use PublicInbox::MDA; use PublicInbox::Eml; use POSIX qw(strftime); +use Time::HiRes qw(gettimeofday); sub default_branch () { state $default_branch = do { @@ -88,8 +89,6 @@ sub gfi_start { sub wfail () { die "write to fast-import failed: $!" } -sub now_raw () { time . ' +0000' } - sub norm_body ($) { my ($mime) = @_; my $b = $mime->body_raw; @@ -263,7 +262,8 @@ sub remove { print $w "reset $ref\n" or wfail; } my $ident = $self->{ident}; - my $now = now_raw(); + my ($now) = gettimeofday; + $now .= ' +0000'; $msg //= 'rm'; my $len = length($msg) + 1; print $w "commit $ref\nmark :$commit\n", diff --git a/lib/PublicInbox/LeiLsMailSource.pm b/lib/PublicInbox/LeiLsMailSource.pm index 50799270..404e1486 100644 --- a/lib/PublicInbox/LeiLsMailSource.pm +++ b/lib/PublicInbox/LeiLsMailSource.pm @@ -8,6 +8,7 @@ package PublicInbox::LeiLsMailSource; use strict; use v5.10.1; use parent qw(PublicInbox::IPC PublicInbox::LeiInput); +use Time::HiRes qw(gettimeofday); sub input_path_url { # overrides LeiInput version my ($self, $url) = @_; @@ -74,7 +75,7 @@ sub input_path_url { # overrides LeiInput version my $fc = $lei->url_folder_cache; my $lk = $fc->lock_for_scope; $fc->dbh->begin_work; - my $now = time; + my ($now) = gettimeofday; $fc->set($_, $now) for @f; $fc->dbh->commit; } diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index 316b7775..0e50b789 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -17,6 +17,7 @@ use POSIX qw(strftime); use PublicInbox::DS qw(now); use PublicInbox::SHA qw(sha1_hex); use Time::Local qw(timegm timelocal); +use Time::HiRes qw(gettimeofday); use PublicInbox::GitAsyncCat; use PublicInbox::Address; @@ -137,7 +138,10 @@ sub list_active_times_i { my ($self, $ibxs) = @_; my @window = splice(@$ibxs, 0, 1000); $self->msg_more(join('', map { - my $c = eval { $_->uidvalidity } // time; + my $c = eval { $_->uidvalidity } // do { + my ($sec) = gettimeofday; + $sec; + }; "$_->{newsgroup} $c <$_->{-primary_address}>\r\n"; } @window)); scalar @$ibxs; # continue if there's more @@ -593,7 +597,10 @@ sub cmd_stat ($;$) { sub cmd_ihave ($) { \"435 article not wanted - do not send it\r\n" } -sub cmd_date ($) { '111 '.strftime('%Y%m%d%H%M%S', gmtime(time))."\r\n" } +sub cmd_date ($) { + my ($sec) = gettimeofday; + '111 '.strftime('%Y%m%d%H%M%S', gmtime($sec))."\r\n" +} sub cmd_help ($) { \"100 help text follows\r\n.\r\n" }