Data-Log-Shared

 view release on metacpan or  search on metacpan

log.h  view on Meta::CPAN

static inline uint64_t log_region_size(const LogHandle *h) {
    return (h->mmap_size > sizeof(LogHeader)) ? (h->mmap_size - sizeof(LogHeader)) : 0;
}

/* ================================================================
 * Utility
 * ================================================================ */

static inline void log_make_deadline(double t, struct timespec *dl) {
    clock_gettime(CLOCK_MONOTONIC, dl);
    if (!(t < 1e9)) t = 1e9; /* clamp Inf/NaN/huge: avoid UB (time_t) cast -> instant spurious timeout */
    dl->tv_sec += (time_t)t;
    dl->tv_nsec += (long)((t - (double)(time_t)t) * 1e9);
    if (dl->tv_nsec >= 1000000000L) { dl->tv_sec++; dl->tv_nsec -= 1000000000L; }
}

static inline int log_remaining(const struct timespec *dl, struct timespec *rem) {
    struct timespec now;
    clock_gettime(CLOCK_MONOTONIC, &now);
    rem->tv_sec = dl->tv_sec - now.tv_sec;
    rem->tv_nsec = dl->tv_nsec - now.tv_nsec;

xt/timeout_validation.t  view on Meta::CPAN

use strict;
use warnings;
use Test::More;
use POSIX qw(_exit);
use Time::HiRes qw(time);
use Data::Log::Shared;

plan skip_all => 'AUTHOR_TESTING not set' unless $ENV{AUTHOR_TESTING};

# Boundary timeouts: negative, +Inf, NaN. None should crash; results
# should match documented behavior or croak cleanly.

my $h = Data::Log::Shared->new(undef, 4096);

# Run each timeout in a child to detect signal-death.
sub run_child {
    my ($label, $code) = @_;
    my $pid = fork // die;
    if ($pid == 0) {
        eval { $code->() };

xt/timeout_validation.t  view on Meta::CPAN

    sub { local $SIG{ALRM} = sub { _exit(0) }; alarm 1; $h->wait_for(0, -1.0) });
isnt $r1, 'signal_11', "negative timeout: no SIGSEGV (got $r1)";
isnt $r1, 'signal_6',  "negative timeout: no SIGABRT (got $r1)";

# +Infinity: same as negative, may block forever
my $r2 = run_child('inf timeout',
    sub { local $SIG{ALRM} = sub { _exit(0) }; alarm 1; $h->wait_for(0, "Inf"+0) });
isnt $r2, 'signal_11', "inf timeout: no SIGSEGV (got $r2)";
isnt $r2, 'signal_6',  "inf timeout: no SIGABRT (got $r2)";

# NaN: implementation-defined, must not crash
my $r3 = run_child('nan timeout',
    sub { local $SIG{ALRM} = sub { _exit(0) }; alarm 1; $h->wait_for(0, "NaN"+0) });
isnt $r3, 'signal_11', "NaN timeout: no SIGSEGV (got $r3)";
isnt $r3, 'signal_6',  "NaN timeout: no SIGABRT (got $r3)";

done_testing;



( run in 1.766 second using v1.01-cache-2.11-cpan-1191d43216d )