| 1 |
|
| /* hm_sa_bus_perl.h - the Perl-side state and collector for the message bus. |
| 2 |
|
| * |
| 3 |
|
| * Separate from hm_sa_bus.h because that header knows nothing about Perl and |
| 4 |
|
| * should stay that way: it is the substrate an XS consumer reaches through |
| 5 |
|
| * the ABI, and the benchmark harness drives it with no interpreter. This is |
| 6 |
|
| * the thin layer that turns a drain into a list of pairs and a record into a |
| 7 |
|
| * call of a coderef. |
| 8 |
|
| */ |
| 9 |
|
| |
| 10 |
|
| #ifndef HM_SA_BUS_PERL_H |
| 11 |
|
| #define HM_SA_BUS_PERL_H |
| 12 |
|
| |
| 13 |
|
| #include "hm_sa_bus.h" |
| 14 |
|
| |
| 15 |
|
| /* Collect one message as [topic, payload]. The strings are copies: the |
| 16 |
|
| * callback is handed pointers into the cursor's scratch, which the next |
| 17 |
|
| * record overwrites. */ |
| 18 |
72 |
| static void hm_bus_perl_collect(void *ud, uint64_t seq, const char *topic, |
| 19 |
|
| uint32_t tlen, const char *payload, |
| 20 |
|
| uint32_t plen) { |
| 21 |
|
| dTHX; |
| 22 |
72 |
| AV *out = (AV *)ud; |
| 23 |
72 |
| AV *one = newAV(); |
| 24 |
|
| (void)seq; |
| 25 |
72 |
| av_push(one, newSVpvn(topic, tlen)); |
| 26 |
72 |
| av_push(one, newSVpvn(payload, plen)); |
| 27 |
72 |
| av_push(out, newRV_noinc((SV *)one)); |
| 28 |
72 |
| } |
| 29 |
|
| |
| 30 |
|
| /* A registration is a coderef held in this process. It cannot cross a fork, |
| 31 |
|
| * which is why the shared thing is the ring and not the list of readers. */ |
| 32 |
|
| static SV *hm_bus_perl_subs[HM_BUS_SUBS]; |
| 33 |
|
| |
| 34 |
|
| /* Deliver one message to one Perl subscriber. |
| 35 |
|
| * |
| 36 |
|
| * G_EVAL is not optional. This runs from the event loop, called out of an io |
| 37 |
|
| * watcher with no Perl frame around it, and a die from a subscriber would |
| 38 |
|
| * unwind through the loop and take the worker down - which for a chat server |
| 39 |
|
| * means one bad handler silently removing a worker from the pool. A death |
| 40 |
|
| * becomes a warning and the next subscriber still runs. */ |
| 41 |
19 |
| static void hm_bus_perl_deliver(void *ud, uint64_t seq, const char *topic, |
| 42 |
|
| uint32_t tlen, const char *payload, |
| 43 |
|
| uint32_t plen) { |
| 44 |
|
| dTHX; |
| 45 |
19 |
| dSP; |
| 46 |
19 |
| SV *cb = (SV *)ud; |
| 47 |
|
| (void)seq; |
| 48 |
|
| /* |
| 49 |
|
| # uncoverable branch true class:ignore_covered_err |
| 50 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 51 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 52 |
19 |
▶ | if (!cb || !SvOK(cb)) return; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!cb || !SvOK(cb)) return; |
19 |
0 |
19 |
| if (!cb || !SvOK(cb)) return; |
0 |
19 |
19 |
|
| 53 |
|
| |
| 54 |
19 |
| ENTER; SAVETMPS; |
| 55 |
19 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
19 |
19 |
|
| 56 |
19 |
▶ | EXTEND(SP, 2); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 2); |
0 |
19 |
19 |
|
| 57 |
19 |
| PUSHs(sv_2mortal(newSVpvn(topic, tlen))); |
| 58 |
19 |
| PUSHs(sv_2mortal(newSVpvn(payload, plen))); |
| 59 |
19 |
| PUTBACK; |
| 60 |
19 |
| (void)call_sv(cb, G_VOID | G_DISCARD | G_EVAL); |
| 61 |
19 |
| SPAGAIN; |
| 62 |
19 |
▶ | if (SvTRUE(ERRSV)) /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTRUE(ERRSV)) /* # uncoverable condition right count:1 class:ignore_covered_err */ |
19 |
0 |
19 |
| if (SvTRUE(ERRSV)) /* # uncoverable condition right count:1 class:ignore_covered_err */ |
1 |
18 |
19 |
|
| 63 |
1 |
▶ | warn("Hyperman: bus subscriber died: %" SVf, SVfARG(ERRSV)); |
Branch: 1 branch
| Branch | True | False | Total |
| warn("Hyperman: bus subscriber died: %" SVf, SVfARG(ERRSV)); |
1 |
0 |
1 |
|
| 64 |
19 |
| PUTBACK; |
| 65 |
19 |
▶ | FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; LEAVE; |
19 |
0 |
19 |
|
| 66 |
|
| } |
| 67 |
|
| |
| 68 |
|
| #endif /* HM_SA_BUS_PERL_H */ |