xs/sse.xs

filter: Statementstmt 95.4% 21 / 22 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 86.6% 26 / 30 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/punk/punk_import.h ↑ Summary include/punk/punk_session.h »
1 MODULE = Punk PACKAGE = Punk::SSE
2  
3 PROTOTYPES: DISABLE
4  
5 # Server-Sent Events, in C (punk_sse.h). The `sse` route kind hands the socket
6 # to a stream the handler pushes text/event-stream events onto; lib/Punk/SSE.pm
7 # is documentation. _dispatch is reached from punk_serve.h once guards pass.
8 SV *
9 _dispatch(c, rec, env)
10 SV *c
11 SV *rec
12 SV *env
13 CODE:
14 41 RETVAL = punk_sse_dispatch(aTHX_ c, rec, env);
15 OUTPUT:
16 RETVAL
17  
18 MODULE = Punk PACKAGE = Punk::SSE
19  
20 # send($data): one event ($data a ref is JSON-encoded; a multi-line string
21 # becomes multiple data: lines). event($name, $data): a named event. Both chain.
22 SV *
23 send(self, data = &PL_sv_undef)
24 SV *self
25 SV *data
26 CODE:
27 81 se_send(aTHX_ se_of(aTHX_ self), data);
28 81 RETVAL = newSVsv(self);
29 OUTPUT:
30 RETVAL
31  
32 SV *
33 event(self, name, data = &PL_sv_undef)
34 SV *self
35 SV *name
36 SV *data
37 CODE:
38 20 se_event(aTHX_ se_of(aTHX_ self), name, data);
39 20 RETVAL = newSVsv(self);
40 OUTPUT:
41 RETVAL
42  
43 # comment($text) (: text), id($id) and retry($ms) write a single SSE field.
44 # id/retry are their own line, so send them just before the event they stamp.
45 SV *
46 comment(self, text = &PL_sv_undef)
47 SV *self
48 SV *text
49 CODE:
50 9 se_field(aTHX_ se_of(aTHX_ self), ": ", text);
51 9 RETVAL = newSVsv(self);
52 OUTPUT:
53 RETVAL
54  
55 SV *
56 id(self, id)
57 SV *self
58 SV *id
59 CODE:
60 9 se_field(aTHX_ se_of(aTHX_ self), "id: ", id);
61 9 RETVAL = newSVsv(self);
62 OUTPUT:
63 RETVAL
64  
65 SV *
66 retry(self, ms)
67 SV *self
68 SV *ms
69 CODE:
70 8 se_field(aTHX_ se_of(aTHX_ self), "retry: ", ms);
71 8 RETVAL = newSVsv(self);
72 OUTPUT:
73 RETVAL
74  
75 # on(close => $cb): the only event, fired once when the stream ends (client
76 # gone, close, or a write error). Chains.
77 SV *
78 on(self, event, cb)
79 SV *self
80 SV *event
81 SV *cb
82 CODE:
83 {
84 2 punk_sse *sse = se_of(aTHX_ self);
85 2 STRLEN el; const char *ev = SvPV_const(event, el);
86 2 ▶ # uncoverable branch true
Branch: 2 branches
BranchTrueFalseTotal
# uncoverable branch true 2 0 2
# uncoverable branch true 0 2 2
87 0 # uncoverable condition left count:1 class:ignore_covered_err
88 2 ▶ # uncoverable condition left count:2 class:ignore_covered_err
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable condition left count:2 class:ignore_covered_err 2 0 2
89 2 if (!(el == 5 && memEQ(ev, "close", 5)))
90 2 croak("Punk::SSE::Stream: unknown event '%s' (only 'close')", ev); /* # uncoverable statement */
91 # uncoverable branch false
92 # uncoverable condition right count:1 class:ignore_covered_err
93 if (!sse->cbs) sse->cbs = newHV();
94 (void)hv_store(sse->cbs, ev, (I32)el, newSVsv(cb), 0);
95 RETVAL = newSVsv(self);
96 }
97 OUTPUT:
98 RETVAL
99  
100 # close: end the stream now.
101 SV *
102 close(self)
103 SV *self
104 CODE:
105 35 se_teardown(aTHX_ se_of(aTHX_ self));
106 35 RETVAL = newSVsv(self);
107 OUTPUT:
108 RETVAL
109  
110 IV
111 is_open(self)
112 SV *self
113 CODE:
114 34 ▶ RETVAL = se_of(aTHX_ self)->state == SSE_OPEN ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = se_of(aTHX_ self)->state == SSE_OPEN ? 1 : 0; 31 3 34
115 OUTPUT:
116 RETVAL
117  
118 void
119 DESTROY(self)
120 SV *self
121 CODE:
122 37 se_free(aTHX_ se_of(aTHX_ self));
« include/punk/punk_import.h ↑ Summary include/punk/punk_session.h »