From bf5d011d85bacf1100f4c4d951f10b4a4df3ed36 Mon Sep 17 00:00:00 2001 From: Matt Sergeant Date: Wed, 29 Aug 2007 21:37:33 +0000 Subject: [PATCH] Update id generator again git-svn-id: https://svn.perl.org/qpsmtpd/trunk@777 958fd67b-6ff1-0310-b445-bb7760255be9 --- lib/Qpsmtpd/SMTP.pm | 2 +- lib/Qpsmtpd/Transaction.pm | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/Qpsmtpd/SMTP.pm b/lib/Qpsmtpd/SMTP.pm index 0ebc4de..c420215 100644 --- a/lib/Qpsmtpd/SMTP.pm +++ b/lib/Qpsmtpd/SMTP.pm @@ -135,7 +135,7 @@ sub transaction { sub reset_transaction { my $self = shift; $self->run_hooks("reset_transaction") if $self->{_transaction}; - return $self->{_transaction} = Qpsmtpd::Transaction->new(connection => $self->connection); + return $self->{_transaction} = Qpsmtpd::Transaction->new(); } diff --git a/lib/Qpsmtpd/Transaction.pm b/lib/Qpsmtpd/Transaction.pm index a04f996..55fd315 100644 --- a/lib/Qpsmtpd/Transaction.pm +++ b/lib/Qpsmtpd/Transaction.pm @@ -5,7 +5,7 @@ use strict; use Qpsmtpd::Utils; use Qpsmtpd::Constants; use Socket qw(inet_aton); -use Time::HiRes qw(time); +use Time::HiRes qw(gettimeofday); use IO::File qw(O_RDWR O_CREAT); @@ -17,10 +17,11 @@ sub start { my %args = @_; # generate id - my $conn = $args{connection}; - my $ip = $conn->remote_port || "0"; - my $start = time; - my $id = "$start.$$.$ip"; + # use gettimeofday for microsec precision + my ($start, $mstart) = gettimeofday(); + # add in rand() in case gettimeofday clock is slow (e.g. bsd?) + # add in $$ in case srand is set per process + my $id = sprintf("%d.%06d.%d.%d", $start, $mstart, rand(10000), $$); my $self = { _rcpt => [], started => $start, _id => $id }; bless ($self, $class);