Branch Coverage

lib/Redis/Fast.xs
Criterion Covered Total %
branch 205 636 32.2


line true false branch
105 0 203 DEBUG_MSG("flags = %x", e->flags);
112 0 0 DEBUG_MSG("flags = %x", e->flags);
119 0 136 DEBUG_MSG("flags = %x", e->flags);
126 0 136 DEBUG_MSG("flags = %x", e->flags);
138 68 0 if (ac->ev.data != NULL)
167 54014 0 if(self==NULL) return WAIT_FOR_EVENT_EXCEPTION;
168 54014 0 if(self->ac==NULL) return WAIT_FOR_EVENT_EXCEPTION;
173 54014 0 if(e==NULL) return 0;
175 68 53946 if((e->flags & (WAIT_FOR_READ|WAIT_FOR_WRITE)) == (WAIT_FOR_READ|WAIT_FOR_WRITE)) {
176 0 68 DEBUG_MSG("set READ and WRITE, compare read_timeout = %f and write_timeout = %f",
178 66 2 if(read_timeout < 0 && write_timeout < 0) {
0 66 if(read_timeout < 0 && write_timeout < 0) {
181 2 0 } else if(read_timeout < 0) {
184 0 2 } else if(write_timeout < 0) {
187 0 0 } else if(read_timeout < write_timeout) {
194 68 53878 } else if(e->flags & WAIT_FOR_READ) {
195 68 0 DEBUG_MSG("set READ, read_timeout = %f", read_timeout);
198 0 53878 } else if(e->flags & WAIT_FOR_WRITE) {
199 53878 0 DEBUG_MSG("set WRITE, write_timeout = %f", write_timeout);
205 4 54010 if (timeout < 0) {
210 0 54014 DEBUG_MSG("select start, timeout is %f", timeout);
214 136 53878 if(e->flags & WAIT_FOR_READ) { pollfd.events |= POLLIN; }
215 53946 68 if(e->flags & WAIT_FOR_WRITE) { pollfd.events |= POLLOUT; }
217 0 54014 DEBUG_MSG("poll returns %d", rc);
218 1 54013 if(rc == 0) {
219 0 1 DEBUG_MSG("%s", "timeout");
223 0 54013 if(rc < 0) {
224 0 0 DEBUG_MSG("exception: %s", strerror(errno));
225 0 0 if( errno == EINTR ) {
226 0 0 PERL_ASYNC_CHECK();
227 0 0 DEBUG_MSG("%s", "recieved interrupt. retry wait_for_event");
232 54013 0 if(self->ac && (pollfd.revents & POLLIN) != 0) {
67 53946 if(self->ac && (pollfd.revents & POLLIN) != 0) {
233 0 67 DEBUG_MSG("ready to %s", "read");
236 54007 6 if(self->ac && (pollfd.revents & (POLLOUT|POLLHUP)) != 0) {
53946 61 if(self->ac && (pollfd.revents & (POLLOUT|POLLHUP)) != 0) {
237 0 53946 DEBUG_MSG("ready to %s", "write");
240 0 54013 if((pollfd.revents & (POLLERR|POLLNVAL)) != 0) {
241 0 0 DEBUG_MSG(
0 0 DEBUG_MSG(
0 0 DEBUG_MSG(
248 0 54013 DEBUG_MSG("%s", "finish");
254 0 130 DEBUG_MSG("%s", "start");
255 197 68 while(self->ac && self->ac->replies.tail) {
136 61 while(self->ac && self->ac->replies.tail) {
257 135 1 if (res != WAIT_FOR_EVENT_OK) {
258 0 1 DEBUG_MSG("error: %d", res);
262 0 129 DEBUG_MSG("%s", "finish");
269 0 68 DEBUG_MSG("connected status = %d", status);
270 0 68 if(status != REDIS_OK) {
282 0 68 DEBUG_MSG("disconnected status = %d", status);
292 0 69 DEBUG_MSG("%s", "start");
294 0 69 if(self->on_build_sock) {
300 0 0 PUSHMARK(SP);
303 0 0 FREETMPS;
307 66 3 if(self->path) {
313 0 69 if(ac == NULL) {
314 0 0 DEBUG_MSG("%s", "allocation error");
317 1 68 if(ac->err) {
318 0 1 DEBUG_MSG("connection error: %s", ac->errstr);
332 68 0 if(self->cnx_timeout) {
335 53878 68 while(!self->is_connected) {
337 0 53878 if(self->ac == NULL) {
344 0 53878 if(res != WAIT_FOR_EVENT_OK) {
345 0 0 DEBUG_MSG("error: %d", res);
359 68 0 if(self->on_connect){
361 0 68 PUSHMARK(SP);
365 0 68 DEBUG_MSG("%s", "finish");
373 0 69 DEBUG_MSG("%s", "start");
380 3 66 if(self->reconnect == 0) {
381 1 2 if(! __build_sock(self)) {
382 0 1 if(self->path) {
396 66 0 if(__build_sock(self)) {
398 0 66 DEBUG_MSG("%s", "finish");
403 0 0 DEBUG_MSG("elapsed time:%f, reconnect:%lf", elapsed_time, self->reconnect);
404 0 0 if( elapsed_time > self->reconnect) {
405 0 0 if(self->path) {
410 0 0 DEBUG_MSG("%s", "timed out");
414 0 0 DEBUG_MSG("%s", "failed to connect. wait...");
423 0 71 DEBUG_MSG("%s", "start");
424 71 0 if(self->is_connected && !self->ac && self->reconnect > 0) {
3 68 if(self->is_connected && !self->ac && self->reconnect > 0) {
0 3 if(self->is_connected && !self->ac && self->reconnect > 0) {
425 0 0 DEBUG_MSG("%s", "connection not found. reconnect");
428 3 68 if(!self->ac) {
429 0 3 DEBUG_MSG("%s", "Not connected to any server");
431 0 71 DEBUG_MSG("%s", "finish");
458 73 20 for (i = 0; i < reply->elements; i++) {
460 3 70 if(collect_errors) {
462 2 1 if(elem.result) {
467 1 2 if(elem.error) {
474 68 2 if(elem.result) {
479 2 68 if(elem.error && !res.error) {
2 0 if(elem.error && !res.error) {
500 13 52 if (ret.error == NULL) {
503 0 13 if (self->reconnect_on_error == NULL) {
509 0 0 if( self->next_reconnect_on_error_at < 0 ||
0 0 if( self->next_reconnect_on_error_at < 0 ||
515 0 0 sv_ret = ret.result ? ret.result : &PL_sv_undef;
519 0 0 PUSHMARK(SP);
520 0 0 XPUSHs(sv_err);
521 0 0 XPUSHs(sv_ret);
522 0 0 XPUSHs(sv_cmd);
529 0 0 if (count != 1) {
532 0 0 _need_reconnect = POPi;
535 0 0 FREETMPS;
545 0 67 DEBUG_MSG("%p", (void*)privdata);
546 66 1 if(reply) {
548 0 66 if(cbt->custom_decode) {
553 1 0 } else if(c->c.flags & REDIS_FREEING) {
554 0 1 DEBUG_MSG("%s", "redis freeing");
557 0 0 DEBUG_MSG("connect error: %s", c->errstr);
562 0 67 DEBUG_MSG("%s", "finish");
568 0 1 DEBUG_MSG("%p, %p", reply, privdata);
569 1 0 if (reply) {
580 0 1 if(cbt->custom_decode) {
586 0 1 if(result.result == NULL) result.result = &PL_sv_undef;
587 1 0 if(result.error == NULL) result.error = &PL_sv_undef;
589 0 1 PUSHMARK(SP);
590 0 1 XPUSHs(result.result);
591 0 1 XPUSHs(result.error);
596 1 0 FREETMPS;
601 1 0 if (0 < self->reconnect && !self->need_reconnect
1 0 if (0 < self->reconnect && !self->need_reconnect
603 0 1 && self->reconnect_on_error != NULL) {
605 0 0 if(cbt->custom_decode) {
620 0 0 if (c->c.flags & REDIS_FREEING) {
621 0 0 DEBUG_MSG("%s", "redis freeing");
623 0 0 DEBUG_MSG("connect error: %s", c->errstr);
636 0 0 if (c->c.flags & REDIS_FREEING) {
641 0 0 DEBUG_MSG("error: %s", msg);
644 0 0 PUSHMARK(SP);
645 0 0 XPUSHs(result.result);
646 0 0 XPUSHs(result.error);
651 0 0 FREETMPS;
666 0 0 DEBUG_MSG("%s", "start");
667 0 0 if(!cbt) {
668 0 0 DEBUG_MSG("%s", "cbt is empty finished");
672 0 0 if (r) {
683 0 0 if (strcasecmp(stype+pvariant,"subscribe") == 0) {
684 0 0 DEBUG_MSG("%s %s %lld", r->element[0]->str, r->element[1]->str, r->element[2]->integer);
687 0 0 } else if (strcasecmp(stype+pvariant,"unsubscribe") == 0) {
688 0 0 DEBUG_MSG("%s %s %lld", r->element[0]->str, r->element[1]->str, r->element[2]->integer);
693 0 0 DEBUG_MSG("%s %s", r->element[0]->str, r->element[1]->str);
697 0 0 if(res.result == NULL) res.result = &PL_sv_undef;
698 0 0 if(res.error == NULL) res.error = &PL_sv_undef;
700 0 0 PUSHMARK(SP);
701 0 0 XPUSHs(res.result);
702 0 0 XPUSHs(res.error);
707 0 0 FREETMPS;
710 0 0 DEBUG_MSG("connect error: %s", c->errstr);
714 0 0 if(is_need_free) {
716 0 0 DEBUG_MSG("destroy %p", cbt);
717 0 0 if(cbt->cb) {
723 0 0 DEBUG_MSG("%s", "finish");
729 0 0 if(!self->ac) {
746 0 0 if(_wait_all_responses(self) == WAIT_FOR_EVENT_OK) {
747 0 0 DEBUG_MSG("%s", "wait_all_responses ok");
748 0 0 if(cbt->ret.result || cbt->ret.error) Safefree(cbt);
0 0 if(cbt->ret.result || cbt->ret.error) Safefree(cbt);
750 0 0 DEBUG_MSG("%s", "wait_all_responses not ok");
751 0 0 if(cbt->ret.result || cbt->ret.error) Safefree(cbt);
0 0 if(cbt->ret.result || cbt->ret.error) Safefree(cbt);
753 0 0 DEBUG_MSG("%s", "finish");
760 0 68 DEBUG_MSG("start %s", argv[0]);
762 0 68 DEBUG_MSG("pid check: previous pid is %d, now %d", self->pid, getpid());
763 0 68 if(self->pid != getpid()) {
764 0 0 DEBUG_MSG("%s", "pid changed. create new connection..");
768 0 68 if(EQUALS_COMMAND(argvlen[0], argv[0], "MULTI")) {
0 0 if(EQUALS_COMMAND(argvlen[0], argv[0], "MULTI")) {
770 1 67 } else if(EQUALS_COMMAND(argvlen[0], argv[0], "EXEC") ||
0 1 } else if(EQUALS_COMMAND(argvlen[0], argv[0], "EXEC") ||
0 67 } else if(EQUALS_COMMAND(argvlen[0], argv[0], "EXEC") ||
771 0 0 EQUALS_COMMAND(argvlen[0], argv[0], "DISCARD")) {
773 0 67 } else if(EQUALS_COMMAND(argvlen[0], argv[0], "WATCH")) {
0 0 } else if(EQUALS_COMMAND(argvlen[0], argv[0], "WATCH")) {
775 0 67 } else if(EQUALS_COMMAND(argvlen[0], argv[0], "UNWATCH")) {
0 0 } else if(EQUALS_COMMAND(argvlen[0], argv[0], "UNWATCH")) {
779 1 67 if(cb) {
796 65 2 int i, cnt = (self->reconnect == 0 ? 1 : 2);
798 67 0 for(i = 0; i < cnt; i++) {
807 0 67 DEBUG_MSG("%s", "send command in sync mode");
812 0 67 DEBUG_MSG("%s", "waiting response");
814 66 1 if(res == WAIT_FOR_EVENT_OK && self->need_reconnect == 0) {
66 0 if(res == WAIT_FOR_EVENT_OK && self->need_reconnect == 0) {
816 65 1 if (1 < cnt - i) {
821 0 65 if (_need_reconnect) {
825 66 0 if (!_need_reconnect) {
827 11 55 if(cbt->ret.result || cbt->ret.error) Safefree(cbt);
11 0 if(cbt->ret.result || cbt->ret.error) Safefree(cbt);
828 0 66 DEBUG_MSG("finish %s", argv[0]);
833 0 1 if( res == WAIT_FOR_EVENT_READ_TIMEOUT ) break;
835 0 0 if(self->flags & (FLAG_INSIDE_TRANSACTION | FLAG_INSIDE_WATCH)) {
837 0 0 DEBUG_MSG("error: %s", msg);
843 0 0 if(!self->ac) {
845 0 0 DEBUG_MSG("error: %s", msg);
851 0 1 if( res == WAIT_FOR_EVENT_OK && (cbt->ret.result || cbt->ret.error) ) Safefree(cbt);
0 0 if( res == WAIT_FOR_EVENT_OK && (cbt->ret.result || cbt->ret.error) ) Safefree(cbt);
0 0 if( res == WAIT_FOR_EVENT_OK && (cbt->ret.result || cbt->ret.error) ) Safefree(cbt);
854 1 0 if(res == WAIT_FOR_EVENT_READ_TIMEOUT || res == WAIT_FOR_EVENT_WRITE_TIMEOUT) {
857 0 1 DEBUG_MSG("error: %s", self->error);
861 0 0 if(!self->ac) {
863 0 0 DEBUG_MSG("error: %s", msg);
868 0 1 DEBUG_MSG("Finish %s", argv[0]);
880 0 0 if(reply->type == REDIS_REPLY_STRING ||
888 0 0 while(len != 0) {
892 0 0 if(line == NULL) {
898 0 0 if(str[0] != '#' && sep != NULL) {
0 0 if(str[0] != '#' && sep != NULL) {
905 0 0 if (ret == NULL) {
910 0 0 if(line == NULL) {
933 0 70 DEBUG_MSG("%s", "start");
940 0 70 DEBUG_MSG("return %p", ST(0));
1075 0 0 RETVAL = self->ac ? self->ac->c.fd : 0;
1138 0 0 if ( -1 < val ) {
1162 0 70 DEBUG_MSG("%s", "start");
1163 62 8 if (self->ac) {
1164 0 62 DEBUG_MSG("%s", "free ac");
1170 4 66 if(self->hostname) {
1171 0 4 DEBUG_MSG("%s", "free hostname");
1176 66 4 if(self->path) {
1177 0 66 DEBUG_MSG("%s", "free path");
1182 70 0 if(self->error) {
1183 0 70 DEBUG_MSG("%s", "free error");
1188 70 0 if(self->on_connect) {
1189 0 70 DEBUG_MSG("%s", "free on_connect");
1194 0 70 if(self->on_build_sock) {
1195 0 0 DEBUG_MSG("%s", "free on_build_sock");
1200 70 0 if(self->data) {
1201 0 70 DEBUG_MSG("%s", "free data");
1206 0 70 if(self->reconnect_on_error) {
1207 0 0 DEBUG_MSG("%s", "free reconnect_on_error");
1212 0 70 DEBUG_MSG("%s", "finish");
1221 0 4 if(self->hostname) {
1226 0 4 if(self->path) {
1231 4 0 if(hostname) {
1243 0 66 if(self->hostname) {
1248 0 66 if(self->path) {
1253 66 0 if(path) {
1272 0 1 if(res != WAIT_FOR_EVENT_OK) {
1276 1 0 if (0 < self->reconnect && self->need_reconnect) {
0 1 if (0 < self->reconnect && self->need_reconnect) {
1289 0 0 if(res != WAIT_FOR_EVENT_OK) {
1293 0 0 if (0 < self->reconnect && self->need_reconnect) {
0 0 if (0 < self->reconnect && self->need_reconnect) {
1313 0 68 if(!self->ac) {
1318 1 67 if (SvROK(cb) && SvTYPE(SvRV(cb)) == SVt_PVCV) {
1 0 if (SvROK(cb) && SvTYPE(SvRV(cb)) == SVt_PVCV) {
1324 0 68 Newx(argv, sizeof(char*) * argc, char*);
1325 0 68 Newx(argvlen, sizeof(size_t) * argc, size_t);
1327 136 68 for (i = 0; i < argc; i++) {
1328 0 136 if(!sv_utf8_downgrade(ST(i + 1), 1)) {
1331 136 0 argv[i] = SvPV(ST(i + 1), len);
1336 1 67 if(cb && EQUALS_COMMAND(argvlen[0], argv[0], "EXEC"))
1 0 if(cb && EQUALS_COMMAND(argvlen[0], argv[0], "EXEC"))
1 0 if(cb && EQUALS_COMMAND(argvlen[0], argv[0], "EXEC"))
1344 56 12 ST(0) = ret.result ? ret.result : &PL_sv_undef;
1345 14 54 ST(1) = ret.error ? ret.error : &PL_sv_undef;
1354 0 0 DEBUG_MSG("%s", "start QUIT");
1355 0 0 if(self->ac) {
1360 0 0 DEBUG_MSG("%s", "finish. there is no connection.");
1370 0 0 DEBUG_MSG("%s", "start SHUTDOWN");
1371 0 0 if(self->ac) {
1381 0 0 DEBUG_MSG("%s", "redis server has alread shutdown");
1399 0 0 if(!self->ac) {
1404 0 0 if (SvROK(cb) && SvTYPE(SvRV(cb)) == SVt_PVCV) {
0 0 if (SvROK(cb) && SvTYPE(SvRV(cb)) == SVt_PVCV) {
1410 0 0 Newx(argv, sizeof(char*) * argc, char*);
1411 0 0 Newx(argvlen, sizeof(size_t) * argc, size_t);
1415 0 0 for (i = 1; i < argc; i++) {
1416 0 0 argv[i] = SvPV(ST(i), len);
1424 0 0 ST(0) = ret.result ? ret.result : &PL_sv_undef;
1425 0 0 ST(1) = ret.error ? ret.error : &PL_sv_undef;
1442 3 0 if(!self->ac) {
1450 0 0 if (SvROK(cb) && SvTYPE(SvRV(cb)) == SVt_PVCV) {
0 0 if (SvROK(cb) && SvTYPE(SvRV(cb)) == SVt_PVCV) {
1456 0 0 Newx(argv, sizeof(char*) * argc, char*);
1457 0 0 Newx(argvlen, sizeof(size_t) * argc, size_t);
1461 0 0 for (i = 1; i < argc; i++) {
1462 0 0 argv[i] = SvPV(ST(i), len);
1470 0 0 ST(0) = ret.result ? ret.result : &PL_sv_undef;
1471 0 0 ST(1) = ret.error ? ret.error : &PL_sv_undef;
1488 0 0 int cnt = (self->reconnect == 0 ? 1 : 2);
1490 0 0 DEBUG_MSG("%s", "start");
1493 0 0 if(!self->ac) {
1497 0 0 if(!self->is_subscriber) {
1501 0 0 if (SvROK(cb) && SvTYPE(SvRV(cb)) == SVt_PVCV) {
0 0 if (SvROK(cb) && SvTYPE(SvRV(cb)) == SVt_PVCV) {
1507 0 0 Newx(argv, sizeof(char*) * argc, char*);
1508 0 0 Newx(argvlen, sizeof(size_t) * argc, size_t);
1510 0 0 for (i = 0; i < argc; i++) {
1511 0 0 argv[i] = SvPV(ST(i+1), len);
1513 0 0 DEBUG_MSG("argv[%d] = %s", i, argv[i]);
1516 0 0 for(i = 0; i < cnt; i++) {
1518 0 0 if (strcasecmp(argv[0]+pvariant,"unsubscribe") != 0) {
1519 0 0 DEBUG_MSG("%s", "command is not unsubscribe");
1524 0 0 DEBUG_MSG("%s", "command is unsubscribe");
1527 0 0 redisAsyncCommandArgv(
1532 0 0 while(self->expected_subs > 0 && wait_for_event(self, self->read_timeout, self->write_timeout) == WAIT_FOR_EVENT_OK) ;
0 0 while(self->expected_subs > 0 && wait_for_event(self, self->read_timeout, self->write_timeout) == WAIT_FOR_EVENT_OK) ;
1533 0 0 if(self->expected_subs == 0) break;
1535 0 0 if(!self->ac) {
1544 0 0 DEBUG_MSG("%s", "finish");
1552 0 0 int i, cnt = (self->reconnect == 0 ? 1 : 2);
1554 0 0 DEBUG_MSG("%s", "start");
1556 0 0 for(i = 0; i < cnt; i++) {
1557 0 0 while((res = wait_for_event(self, timeout, timeout)) == WAIT_FOR_EVENT_OK) ;
1558 0 0 if(res == WAIT_FOR_EVENT_READ_TIMEOUT || res == WAIT_FOR_EVENT_WRITE_TIMEOUT) break;
1560 0 0 if(!self->ac) {
1564 0 0 if(res == WAIT_FOR_EVENT_EXCEPTION) {
1565 0 0 if(!self->ac) {
1566 0 0 DEBUG_MSG("%s", "Connection not found");
1568 0 0 } else if(self->ac->c.err == REDIS_ERR_EOF) {
1569 0 0 DEBUG_MSG("hiredis returns error: %s", self->ac->c.errstr);
1572 0 0 DEBUG_MSG("hiredis returns error: %s", self->ac->c.errstr);
1578 0 0 DEBUG_MSG("finish with %d", res);
1586 0 0 DEBUG_MSG("%s", "start");
1588 0 0 DEBUG_MSG("%s", "finish");