Commit 03e14ad7 authored by Michael Gray's avatar Michael Gray
Browse files

Zircon::Timestamp.

parent 7b29d09d
......@@ -9,11 +9,11 @@ use feature 'state';
use Carp qw( croak );
use Errno qw( EAGAIN ENODATA );
use Readonly;
use Time::HiRes qw( gettimeofday );
use ZMQ::LibZMQ3;
use ZMQ::Constants qw(ZMQ_REP ZMQ_REQ ZMQ_LAST_ENDPOINT ZMQ_POLLIN ZMQ_FD ZMQ_DONTWAIT ZMQ_SNDMORE ZMQ_LINGER EFSM);
use Zircon::Timestamp;
use Zircon::Context::ZMQ::Ctx;
use base 'Zircon::Trace';
......@@ -238,13 +238,12 @@ sub _process_server_request {
my $reply = $self->_request_callback->($self->_request_body, $request_header, $collision_result);
$self->zircon_trace("reply: '%s'", $reply // '<undef>');
my ($sec, $usec) = gettimeofday;
my $timestamp = Zircon::Timestamp->timestamp;
my $reply_header = {
msg_type => 'REPLY',
request_id => $request_header->{request_id},
request_attempt => $request_header->{request_attempt},
clock_sec => $sec,
clock_usec => $usec,
%$timestamp,
};
if (my $e = $self->_send_two_part($self->_zmq_responder, $reply_header, $reply // '')) {
......@@ -291,12 +290,15 @@ sub send {
my $error = 'unset';
my $zerr;
my ($sec, $usec) = gettimeofday;
my $timestamp = {};
unless (exists $conn_header->{clock_sec} and exists $conn_header->{clock_usec}) {
$timestamp = Zircon::Timestamp->timestamp;
}
my $header = {
%$conn_header,
%$timestamp,
msg_type => 'REQUEST',
clock_sec => $sec,
clock_usec => $usec,
};
my $responder = $self->_zmq_responder;
......
......@@ -6,7 +6,8 @@ use warnings;
use Carp;
use Scalar::Util qw( weaken );
use Time::HiRes qw( gettimeofday );
use Zircon::Timestamp;
use Readonly;
Readonly my $ZIRCON_PROTOCOL_VERSION => '3.0';
......@@ -133,7 +134,8 @@ sub _timestamp {
my ($self) = @_;
return if $self->inhibit_timestamps;
my ($sec, $usec) = gettimeofday;
my $timestamp = Zircon::Timestamp->timestamp;
my ($sec, $usec) = @$timestamp{qw( clock_sec clock_usec )};
return ('request_time' => "$sec,$usec");
}
......
package Zircon::Timestamp;
use strict;
use warnings;
use Time::HiRes qw( gettimeofday );
sub timestamp {
my ($sec, $usec) = gettimeofday;
return {
clock_sec => $sec,
clock_usec => $usec,
};
}
1;
=head1 AUTHOR
Ana Code B<email> anacode@sanger.ac.uk
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment