Data-ReqRep-Shared

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    one it sends to.

    A timeout of 0, like the non-blocking calls, never waits for a request, a
    reply, a slot or room: "req_wait" with one still sends the request, then
    gives it up at once. Such a call on a Str channel still waits for the
    queue mutex, for two seconds at most when the process holding it is
    stopped, and gives up as soon as a signal arrives; its handler runs once
    the call returns. A timed call keeps its deadline behind a stopped holder,
    except that "recv_wait_multi" taking the rest of its batch, and a send
    giving back arena room, its own as it times out or a dead process's, may
    each run up to two seconds over. A negative timeout, or NaN, waits for
    ever like no timeout at all, so clamp a computed remaining time at 0.
    "req_wait" reads an undef timeout as 0; the other waits read it as no
    timeout.

    Asynchronous:

        my $id   = $cli->send($data);               # non-blocking
        my $id   = $cli->send_wait($data, $secs);   # blocking
        my $resp = $cli->get($id);                   # non-blocking
        my $resp = $cli->get_wait($id, $secs);       # blocking

lib/Data/ReqRep/Shared.pm  view on Meta::CPAN

channels let each stage exit before stopping the one it sends to.

A timeout of 0, like the non-blocking calls, never waits for a request, a
reply, a slot or room: C<req_wait> with one still sends the request, then
gives it up at once. Such a call on a Str channel still waits for the queue
mutex, for two seconds at most when the process holding it is stopped, and
gives up as soon as a signal arrives; its handler runs once the call returns.
A timed call keeps its deadline behind a stopped holder, except that
C<recv_wait_multi> taking the rest of its batch, and a send giving back arena
room, its own as it times out or a dead process's, may each run up to two
seconds over. A negative timeout, or NaN, waits for ever like no timeout at
all, so clamp a computed remaining time at 0. C<req_wait> reads an undef
timeout as 0; the other waits read it as no timeout.

B<Asynchronous>:

    my $id   = $cli->send($data);               # non-blocking
    my $id   = $cli->send_wait($data, $secs);   # blocking
    my $resp = $cli->get($id);                   # non-blocking
    my $resp = $cli->get_wait($id, $secs);       # blocking
    $cli->cancel($id);                           # abandon request

reqrep.h  view on Meta::CPAN

}

static inline uint64_t reqrep_now_ns(void) {
    struct timespec t;
    clock_gettime(CLOCK_MONOTONIC, &t);
    return (uint64_t)t.tv_sec * 1000000000ULL + (uint64_t)t.tv_nsec;
}

static inline void reqrep_make_deadline(double timeout, struct timespec *deadline) {
    clock_gettime(CLOCK_MONOTONIC, deadline);
    if (!(timeout < 1e9)) timeout = 1e9; /* Inf/NaN/huge: the time_t cast would be UB */
    deadline->tv_sec += (time_t)timeout;
    deadline->tv_nsec += (long)((timeout - (double)(time_t)timeout) * 1e9);
    if (deadline->tv_nsec >= 1000000000L) {
        deadline->tv_sec++;
        deadline->tv_nsec -= 1000000000L;
    }
}

static inline double reqrep_time_left(const struct timespec *deadline) {
    struct timespec left;



( run in 1.850 second using v1.01-cache-2.11-cpan-60884a8df76 )