xs/sse.xs

filter: Statementstmt 63.6% 14 / 22 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 46.6% 14 / 30 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/dispatch.xs ↑ Summary include/punk/punk_sse.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 6 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 11 se_send(aTHX_ se_of(aTHX_ self), data);
28 11 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 3 se_event(aTHX_ se_of(aTHX_ self), name, data);
39 3 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 2 se_field(aTHX_ se_of(aTHX_ self), ": ", text);
51 2 RETVAL = newSVsv(self);
52 OUTPUT:
53 RETVAL
54  
55 SV *
56 id(self, id)
57 SV *self
58 SV *id
59 CODE:
60 2 se_field(aTHX_ se_of(aTHX_ self), "id: ", id);
61 2 RETVAL = newSVsv(self);
62 OUTPUT:
63 RETVAL
64  
65 SV *
66 retry(self, ms)
67 SV *self
68 SV *ms
69 CODE:
70 1 se_field(aTHX_ se_of(aTHX_ self), "retry: ", ms);
71 1 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 0 punk_sse *sse = se_of(aTHX_ self);
85 0 STRLEN el; const char *ev = SvPV_const(event, el);
86 0 ▶ if (!(el == 5 && memEQ(ev, "close", 5)))
Branch: 2 branches
BranchTrueFalseTotal
if (!(el == 5 && memEQ(ev, "close", 5))) 0 0 0
if (!(el == 5 && memEQ(ev, "close", 5))) 0 0 0
87 0 croak("Punk::SSE::Stream: unknown event '%s' (only 'close')", ev);
88 0 ▶ if (!sse->cbs) sse->cbs = newHV();
Branch: 1 branch
BranchTrueFalseTotal
if (!sse->cbs) sse->cbs = newHV(); 0 0 0
89 0 (void)hv_store(sse->cbs, ev, (I32)el, newSVsv(cb), 0);
90 0 RETVAL = newSVsv(self);
91 }
92 OUTPUT:
93 RETVAL
94  
95 # close: end the stream now.
96 SV *
97 close(self)
98 SV *self
99 CODE:
100 4 se_teardown(aTHX_ se_of(aTHX_ self));
101 4 RETVAL = newSVsv(self);
102 OUTPUT:
103 RETVAL
104  
105 IV
106 is_open(self)
107 SV *self
108 CODE:
109 0 ▶ RETVAL = se_of(aTHX_ self)->state == SSE_OPEN ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = se_of(aTHX_ self)->state == SSE_OPEN ? 1 : 0; 0 0 0
110 OUTPUT:
111 RETVAL
112  
113 void
114 DESTROY(self)
115 SV *self
116 CODE:
117 4 se_free(aTHX_ se_of(aTHX_ self));
« xs/dispatch.xs ↑ Summary include/punk/punk_sse.h »