RabbitMQ.xs

filter: Statementstmt 56.4% 214 / 379 Branchbran 44.5% 122 / 274 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 51.4% 336 / 653 SCAR 0
CC
0
Cov
0%
CRAP 0
« amqp_connection.c ↑ Summary amqp_api.c »
1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4  
5 #include "amqp.h"
6 #include "amqp_private.h"
7 #include "amqp_framing.h"
8  
9 typedef amqp_connection_state_t Net__RabbitMQ;
10  
11 #define int_from_hv(hv,name) \
12 do { SV **v; if(NULL != (v = hv_fetch(hv, #name, strlen(#name), 0))) name = SvIV(*v); } while(0)
13 #define double_from_hv(hv,name) \
14 do { SV **v; if(NULL != (v = hv_fetch(hv, #name, strlen(#name), 0))) name = SvNV(*v); } while(0)
15 #define str_from_hv(hv,name) \
16 do { SV **v; if(NULL != (v = hv_fetch(hv, #name, strlen(#name), 0))) name = SvPV_nolen(*v); } while(0)
17  
18 18 void die_on_error(pTHX_ int x, char const *context) {
19 18 ▶ if (x < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (x < 0) { 18 0 18
20 18 Perl_croak(aTHX_ "%s: %s\n", context, strerror(-x));
21 }
22 0 }
23  
24 60 void die_on_amqp_error(pTHX_ amqp_rpc_reply_t x, char const *context) {
25 60 switch (x.reply_type) {
26 0 case AMQP_RESPONSE_NORMAL:
27 0 return;
28  
29 0 case AMQP_RESPONSE_NONE:
30 0 Perl_croak(aTHX_ "%s: missing RPC reply type!", context);
31 break;
32  
33 60 case AMQP_RESPONSE_LIBRARY_EXCEPTION:
34 60 Perl_croak(aTHX_ "%s: %s\n", context,
35 60 ▶ x.library_errno ? strerror(x.library_errno) : "(end-of-stream)");
Branch: 1 branch
BranchTrueFalseTotal
x.library_errno ? strerror(x.library_errno) : "(end-of-stream)"); 60 0 60
36 break;
37  
38 0 case AMQP_RESPONSE_SERVER_EXCEPTION:
39 0 switch (x.reply.id) {
40 0 case AMQP_CONNECTION_CLOSE_METHOD: {
41 0 amqp_connection_close_t *m = (amqp_connection_close_t *) x.reply.decoded;
42 0 Perl_croak(aTHX_ "%s: server connection error %d, message: %.*s",
43 context,
44 0 m->reply_code,
45 0 (int) m->reply_text.len, (char *) m->reply_text.bytes);
46 break;
47 }
48 0 case AMQP_CHANNEL_CLOSE_METHOD: {
49 0 amqp_channel_close_t *m = (amqp_channel_close_t *) x.reply.decoded;
50 0 Perl_croak(aTHX_ "%s: server channel error %d, message: %.*s",
51 context,
52 0 m->reply_code,
53 0 (int) m->reply_text.len, (char *) m->reply_text.bytes);
54 break;
55 }
56 0 default:
57 0 Perl_croak(aTHX_ "%s: unknown server error, method id 0x%08X", context, x.reply.id);
58 break;
59 }
60 break;
61 }
62 }
63  
64 static void
65 0 internal_brcb(amqp_channel_t channel, amqp_basic_return_t *m, void *vsv) {
66 HV *mp;
67 0 SV *sv = (SV *)vsv;
68 0 dSP;
69 0 ENTER;
70 0 SAVETMPS;
71 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
72 0 ▶ XPUSHs(sv_2mortal(newSViv(channel)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(channel))); 0 0 0
73 0 mp = newHV();
74 0 hv_store(mp, "reply_code", strlen("reply_code"), newSViv(m->reply_code), 0);
75 0 hv_store(mp, "reply_text", strlen("reply_text"),
76 newSVpvn(m->reply_text.bytes, m->reply_text.len), 0);
77 0 hv_store(mp, "exchange", strlen("exchange"),
78 newSVpvn(m->exchange.bytes, m->exchange.len), 0);
79 0 hv_store(mp, "routing_key", strlen("routing_key"),
80 newSVpvn(m->routing_key.bytes, m->routing_key.len), 0);
81 0 ▶ XPUSHs(sv_2mortal((SV *)newRV((SV *)mp)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal((SV *)newRV((SV *)mp))); 0 0 0
82 0 PUTBACK;
83 0 call_sv(sv, G_DISCARD);
84 0 SPAGAIN;
85 0 PUTBACK;
86 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
87 0 LEAVE;
88 0 }
89 11 int internal_recv(HV *RETVAL, amqp_connection_state_t conn, int piggyback) {
90 amqp_frame_t frame;
91 amqp_basic_deliver_t *d;
92 amqp_basic_properties_t *p;
93 size_t body_target;
94 size_t body_received;
95 int result;
96  
97 11 result = 0;
98 0 while (1) {
99 SV *payload;
100  
101 11 ▶ if(!piggyback) {
Branch: 1 branch
BranchTrueFalseTotal
if(!piggyback) { 11 0 11
102 11 amqp_maybe_release_buffers(conn);
103 11 result = amqp_simple_wait_frame(conn, &frame);
104 11 ▶ if (result <= 0) break;
Branch: 1 branch
BranchTrueFalseTotal
if (result <= 0) break; 11 0 11
105 0 ▶ if (frame.frame_type == AMQP_FRAME_HEARTBEAT) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame.frame_type == AMQP_FRAME_HEARTBEAT) { 0 0 0
106 0 hv_store(RETVAL, "frame_type", strlen("frame_type"), newSVpv((const char *)"heartbeat", 0), 0);
107 0 return result;
108 }
109 0 ▶ if (frame.frame_type != AMQP_FRAME_METHOD) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (frame.frame_type != AMQP_FRAME_METHOD) continue; 0 0 0
110 0 ▶ if (frame.payload.method.id != AMQP_BASIC_DELIVER_METHOD) continue;
Branch: 1 branch
BranchTrueFalseTotal
if (frame.payload.method.id != AMQP_BASIC_DELIVER_METHOD) continue; 0 0 0
111 0 d = (amqp_basic_deliver_t *) frame.payload.method.decoded;
112 0 hv_store(RETVAL, "delivery_tag", strlen("delivery_tag"), newSVpvn((const char *)&d->delivery_tag, sizeof(d->delivery_tag)), 0);
113 0 hv_store(RETVAL, "exchange", strlen("exchange"), newSVpvn(d->exchange.bytes, d->exchange.len), 0);
114 0 hv_store(RETVAL, "consumer_tag", strlen("consumer_tag"), newSVpvn(d->consumer_tag.bytes, d->consumer_tag.len), 0);
115 0 hv_store(RETVAL, "routing_key", strlen("routing_key"), newSVpvn(d->routing_key.bytes, d->routing_key.len), 0);
116 0 piggyback = 0;
117 }
118  
119 0 result = amqp_simple_wait_frame(conn, &frame);
120 0 ▶ if (frame.frame_type == AMQP_FRAME_HEARTBEAT) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame.frame_type == AMQP_FRAME_HEARTBEAT) { 0 0 0
121 0 hv_store(RETVAL, "frame_type", strlen("frame_type"), newSVpv((const char *)"heartbeat", 0), 0);
122 0 return result;
123 }
124 0 ▶ if (result <= 0) break;
Branch: 1 branch
BranchTrueFalseTotal
if (result <= 0) break; 0 0 0
125  
126 0 ▶ if (frame.frame_type != AMQP_FRAME_HEADER)
Branch: 1 branch
BranchTrueFalseTotal
if (frame.frame_type != AMQP_FRAME_HEADER) 0 0 0
127 0 Perl_croak(aTHX_ "Unexpected header %d!", frame.frame_type);
128  
129 HV *props;
130 0 props = newHV();
131 0 hv_store(RETVAL, "props", strlen("props"), newRV_noinc((SV *)props), 0);
132  
133 0 p = (amqp_basic_properties_t *) frame.payload.properties.decoded;
134 0 ▶ if (p->_flags & AMQP_BASIC_CONTENT_TYPE_FLAG) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->_flags & AMQP_BASIC_CONTENT_TYPE_FLAG) { 0 0 0
135 0 hv_store(props, "content_type", strlen("content_type"),
136 newSVpvn(p->content_type.bytes, p->content_type.len), 0);
137 }
138 0 ▶ if (p->_flags & AMQP_BASIC_CONTENT_ENCODING_FLAG) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->_flags & AMQP_BASIC_CONTENT_ENCODING_FLAG) { 0 0 0
139 0 hv_store(props, "content_encoding", strlen("content_encoding"),
140 newSVpvn(p->content_encoding.bytes, p->content_encoding.len), 0);
141 }
142 0 ▶ if (p->_flags & AMQP_BASIC_CORRELATION_ID_FLAG) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->_flags & AMQP_BASIC_CORRELATION_ID_FLAG) { 0 0 0
143 0 hv_store(props, "correlation_id", strlen("correlation_id"),
144 newSVpvn(p->correlation_id.bytes, p->correlation_id.len), 0);
145 }
146 0 ▶ if (p->_flags & AMQP_BASIC_REPLY_TO_FLAG) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->_flags & AMQP_BASIC_REPLY_TO_FLAG) { 0 0 0
147 0 hv_store(props, "reply_to", strlen("reply_to"),
148 newSVpvn(p->reply_to.bytes, p->reply_to.len), 0);
149 }
150 0 ▶ if (p->_flags & AMQP_BASIC_EXPIRATION_FLAG) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->_flags & AMQP_BASIC_EXPIRATION_FLAG) { 0 0 0
151 0 hv_store(props, "expiration", strlen("expiration"),
152 newSVpvn(p->expiration.bytes, p->expiration.len), 0);
153 }
154 0 ▶ if (p->_flags & AMQP_BASIC_MESSAGE_ID_FLAG) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->_flags & AMQP_BASIC_MESSAGE_ID_FLAG) { 0 0 0
155 0 hv_store(props, "message_id", strlen("message_id"),
156 newSVpvn(p->message_id.bytes, p->message_id.len), 0);
157 }
158 0 ▶ if (p->_flags & AMQP_BASIC_TYPE_FLAG) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->_flags & AMQP_BASIC_TYPE_FLAG) { 0 0 0
159 0 hv_store(props, "type", strlen("type"),
160 newSVpvn(p->type.bytes, p->type.len), 0);
161 }
162 0 ▶ if (p->_flags & AMQP_BASIC_USER_ID_FLAG) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->_flags & AMQP_BASIC_USER_ID_FLAG) { 0 0 0
163 0 hv_store(props, "user_id", strlen("user_id"),
164 newSVpvn(p->user_id.bytes, p->user_id.len), 0);
165 }
166 0 ▶ if (p->_flags & AMQP_BASIC_APP_ID_FLAG) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->_flags & AMQP_BASIC_APP_ID_FLAG) { 0 0 0
167 0 hv_store(props, "app_id", strlen("app_id"),
168 newSVpvn(p->app_id.bytes, p->app_id.len), 0);
169 }
170 0 ▶ if (p->_flags & AMQP_BASIC_DELIVERY_MODE_FLAG) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->_flags & AMQP_BASIC_DELIVERY_MODE_FLAG) { 0 0 0
171 0 hv_store(props, "delivery_mode", strlen("delivery_mode"),
172 newSViv(p->delivery_mode), 0);
173 }
174 0 ▶ if (p->_flags & AMQP_BASIC_PRIORITY_FLAG) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->_flags & AMQP_BASIC_PRIORITY_FLAG) { 0 0 0
175 0 hv_store(props, "priority", strlen("priority"),
176 newSViv(p->priority), 0);
177 }
178 0 ▶ if (p->_flags & AMQP_BASIC_TIMESTAMP_FLAG) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->_flags & AMQP_BASIC_TIMESTAMP_FLAG) { 0 0 0
179 0 hv_store(props, "timestamp", strlen("timestamp"),
180 newSViv(p->timestamp), 0);
181 }
182  
183 0 ▶ if (p->_flags & AMQP_BASIC_HEADERS_FLAG) {
Branch: 1 branch
BranchTrueFalseTotal
if (p->_flags & AMQP_BASIC_HEADERS_FLAG) { 0 0 0
184 int i;
185 SV *val;
186 0 HV *headers = newHV();
187 0 hv_store( props, "headers", strlen("headers"), newRV_noinc((SV *)headers), 0 );
188  
189 0 ▶ for( i=0; i < p->headers.num_entries; ++i ) {
Branch: 1 branch
BranchTrueFalseTotal
for( i=0; i < p->headers.num_entries; ++i ) { 0 0 0
190 0 ▶ if( p->headers.entries[i].kind == 'I' ) {
Branch: 1 branch
BranchTrueFalseTotal
if( p->headers.entries[i].kind == 'I' ) { 0 0 0
191 0 hv_store( headers,
192 p->headers.entries[i].key.bytes, p->headers.entries[i].key.len,
193 newSViv(p->headers.entries[i].value.i32),
194 0
195 );
196 }
197 0 ▶ else if( p->headers.entries[i].kind == 'S' ) {
Branch: 1 branch
BranchTrueFalseTotal
else if( p->headers.entries[i].kind == 'S' ) { 0 0 0
198 0 hv_store( headers,
199 p->headers.entries[i].key.bytes, p->headers.entries[i].key.len,
200 newSVpvn( p->headers.entries[i].value.bytes.bytes, p->headers.entries[i].value.bytes.len),
201 0
202 );
203 }
204 0 ▶ else if( p->headers.entries[i].kind == 't' ) {
Branch: 1 branch
BranchTrueFalseTotal
else if( p->headers.entries[i].kind == 't' ) { 0 0 0
205 0 hv_store( headers,
206 p->headers.entries[i].key.bytes, p->headers.entries[i].key.len,
207 newSViv(p->headers.entries[i].value.boolean),
208 0
209 );
210 }
211 else {
212 0 Perl_croak(aTHX_ "Unhandled AMQP type '%c'", p->headers.entries[i].kind == 't');
213 }
214 }
215 }
216  
217 0 body_target = frame.payload.properties.body_size;
218 0 body_received = 0;
219 0 payload = newSVpvn("", 0);
220  
221 0 ▶ while (body_received < body_target) {
Branch: 1 branch
BranchTrueFalseTotal
while (body_received < body_target) { 0 0 0
222 0 result = amqp_simple_wait_frame(conn, &frame);
223 0 ▶ if (result <= 0) break;
Branch: 1 branch
BranchTrueFalseTotal
if (result <= 0) break; 0 0 0
224  
225 0 ▶ if (frame.frame_type != AMQP_FRAME_BODY) {
Branch: 1 branch
BranchTrueFalseTotal
if (frame.frame_type != AMQP_FRAME_BODY) { 0 0 0
226 0 Perl_croak(aTHX_ "Expected fram body, got %d!", frame.frame_type);
227 }
228  
229 0 body_received += frame.payload.body_fragment.len;
230 assert(body_received <= body_target);
231  
232 0 sv_catpvn(payload, frame.payload.body_fragment.bytes, frame.payload.body_fragment.len);
233 }
234  
235 0 ▶ if (body_received != body_target) {
Branch: 1 branch
BranchTrueFalseTotal
if (body_received != body_target) { 0 0 0
236 /* Can only happen when amqp_simple_wait_frame returns <= 0 */
237 /* We break here to close the connection */
238 0 Perl_croak(aTHX_ "Short read %llu != %llu", (long long unsigned int)body_received, (long long unsigned int)body_target);
239 }
240 0 hv_store(RETVAL, "body", strlen("body"), payload, 0);
241 0 break;
242 }
243 11 return result;
244 }
245  
246 6 void hash_to_amqp_table(amqp_connection_state_t conn, HV *hash, amqp_table_t *table) {
247 HE *he;
248 char *key;
249 SV *value;
250 I32 retlen;
251  
252 6 ▶ amqp_create_table(conn, table, HvKEYS(hash));
Branch: 1 branch
BranchTrueFalseTotal
amqp_create_table(conn, table, HvKEYS(hash)); 0 6 6
253  
254 6 hv_iterinit(hash);
255 23 ▶ while (NULL != (he = hv_iternext(hash))) {
Branch: 1 branch
BranchTrueFalseTotal
while (NULL != (he = hv_iternext(hash))) { 17 6 23
256 17 key = hv_iterkey(he, &retlen);
257 17 value = hv_iterval(hash, he);
258  
259 17 ▶ if (SvGMAGICAL(value))
Branch: 1 branch
BranchTrueFalseTotal
if (SvGMAGICAL(value)) 0 17 17
260 0 mg_get(value);
261  
262 17 ▶ if (SvPOK(value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvPOK(value)) { 6 11 17
263 6 amqp_table_add_string(conn, table, amqp_cstring_bytes(key), amqp_cstring_bytes(SvPV_nolen(value)));
264 11 ▶ } else if (SvIOK(value)) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (SvIOK(value)) { 11 0 11
265 11 amqp_table_add_int(conn, table, amqp_cstring_bytes(key), (uint64_t) SvIV(value));
266 } else {
267 0 Perl_croak( aTHX_ "Unsupported SvType for hash value: %d", SvTYPE(value) );
268 }
269 }
270 6 }
271  
272 MODULE = Net::RabbitMQ PACKAGE = Net::RabbitMQ PREFIX = net_rabbitmq_
273  
274 REQUIRE: 1.9505
275 PROTOTYPES: DISABLE
276  
277 int
278 net_rabbitmq_connect(conn, hostname, options)
279 Net::RabbitMQ conn
280 char *hostname
281 HV *options
282 PREINIT:
283 int sockfd;
284 18 char *user = "guest";
285 18 char *password = "guest";
286 18 char *vhost = "/";
287 18 int port = 5672;
288 18 int channel_max = 0;
289 18 int frame_max = 131072;
290 18 int heartbeat = 0;
291 18 ▶ double timeout = -1;
Branch: 1 branch
BranchTrueFalseTotal
double timeout = -1; 18 0 18
292 struct timeval to;
293 CODE:
294 36 ▶ str_from_hv(options, user);
Branch: 1 branch
BranchTrueFalseTotal
str_from_hv(options, user); 18 0 18
295 36 ▶ str_from_hv(options, password);
Branch: 1 branch
BranchTrueFalseTotal
str_from_hv(options, password); 18 0 18
296 18 ▶ str_from_hv(options, vhost);
Branch: 1 branch
BranchTrueFalseTotal
str_from_hv(options, vhost); 0 18 18
297 18 ▶ int_from_hv(options, channel_max);
Branch: 1 branch
BranchTrueFalseTotal
int_from_hv(options, channel_max); 0 18 18
298 18 ▶ int_from_hv(options, frame_max);
Branch: 1 branch
BranchTrueFalseTotal
int_from_hv(options, frame_max); 0 18 18
299 18 ▶ int_from_hv(options, heartbeat);
Branch: 1 branch
BranchTrueFalseTotal
int_from_hv(options, heartbeat); 1 17 18
300 18 ▶ int_from_hv(options, port);
Branch: 1 branch
BranchTrueFalseTotal
int_from_hv(options, port); 0 18 18
301 18 ▶ double_from_hv(options, timeout);
Branch: 1 branch
BranchTrueFalseTotal
double_from_hv(options, timeout); 1 17 18
302 18 ▶ if(timeout >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if(timeout >= 0) { 1 17 18
303 1 to.tv_sec = floor(timeout);
304 1 to.tv_usec = 1000000.0 * (timeout - floor(timeout));
305 }
306  
307 18 ▶ die_on_error(aTHX_ sockfd = amqp_open_socket(hostname, port, (timeout<0)?NULL:&to), "Opening socket");
Branch: 1 branch
BranchTrueFalseTotal
die_on_error(aTHX_ sockfd = amqp_open_socket(hostname, port, (timeout<0)?NULL:&to), "Opening socket"); 17 1 18
308 0 amqp_set_sockfd(conn, sockfd);
309 0 die_on_amqp_error(aTHX_ amqp_login(conn, vhost, channel_max, frame_max,
310 heartbeat, AMQP_SASL_METHOD_PLAIN,
311 user, password),
312 "Logging in");
313 0 ▶ RETVAL = sockfd;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = sockfd; 0 0 0
314 OUTPUT:
315 RETVAL
316  
317 void
318 net_rabbitmq_basic_return(conn, code)
319 Net::RabbitMQ conn
320 SV *code
321 CODE:
322 1 SvREFCNT_inc(code);
323 1 amqp_set_basic_return_cb(conn, internal_brcb, code);
324  
325 void
326 net_rabbitmq_channel_open(conn, channel)
327 Net::RabbitMQ conn
328 int channel
329 PREINIT:
330 amqp_rpc_reply_t *amqp_rpc_reply;
331 CODE:
332 16 amqp_channel_open(conn, channel);
333 16 amqp_rpc_reply = amqp_get_rpc_reply();
334 16 die_on_amqp_error(aTHX_ *amqp_rpc_reply, "Opening channel");
335  
336 void
337 net_rabbitmq_channel_close(conn, channel)
338 Net::RabbitMQ conn
339 int channel
340 CODE:
341 0 die_on_amqp_error(aTHX_ amqp_channel_close(conn, channel, AMQP_REPLY_SUCCESS), "Closing channel");
342  
343 void
344 net_rabbitmq_exchange_declare(conn, channel, exchange, options = NULL, args = NULL)
345 Net::RabbitMQ conn
346 int channel
347 char *exchange
348 HV *options
349 HV *args
350 PREINIT:
351 amqp_rpc_reply_t *amqp_rpc_reply;
352 2 char *exchange_type = "direct";
353 2 int passive = 0;
354 2 int durable = 0;
355 2 int auto_delete = 1;
356 2 ▶ amqp_table_t arguments = AMQP_EMPTY_TABLE;
Branch: 1 branch
BranchTrueFalseTotal
amqp_table_t arguments = AMQP_EMPTY_TABLE; 2 0 2
357 CODE:
358 2 ▶ if(options) {
Branch: 1 branch
BranchTrueFalseTotal
if(options) { 2 0 2
359 4 ▶ str_from_hv(options, exchange_type);
Branch: 1 branch
BranchTrueFalseTotal
str_from_hv(options, exchange_type); 2 0 2
360 2 ▶ int_from_hv(options, passive);
Branch: 1 branch
BranchTrueFalseTotal
int_from_hv(options, passive); 1 1 2
361 2 ▶ int_from_hv(options, durable);
Branch: 1 branch
BranchTrueFalseTotal
int_from_hv(options, durable); 1 1 2
362 2 ▶ int_from_hv(options, auto_delete);
Branch: 1 branch
BranchTrueFalseTotal
int_from_hv(options, auto_delete); 2 0 2
363 }
364 2 amqp_exchange_declare(conn, channel, amqp_cstring_bytes(exchange), amqp_cstring_bytes(exchange_type),
365 passive, durable, auto_delete, arguments);
366 2 amqp_rpc_reply = amqp_get_rpc_reply();
367 2 die_on_amqp_error(aTHX_ *amqp_rpc_reply, "Declaring exchange");
368  
369 void
370 net_rabbitmq_exchange_delete(conn, channel, exchange, options = NULL)
371 Net::RabbitMQ conn
372 int channel
373 char *exchange
374 HV *options
375 PREINIT:
376 amqp_rpc_reply_t *amqp_rpc_reply;
377 0 int if_unused = 1;
378 0 ▶ int nowait = 0;
Branch: 1 branch
BranchTrueFalseTotal
int nowait = 0; 0 0 0
379 CODE:
380 0 ▶ if(options) {
Branch: 1 branch
BranchTrueFalseTotal
if(options) { 0 0 0
381 0 ▶ int_from_hv(options, if_unused);
Branch: 1 branch
BranchTrueFalseTotal
int_from_hv(options, if_unused); 0 0 0
382 0 ▶ int_from_hv(options, nowait);
Branch: 1 branch
BranchTrueFalseTotal
int_from_hv(options, nowait); 0 0 0
383 }
384 0 amqp_exchange_delete(conn, channel, amqp_cstring_bytes(exchange), if_unused, nowait);
385 0 amqp_rpc_reply = amqp_get_rpc_reply();
386 0 die_on_amqp_error(aTHX_ *amqp_rpc_reply, "Deleting exchange");
387  
388 void
389 net_rabbitmq_queue_declare(conn, channel, queuename, options = NULL, args = NULL)
390 Net::RabbitMQ conn
391 int channel
392 char *queuename
393 HV *options
394 HV *args
395 PREINIT:
396 amqp_rpc_reply_t *amqp_rpc_reply;
397 11 int passive = 0;
398 11 int durable = 0;
399 11 int exclusive = 0;
400 11 int auto_delete = 1;
401 11 amqp_table_t arguments = AMQP_EMPTY_TABLE;
402 11 ▶ amqp_bytes_t queuename_b = AMQP_EMPTY_BYTES;
Branch: 1 branch
BranchTrueFalseTotal
amqp_bytes_t queuename_b = AMQP_EMPTY_BYTES; 11 0 11
403 PPCODE:
404 11 ▶ if(queuename && strcmp(queuename, "")) queuename_b = amqp_cstring_bytes(queuename);
Branch: 2 branches
BranchTrueFalseTotal
if(queuename && strcmp(queuename, "")) queuename_b = amqp_cstring_bytes(queuename); 11 0 11
if(queuename && strcmp(queuename, "")) queuename_b = amqp_cstring_bytes(queuename); 7 4 11
405 11 ▶ if(options) {
Branch: 1 branch
BranchTrueFalseTotal
if(options) { 11 0 11
406 11 ▶ int_from_hv(options, passive);
Branch: 1 branch
BranchTrueFalseTotal
int_from_hv(options, passive); 8 3 11
407 11 ▶ int_from_hv(options, durable);
Branch: 1 branch
BranchTrueFalseTotal
int_from_hv(options, durable); 8 3 11
408 11 ▶ int_from_hv(options, exclusive);
Branch: 1 branch
BranchTrueFalseTotal
int_from_hv(options, exclusive); 8 3 11
409 11 ▶ int_from_hv(options, auto_delete);
Branch: 1 branch
BranchTrueFalseTotal
int_from_hv(options, auto_delete); 11 0 11
410 }
411 11 ▶ if(args)
Branch: 1 branch
BranchTrueFalseTotal
if(args) 0 11 11
412 0 hash_to_amqp_table(conn, args, &arguments);
413 11 amqp_queue_declare_ok_t *r = amqp_queue_declare(conn, channel, queuename_b, passive,
414 durable, exclusive, auto_delete,
415 arguments);
416 11 amqp_rpc_reply = amqp_get_rpc_reply();
417 11 die_on_amqp_error(aTHX_ *amqp_rpc_reply, "Declaring queue");
418 0 ▶ XPUSHs(sv_2mortal(newSVpvn(r->queue.bytes, r->queue.len)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvn(r->queue.bytes, r->queue.len))); 0 0 0
419 0 ▶ if(GIMME_V == G_ARRAY) {
Branch: 1 branch
BranchTrueFalseTotal
if(GIMME_V == G_ARRAY) { 0 0 0
420 0 ▶ XPUSHs(sv_2mortal(newSVuv(r->message_count)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVuv(r->message_count))); 0 0 0
421 0 ▶ XPUSHs(sv_2mortal(newSVuv(r->consumer_count)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVuv(r->consumer_count))); 0 0 0
422 }
423  
424 void
425 net_rabbitmq_queue_bind(conn, channel, queuename, exchange, bindingkey, args = NULL)
426 Net::RabbitMQ conn
427 int channel
428 char *queuename
429 char *exchange
430 char *bindingkey
431 HV *args
432 PREINIT:
433 amqp_rpc_reply_t *amqp_rpc_reply;
434 8 ▶ amqp_table_t arguments = AMQP_EMPTY_TABLE;
Branch: 1 branch
BranchTrueFalseTotal
amqp_table_t arguments = AMQP_EMPTY_TABLE; 8 0 8
435 CODE:
436 8 ▶ if(queuename == NULL || exchange == NULL)
Branch: 2 branches
BranchTrueFalseTotal
if(queuename == NULL || exchange == NULL) 8 0 8
if(queuename == NULL || exchange == NULL) 0 8 8
437 0 Perl_croak(aTHX_ "queuename and exchange must both be specified");
438 8 ▶ if(bindingkey == NULL && args == NULL)
Branch: 2 branches
BranchTrueFalseTotal
if(bindingkey == NULL && args == NULL) 0 8 8
if(bindingkey == NULL && args == NULL) 0 0 0
439 0 Perl_croak(aTHX_ "bindingkey or args must be specified");
440 8 ▶ if(args)
Branch: 1 branch
BranchTrueFalseTotal
if(args) 1 7 8
441 1 hash_to_amqp_table(conn, args, &arguments);
442 8 amqp_queue_bind(conn, channel, amqp_cstring_bytes(queuename),
443 amqp_cstring_bytes(exchange),
444 amqp_cstring_bytes(bindingkey),
445 arguments);
446 8 amqp_rpc_reply = amqp_get_rpc_reply();
447 8 die_on_amqp_error(aTHX_ *amqp_rpc_reply, "Binding queue");
448  
449 void
450 net_rabbitmq_queue_unbind(conn, channel, queuename, exchange, bindingkey, args = NULL)
451 Net::RabbitMQ conn
452 int channel
453 char *queuename
454 char *exchange
455 char *bindingkey
456 HV *args
457 PREINIT:
458 amqp_rpc_reply_t *amqp_rpc_reply;
459 1 ▶ amqp_table_t arguments = AMQP_EMPTY_TABLE;
Branch: 1 branch
BranchTrueFalseTotal
amqp_table_t arguments = AMQP_EMPTY_TABLE; 1 0 1
460 CODE:
461 1 ▶ if(queuename == NULL || exchange == NULL)
Branch: 2 branches
BranchTrueFalseTotal
if(queuename == NULL || exchange == NULL) 1 0 1
if(queuename == NULL || exchange == NULL) 0 1 1
462 0 Perl_croak(aTHX_ "queuename and exchange must both be specified");
463 1 ▶ if(bindingkey == NULL && args == NULL)
Branch: 2 branches
BranchTrueFalseTotal
if(bindingkey == NULL && args == NULL) 0 1 1
if(bindingkey == NULL && args == NULL) 0 0 0
464 0 Perl_croak(aTHX_ "bindingkey or args must be specified");
465 1 ▶ if(args)
Branch: 1 branch
BranchTrueFalseTotal
if(args) 1 0 1
466 1 hash_to_amqp_table(conn, args, &arguments);
467 1 amqp_queue_unbind(conn, channel, amqp_cstring_bytes(queuename),
468 amqp_cstring_bytes(exchange),
469 amqp_cstring_bytes(bindingkey),
470 arguments);
471 1 amqp_rpc_reply = amqp_get_rpc_reply();
472 1 die_on_amqp_error(aTHX_ *amqp_rpc_reply, "Unbinding queue");
473  
474 SV *
475 net_rabbitmq_consume(conn, channel, queuename, options = NULL)
476 Net::RabbitMQ conn
477 int channel
478 char *queuename
479 HV *options
480 PREINIT:
481 amqp_rpc_reply_t *amqp_rpc_reply;
482 amqp_basic_consume_ok_t *r;
483 9 char *consumer_tag = NULL;
484 9 int no_local = 0;
485 9 int no_ack = 1;
486 9 ▶ int exclusive = 0;
Branch: 1 branch
BranchTrueFalseTotal
int exclusive = 0; 9 0 9
487 CODE:
488 9 ▶ if(options) {
Branch: 1 branch
BranchTrueFalseTotal
if(options) { 8 1 9
489 16 ▶ str_from_hv(options, consumer_tag);
Branch: 1 branch
BranchTrueFalseTotal
str_from_hv(options, consumer_tag); 8 0 8
490 8 ▶ int_from_hv(options, no_local);
Branch: 1 branch
BranchTrueFalseTotal
int_from_hv(options, no_local); 4 4 8
491 8 ▶ int_from_hv(options, no_ack);
Branch: 1 branch
BranchTrueFalseTotal
int_from_hv(options, no_ack); 8 0 8
492 8 ▶ int_from_hv(options, exclusive);
Branch: 1 branch
BranchTrueFalseTotal
int_from_hv(options, exclusive); 4 4 8
493 }
494 17 ▶ r = amqp_basic_consume(conn, channel, amqp_cstring_bytes(queuename),
Branch: 1 branch
BranchTrueFalseTotal
r = amqp_basic_consume(conn, channel, amqp_cstring_bytes(queuename), 8 1 9
495 8 consumer_tag ? amqp_cstring_bytes(consumer_tag) : AMQP_EMPTY_BYTES,
496 no_local, no_ack, exclusive);
497 9 amqp_rpc_reply = amqp_get_rpc_reply();
498 9 die_on_amqp_error(aTHX_ *amqp_rpc_reply, "Consume queue");
499 0 RETVAL = newSVpvn(r->consumer_tag.bytes, r->consumer_tag.len);
500 OUTPUT:
501 RETVAL
502  
503 HV *
504 net_rabbitmq_recv(conn)
505 Net::RabbitMQ conn
506 PREINIT:
507 11 ▶ int result = 0;
Branch: 1 branch
BranchTrueFalseTotal
int result = 0; 11 0 11
508 CODE:
509 11 RETVAL = newHV();
510 11 sv_2mortal((SV*)RETVAL);
511 11 result = internal_recv(RETVAL, conn, 0);
512 11 ▶ if(result <= 0) Perl_croak(aTHX_ "Bad frame read.");
Branch: 1 branch
BranchTrueFalseTotal
if(result <= 0) Perl_croak(aTHX_ "Bad frame read."); 11 0 11
513 OUTPUT:
514 RETVAL
515  
516 void
517 net_rabbitmq_ack(conn, channel, delivery_tag, multiple = 0)
518 Net::RabbitMQ conn
519 int channel
520 SV *delivery_tag
521 int multiple
522 PREINIT:
523 STRLEN len;
524 uint64_t tag;
525 unsigned char *l;
526 CODE:
527 1 l = SvPV(delivery_tag, len);
528 1 ▶ if(len != sizeof(tag)) Perl_croak(aTHX_ "bad tag");
Branch: 1 branch
BranchTrueFalseTotal
if(len != sizeof(tag)) Perl_croak(aTHX_ "bad tag"); 1 0 1
529 0 memcpy(&tag, l, sizeof(tag));
530 0 die_on_error(aTHX_ amqp_basic_ack(conn, channel, tag, multiple),
531 "ack");
532  
533  
534 void
535 net_rabbitmq_reject(conn, channel, delivery_tag, requeue = 0)
536 Net::RabbitMQ conn
537 int channel
538 SV *delivery_tag
539 int requeue
540 PREINIT:
541 STRLEN len;
542 uint64_t tag;
543 unsigned char *l;
544 CODE:
545 1 l = SvPV(delivery_tag, len);
546 1 ▶ if(len != sizeof(tag)) Perl_croak(aTHX_ "bad tag");
Branch: 1 branch
BranchTrueFalseTotal
if(len != sizeof(tag)) Perl_croak(aTHX_ "bad tag"); 1 0 1
547 0 memcpy(&tag, l, sizeof(tag));
548 0 die_on_error(aTHX_ amqp_basic_reject(conn, channel, tag, requeue),
549 "reject");
550  
551  
552 void
553 net_rabbitmq_purge(conn, channel, queuename, no_wait = 0)
554 Net::RabbitMQ conn
555 int channel
556 char *queuename
557 int no_wait
558 PREINIT:
559 amqp_rpc_reply_t *amqp_rpc_reply;
560 CODE:
561 2 amqp_queue_purge(conn, channel, amqp_cstring_bytes(queuename), no_wait);
562 2 amqp_rpc_reply = amqp_get_rpc_reply();
563 2 die_on_amqp_error(aTHX_ *amqp_rpc_reply, "Purging queue");
564  
565 int
566 net_rabbitmq__publish(conn, channel, routing_key, body, options = NULL, props = NULL)
567 Net::RabbitMQ conn
568 int channel
569 HV *options;
570 char *routing_key
571 SV *body
572 HV *props
573 PREINIT:
574 SV **v;
575 15 char *exchange = "amq.direct";
576 15 amqp_boolean_t mandatory = 0;
577 15 amqp_boolean_t immediate = 0;
578 int rv;
579 15 ▶ amqp_bytes_t exchange_b = { 0 };
Branch: 1 branch
BranchTrueFalseTotal
amqp_bytes_t exchange_b = { 0 }; 15 0 15
580 amqp_bytes_t routing_key_b;
581 amqp_bytes_t body_b;
582 struct amqp_basic_properties_t_ properties;
583 STRLEN len;
584 CODE:
585 15 routing_key_b = amqp_cstring_bytes(routing_key);
586 15 body_b.bytes = SvPV(body, len);
587 15 body_b.len = len;
588 15 ▶ if(options) {
Branch: 1 branch
BranchTrueFalseTotal
if(options) { 15 0 15
589 15 ▶ if(NULL != (v = hv_fetch(options, "mandatory", strlen("mandatory"), 0))) mandatory = SvIV(*v) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
if(NULL != (v = hv_fetch(options, "mandatory", strlen("mandatory"), 0))) mandatory = SvIV(*v) ? 1 : 0; 2 13 15
590 15 ▶ if(NULL != (v = hv_fetch(options, "immediate", strlen("immediate"), 0))) immediate = SvIV(*v) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
if(NULL != (v = hv_fetch(options, "immediate", strlen("immediate"), 0))) immediate = SvIV(*v) ? 1 : 0; 2 13 15
591 30 ▶ if(NULL != (v = hv_fetch(options, "exchange", strlen("exchange"), 0))) exchange_b = amqp_cstring_bytes(SvPV_nolen(*v));
Branch: 1 branch
BranchTrueFalseTotal
if(NULL != (v = hv_fetch(options, "exchange", strlen("exchange"), 0))) exchange_b = amqp_cstring_bytes(SvPV_nolen(*v)); 15 0 15
592 }
593 15 properties.headers = AMQP_EMPTY_TABLE;
594 15 properties._flags = 0;
595 15 ▶ if (props) {
Branch: 1 branch
BranchTrueFalseTotal
if (props) { 15 0 15
596 15 ▶ if (NULL != (v = hv_fetch(props, "content_type", strlen("content_type"), 0))) {
Branch: 1 branch
BranchTrueFalseTotal
if (NULL != (v = hv_fetch(props, "content_type", strlen("content_type"), 0))) { 2 13 15
597 4 properties.content_type = amqp_cstring_bytes(SvPV_nolen(*v));
598 2 properties._flags |= AMQP_BASIC_CONTENT_TYPE_FLAG;
599 }
600 15 ▶ if (NULL != (v = hv_fetch(props, "content_encoding", strlen("content_encoding"), 0))) {
Branch: 1 branch
BranchTrueFalseTotal
if (NULL != (v = hv_fetch(props, "content_encoding", strlen("content_encoding"), 0))) { 2 13 15
601 4 properties.content_encoding = amqp_cstring_bytes(SvPV_nolen(*v));
602 2 properties._flags |= AMQP_BASIC_CONTENT_ENCODING_FLAG;
603 }
604 15 ▶ if (NULL != (v = hv_fetch(props, "correlation_id", strlen("correlation_id"), 0))) {
Branch: 1 branch
BranchTrueFalseTotal
if (NULL != (v = hv_fetch(props, "correlation_id", strlen("correlation_id"), 0))) { 2 13 15
605 4 properties.correlation_id = amqp_cstring_bytes(SvPV_nolen(*v));
606 2 properties._flags |= AMQP_BASIC_CORRELATION_ID_FLAG;
607 }
608 15 ▶ if (NULL != (v = hv_fetch(props, "reply_to", strlen("reply_to"), 0))) {
Branch: 1 branch
BranchTrueFalseTotal
if (NULL != (v = hv_fetch(props, "reply_to", strlen("reply_to"), 0))) { 2 13 15
609 4 properties.reply_to = amqp_cstring_bytes(SvPV_nolen(*v));
610 2 properties._flags |= AMQP_BASIC_REPLY_TO_FLAG;
611 }
612 15 ▶ if (NULL != (v = hv_fetch(props, "expiration", strlen("expiration"), 0))) {
Branch: 1 branch
BranchTrueFalseTotal
if (NULL != (v = hv_fetch(props, "expiration", strlen("expiration"), 0))) { 2 13 15
613 4 properties.expiration = amqp_cstring_bytes(SvPV_nolen(*v));
614 2 properties._flags |= AMQP_BASIC_EXPIRATION_FLAG;
615 }
616 15 ▶ if (NULL != (v = hv_fetch(props, "message_id", strlen("message_id"), 0))) {
Branch: 1 branch
BranchTrueFalseTotal
if (NULL != (v = hv_fetch(props, "message_id", strlen("message_id"), 0))) { 2 13 15
617 4 properties.message_id = amqp_cstring_bytes(SvPV_nolen(*v));
618 2 properties._flags |= AMQP_BASIC_MESSAGE_ID_FLAG;
619 }
620 15 ▶ if (NULL != (v = hv_fetch(props, "type", strlen("type"), 0))) {
Branch: 1 branch
BranchTrueFalseTotal
if (NULL != (v = hv_fetch(props, "type", strlen("type"), 0))) { 2 13 15
621 4 properties.type = amqp_cstring_bytes(SvPV_nolen(*v));
622 2 properties._flags |= AMQP_BASIC_TYPE_FLAG;
623 }
624 15 ▶ if (NULL != (v = hv_fetch(props, "user_id", strlen("user_id"), 0))) {
Branch: 1 branch
BranchTrueFalseTotal
if (NULL != (v = hv_fetch(props, "user_id", strlen("user_id"), 0))) { 2 13 15
625 4 properties.user_id = amqp_cstring_bytes(SvPV_nolen(*v));
626 2 properties._flags |= AMQP_BASIC_USER_ID_FLAG;
627 }
628 15 ▶ if (NULL != (v = hv_fetch(props, "app_id", strlen("app_id"), 0))) {
Branch: 1 branch
BranchTrueFalseTotal
if (NULL != (v = hv_fetch(props, "app_id", strlen("app_id"), 0))) { 2 13 15
629 4 properties.app_id = amqp_cstring_bytes(SvPV_nolen(*v));
630 2 properties._flags |= AMQP_BASIC_APP_ID_FLAG;
631 }
632 15 ▶ if (NULL != (v = hv_fetch(props, "delivery_mode", strlen("delivery_mode"), 0))) {
Branch: 1 branch
BranchTrueFalseTotal
if (NULL != (v = hv_fetch(props, "delivery_mode", strlen("delivery_mode"), 0))) { 2 13 15
633 2 properties.delivery_mode = (uint8_t) SvIV(*v);
634 2 properties._flags |= AMQP_BASIC_DELIVERY_MODE_FLAG;
635 }
636 15 ▶ if (NULL != (v = hv_fetch(props, "priority", strlen("priority"), 0))) {
Branch: 1 branch
BranchTrueFalseTotal
if (NULL != (v = hv_fetch(props, "priority", strlen("priority"), 0))) { 2 13 15
637 2 properties.priority = (uint8_t) SvIV(*v);
638 2 properties._flags |= AMQP_BASIC_PRIORITY_FLAG;
639 }
640 15 ▶ if (NULL != (v = hv_fetch(props, "timestamp", strlen("timestamp"), 0))) {
Branch: 1 branch
BranchTrueFalseTotal
if (NULL != (v = hv_fetch(props, "timestamp", strlen("timestamp"), 0))) { 2 13 15
641 2 properties.timestamp = (uint64_t) SvIV(*v);
642 2 properties._flags |= AMQP_BASIC_TIMESTAMP_FLAG;
643 }
644 15 ▶ if (NULL != (v = hv_fetch(props, "headers", strlen("headers"), 0))) {
Branch: 1 branch
BranchTrueFalseTotal
if (NULL != (v = hv_fetch(props, "headers", strlen("headers"), 0))) { 4 11 15
645 4 hash_to_amqp_table(conn, (HV *)SvRV(*v), &properties.headers);
646 4 properties._flags |= AMQP_BASIC_HEADERS_FLAG;
647 }
648 }
649 15 rv = amqp_basic_publish(conn, channel, exchange_b, routing_key_b, mandatory, immediate, &properties, body_b);
650 15 ▶ RETVAL = rv;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = rv; 6 9 15
651 OUTPUT:
652 RETVAL
653  
654 SV *
655 net_rabbitmq_get(conn, channel, queuename, options = NULL)
656 Net::RabbitMQ conn
657 int channel
658 char *queuename
659 HV *options
660 PREINIT:
661 amqp_rpc_reply_t r;
662 5 ▶ int no_ack = 1;
Branch: 1 branch
BranchTrueFalseTotal
int no_ack = 1; 5 0 5
663 CODE:
664 5 ▶ if(options)
Branch: 1 branch
BranchTrueFalseTotal
if(options) 0 5 5
665 0 ▶ int_from_hv(options, no_ack);
Branch: 1 branch
BranchTrueFalseTotal
int_from_hv(options, no_ack); 0 0 0
666 5 amqp_maybe_release_buffers(conn);
667 5 ▶ r = amqp_basic_get(conn, channel, queuename ? amqp_cstring_bytes(queuename) : AMQP_EMPTY_BYTES, no_ack);
Branch: 1 branch
BranchTrueFalseTotal
r = amqp_basic_get(conn, channel, queuename ? amqp_cstring_bytes(queuename) : AMQP_EMPTY_BYTES, no_ack); 5 0 5
668 5 die_on_amqp_error(aTHX_ r, "basic_get");
669 0 ▶ if(r.reply.id == AMQP_BASIC_GET_OK_METHOD) {
Branch: 1 branch
BranchTrueFalseTotal
if(r.reply.id == AMQP_BASIC_GET_OK_METHOD) { 0 0 0
670 HV *hv;
671 0 amqp_basic_get_ok_t *ok = (amqp_basic_get_ok_t *)r.reply.decoded;
672 0 hv = newHV();
673 0 hv_store(hv, "delivery_tag", strlen("delivery_tag"), newSVpvn((const char *)&ok->delivery_tag, sizeof(ok->delivery_tag)), 0);
674 0 hv_store(hv, "redelivered", strlen("redelivered"), newSViv(ok->redelivered), 0);
675 0 hv_store(hv, "exchange", strlen("exchange"), newSVpvn(ok->exchange.bytes, ok->exchange.len), 0);
676 0 hv_store(hv, "routing_key", strlen("routing_key"), newSVpvn(ok->routing_key.bytes, ok->routing_key.len), 0);
677 0 hv_store(hv, "message_count", strlen("message_count"), newSViv(ok->message_count), 0);
678 0 ▶ if(amqp_data_in_buffer(conn)) {
Branch: 1 branch
BranchTrueFalseTotal
if(amqp_data_in_buffer(conn)) { 0 0 0
679 int rv;
680 0 rv = internal_recv(hv, conn, 1);
681 0 ▶ if(rv <= 0) Perl_croak(aTHX_ "Bad frame read.");
Branch: 1 branch
BranchTrueFalseTotal
if(rv <= 0) Perl_croak(aTHX_ "Bad frame read."); 0 0 0
682 }
683 0 RETVAL = (SV *)newRV_noinc((SV *)hv);
684 }
685 else
686 0 RETVAL = &PL_sv_undef;
687 OUTPUT:
688 RETVAL
689  
690 int
691 net_rabbitmq_get_channel_max(conn)
692 Net::RabbitMQ conn
693 CODE:
694 0 RETVAL = amqp_get_channel_max(conn);
695 OUTPUT:
696 RETVAL
697  
698 void
699 net_rabbitmq_disconnect(conn)
700 Net::RabbitMQ conn
701 PREINIT:
702 int sockfd;
703 CODE:
704 2 die_on_amqp_error(aTHX_ amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection");
705 0 sockfd = amqp_get_sockfd(conn);
706 0 ▶ if(sockfd >= 0) close(sockfd);
Branch: 1 branch
BranchTrueFalseTotal
if(sockfd >= 0) close(sockfd); 0 0 0
707 0 amqp_set_sockfd(conn,-1);
708  
709 Net::RabbitMQ
710 net_rabbitmq_new(clazz)
711 char *clazz
712 CODE:
713 16 RETVAL = amqp_new_connection();
714 OUTPUT:
715 RETVAL
716  
717 void
718 net_rabbitmq_DESTROY(conn)
719 Net::RabbitMQ conn
720 PREINIT:
721 int sockfd;
722 CODE:
723 16 amqp_connection_close(conn, AMQP_REPLY_SUCCESS);
724 16 sockfd = amqp_get_sockfd(conn);
725 16 ▶ if(sockfd >= 0) close(sockfd);
Branch: 1 branch
BranchTrueFalseTotal
if(sockfd >= 0) close(sockfd); 0 16 16
726 16 amqp_destroy_connection(conn);
727  
728 void
729 net_rabbitmq_heartbeat1(conn)
730 Net::RabbitMQ conn
731 PREINIT:
732 amqp_frame_t f;
733 CODE:
734 0 f.frame_type = AMQP_FRAME_HEARTBEAT;
735 0 f.channel = 0;
736 0 amqp_send_frame(conn, &f);
737  
738 void
739 net_rabbitmq_heartbeat(conn)
740 Net::RabbitMQ conn
741 PREINIT:
742 amqp_frame_t f;
743 CODE:
744 1 ▶ if(conn->last_send.tv_sec != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if(conn->last_send.tv_sec != 0) { 0 1 1
745 struct timeval now;
746 0 gettimeofday(&now, NULL);
747 0 long diff = now.tv_sec - conn->last_send.tv_sec;
748 0 diff *= 1000000;
749 0 diff += now.tv_usec - conn->last_send.tv_usec;
750 0 ▶ if(diff < 1000000 * conn->heartbeat)
Branch: 1 branch
BranchTrueFalseTotal
if(diff < 1000000 * conn->heartbeat) 0 0 0
751 0 return;
752 }
753 1 f.frame_type = AMQP_FRAME_HEARTBEAT;
754 1 f.channel = 0;
755 1 amqp_send_frame(conn, &f);
756  
757 void
758 net_rabbitmq_tx_select(conn, channel, args = NULL)
759 Net::RabbitMQ conn
760 int channel
761 HV *args
762 PREINIT:
763 amqp_rpc_reply_t *amqp_rpc_reply;
764 1 ▶ amqp_table_t arguments = AMQP_EMPTY_TABLE;
Branch: 1 branch
BranchTrueFalseTotal
amqp_table_t arguments = AMQP_EMPTY_TABLE; 1 0 1
765 CODE:
766 1 amqp_tx_select(conn, channel, arguments);
767 1 amqp_rpc_reply = amqp_get_rpc_reply();
768 1 die_on_amqp_error(aTHX_ *amqp_rpc_reply, "Selecting transaction");
769  
770 void
771 net_rabbitmq_tx_commit(conn, channel, args = NULL)
772 Net::RabbitMQ conn
773 int channel
774 HV *args
775 PREINIT:
776 amqp_rpc_reply_t *amqp_rpc_reply;
777 1 ▶ amqp_table_t arguments = AMQP_EMPTY_TABLE;
Branch: 1 branch
BranchTrueFalseTotal
amqp_table_t arguments = AMQP_EMPTY_TABLE; 1 0 1
778 CODE:
779 1 amqp_tx_commit(conn, channel, arguments);
780 1 amqp_rpc_reply = amqp_get_rpc_reply();
781 1 die_on_amqp_error(aTHX_ *amqp_rpc_reply, "Commiting transaction");
782  
783 void
784 net_rabbitmq_tx_rollback(conn, channel, args = NULL)
785 Net::RabbitMQ conn
786 int channel
787 HV *args
788 PREINIT:
789 amqp_rpc_reply_t *amqp_rpc_reply;
790 1 ▶ amqp_table_t arguments = AMQP_EMPTY_TABLE;
Branch: 1 branch
BranchTrueFalseTotal
amqp_table_t arguments = AMQP_EMPTY_TABLE; 1 0 1
791 CODE:
792 1 amqp_tx_rollback(conn, channel, arguments);
793 1 amqp_rpc_reply = amqp_get_rpc_reply();
794 1 die_on_amqp_error(aTHX_ *amqp_rpc_reply, "Rolling Back transaction");
795  
796 void
797 net_rabbitmq_basic_qos(conn, channel, args = NULL)
798 Net::RabbitMQ conn
799 int channel
800 HV *args
801 PREINIT:
802 SV **v;
803 amqp_rpc_reply_t *amqp_rpc_reply;
804 1 uint32_t prefetch_size = 0;
805 1 uint16_t prefetch_count = 0;
806 1 ▶ amqp_boolean_t global = 0;
Branch: 1 branch
BranchTrueFalseTotal
amqp_boolean_t global = 0; 1 0 1
807 CODE:
808 1 ▶ if(args) {
Branch: 1 branch
BranchTrueFalseTotal
if(args) { 1 0 1
809 1 ▶ if(NULL != (v = hv_fetch(args, "prefetch_size", strlen("prefetch_size"), 0))) prefetch_size = SvIV(*v);
Branch: 1 branch
BranchTrueFalseTotal
if(NULL != (v = hv_fetch(args, "prefetch_size", strlen("prefetch_size"), 0))) prefetch_size = SvIV(*v); 0 1 1
810 1 ▶ if(NULL != (v = hv_fetch(args, "prefetch_count", strlen("prefetch_count"), 0))) prefetch_count = SvIV(*v);
Branch: 1 branch
BranchTrueFalseTotal
if(NULL != (v = hv_fetch(args, "prefetch_count", strlen("prefetch_count"), 0))) prefetch_count = SvIV(*v); 1 0 1
811 1 ▶ if(NULL != (v = hv_fetch(args, "global", strlen("global"), 0))) global = SvIV(*v) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
if(NULL != (v = hv_fetch(args, "global", strlen("global"), 0))) global = SvIV(*v) ? 1 : 0; 0 1 1
812 }
813 1 amqp_basic_qos(conn, channel,
814 prefetch_size, prefetch_count, global);
815 1 amqp_rpc_reply = amqp_get_rpc_reply();
816 1 die_on_amqp_error(aTHX_ *amqp_rpc_reply, "Basic QoS");
« amqp_connection.c ↑ Summary amqp_api.c »