From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] replace time(2) with gettimeofday(2)
Date: Sun, 10 Sep 2023 09:46:42 +0000 [thread overview]
Message-ID: <20230910094642.1096382-1-e@80x24.org> (raw)
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" }
reply other threads:[~2023-09-10 9:46 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230910094642.1096382-1-e@80x24.org \
--to=e@80x24.org \
--cc=spew@80x24.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).