Branch Coverage

lib/Redis/Fast.xs
Criterion Covered Total %
branch 221 672 32.8


line true false branch
109 0 207 DEBUG_MSG("flags = %x", e->flags);
116 0 0 DEBUG_MSG("flags = %x", e->flags);
123 0 136 DEBUG_MSG("flags = %x", e->flags);
130 0 140 DEBUG_MSG("flags = %x", e->flags);
142 68 0 if (ac->ev.data != NULL)
171 62791 0 if(self==NULL) return WAIT_FOR_EVENT_EXCEPTION;
172 62791 0 if(self->ac==NULL) return WAIT_FOR_EVENT_EXCEPTION;
177 0 62791 if(e==NULL) return 0;
179 68 62723 if((e->flags & (WAIT_FOR_READ|WAIT_FOR_WRITE)) == (WAIT_FOR_READ|WAIT_FOR_WRITE)) {
180 0 68 DEBUG_MSG("set READ and WRITE, compare read_timeout = %f and write_timeout = %f",
182 66 2 if(read_timeout < 0 && write_timeout < 0) {
0 66 if(read_timeout < 0 && write_timeout < 0) {
188 0 2 } else if(write_timeout < 0) {
191 0 0 } else if(read_timeout < write_timeout) {
198 68 62655 } else if(e->flags & WAIT_FOR_READ) {
199 0 68 DEBUG_MSG("set READ, read_timeout = %f", read_timeout);
202 0 62655 } else if(e->flags & WAIT_FOR_WRITE) {
203 62655 0 DEBUG_MSG("set WRITE, write_timeout = %f", write_timeout);
209 4 62787 if (timeout < 0) {
214 0 62791 DEBUG_MSG("select start, timeout is %f", timeout);
218 136 62655 if(e->flags & WAIT_FOR_READ) { pollfd.events |= POLLIN; }
219 62723 68 if(e->flags & WAIT_FOR_WRITE) { pollfd.events |= POLLOUT; }
221 0 62791 DEBUG_MSG("poll returns %d", rc);
222 1 62790 if(rc == 0) {
223 0 1 DEBUG_MSG("%s", "timeout");
227 0 62790 if(rc < 0) {
228 0 0 DEBUG_MSG("exception: %s", strerror(errno));
229 0 0 if( errno == EINTR ) {
230 0 0 PERL_ASYNC_CHECK();
231 0 0 DEBUG_MSG("%s", "recieved interrupt. retry wait_for_event");
236 62790 0 if(self->ac && (pollfd.revents & POLLIN) != 0) {
67 62723 if(self->ac && (pollfd.revents & POLLIN) != 0) {
237 0 67 DEBUG_MSG("ready to %s", "read");
240 62784 6 if(self->ac && (pollfd.revents & (POLLOUT|POLLHUP)) != 0) {
62727 57 if(self->ac && (pollfd.revents & (POLLOUT|POLLHUP)) != 0) {
241 0 62727 DEBUG_MSG("ready to %s", "write");
244 0 62790 if((pollfd.revents & (POLLERR|POLLNVAL)) != 0) {
245 0 0 DEBUG_MSG(
0 0 DEBUG_MSG(
0 0 DEBUG_MSG(
252 62790 0 DEBUG_MSG("%s", "finish");
258 0 130 DEBUG_MSG("%s", "start");
259 197 68 while(self->ac && self->ac->replies.tail) {
136 61 while(self->ac && self->ac->replies.tail) {
261 1 135 if (res != WAIT_FOR_EVENT_OK) {
262 0 1 DEBUG_MSG("error: %d", res);
266 0 129 DEBUG_MSG("%s", "finish");
273 0 68 DEBUG_MSG("connected status = %d", status);
274 0 68 if(status != REDIS_OK) {
286 0 68 DEBUG_MSG("disconnected status = %d", status);
296 0 69 DEBUG_MSG("%s", "start");
298 0 69 if(self->on_build_sock) {
304 0 0 PUSHMARK(SP);
307 0 0 FREETMPS;
311 66 3 if(self->path) {
317 0 69 if(ac == NULL) {
318 0 0 DEBUG_MSG("%s", "allocation error");
321 0 69 if(ac->err) {
322 0 0 DEBUG_MSG("connection error: %s", ac->errstr);
327 1 68 if(self->ssl){
340 1 0 if(ssl_context == NULL || ssl_error != REDIS_SSL_CTX_NONE) {
0 1 if(ssl_context == NULL || ssl_error != REDIS_SSL_CTX_NONE) {
341 0 0 DEBUG_MSG("ssl context error: %s", redisSSLContextGetError(ssl_error));
347 1 0 if (redisInitiateSSLWithContext(&ac->c, ssl_context) != REDIS_OK) {
348 0 1 DEBUG_MSG("ssl connection error: %s", ac->c.errstr);
353 0 0 DEBUG_MSG("%s", "ssl connection setup");
366 68 0 if(self->cnx_timeout) {
369 62655 68 while(!self->is_connected) {
371 0 62655 if(self->ac == NULL) {
378 0 62655 if(res != WAIT_FOR_EVENT_OK) {
379 0 0 DEBUG_MSG("error: %d", res);
393 68 0 if(self->on_connect){
395 0 68 PUSHMARK(SP);
399 0 68 DEBUG_MSG("%s", "finish");
407 0 69 DEBUG_MSG("%s", "start");
414 3 66 if(self->reconnect == 0) {
415 1 2 if(! __build_sock(aTHX_ self)) {
416 0 1 if(self->path) {
430 66 0 if(__build_sock(aTHX_ self)) {
432 0 66 DEBUG_MSG("%s", "finish");
437 0 0 DEBUG_MSG("elapsed time:%f, reconnect:%lf", elapsed_time, self->reconnect);
438 0 0 if( elapsed_time > self->reconnect) {
439 0 0 if(self->path) {
444 0 0 DEBUG_MSG("%s", "timed out");
448 0 0 DEBUG_MSG("%s", "failed to connect. wait...");
457 0 71 DEBUG_MSG("%s", "start");
458 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) {
459 0 0 DEBUG_MSG("%s", "connection not found. reconnect");
462 3 68 if(!self->ac) {
463 0 3 DEBUG_MSG("%s", "Not connected to any server");
465 0 71 DEBUG_MSG("%s", "finish");
492 73 20 for (i = 0; i < reply->elements; i++) {
494 3 70 if(collect_errors) {
496 2 1 if(elem.result) {
501 1 2 if(elem.error) {
508 68 2 if(elem.result) {
513 68 2 if(elem.error && !res.error) {
0 2 if(elem.error && !res.error) {
534 52 13 if (ret.error == NULL) {
537 13 0 if (self->reconnect_on_error == NULL) {
543 0 0 if( self->next_reconnect_on_error_at < 0 ||
0 0 if( self->next_reconnect_on_error_at < 0 ||
549 0 0 sv_ret = ret.result ? ret.result : &PL_sv_undef;
553 0 0 PUSHMARK(SP);
554 0 0 XPUSHs(sv_err);
555 0 0 XPUSHs(sv_ret);
556 0 0 XPUSHs(sv_cmd);
563 0 0 if (count != 1) {
569 0 0 FREETMPS;
581 0 67 DEBUG_MSG("%p", (void*)privdata);
582 66 1 if(reply) {
584 0 66 if(cbt->custom_decode) {
589 1 0 } else if(c->c.flags & REDIS_FREEING) {
590 0 1 DEBUG_MSG("%s", "redis freeing");
593 0 0 DEBUG_MSG("connect error: %s", c->errstr);
598 0 67 DEBUG_MSG("%s", "finish");
606 0 1 DEBUG_MSG("%p, %p", reply, privdata);
607 1 0 if (reply) {
618 0 1 if(cbt->custom_decode) {
624 0 1 if(result.result == NULL) result.result = &PL_sv_undef;
625 1 0 if(result.error == NULL) result.error = &PL_sv_undef;
627 0 1 PUSHMARK(SP);
628 0 1 XPUSHs(result.result);
629 0 1 XPUSHs(result.error);
634 1 0 FREETMPS;
639 1 0 if (0 < self->reconnect && !self->need_reconnect
1 0 if (0 < self->reconnect && !self->need_reconnect
641 0 1 && self->reconnect_on_error != NULL) {
643 0 0 if(cbt->custom_decode) {
658 0 0 if (c->c.flags & REDIS_FREEING) {
659 0 0 DEBUG_MSG("%s", "redis freeing");
661 0 0 DEBUG_MSG("connect error: %s", c->errstr);
674 0 0 if (c->c.flags & REDIS_FREEING) {
679 0 0 DEBUG_MSG("error: %s", msg);
682 0 0 PUSHMARK(SP);
683 0 0 XPUSHs(result.result);
684 0 0 XPUSHs(result.error);
689 0 0 FREETMPS;
706 0 0 DEBUG_MSG("%s", "start");
707 0 0 if(!cbt) {
708 0 0 DEBUG_MSG("%s", "cbt is empty finished");
712 0 0 if (r) {
723 0 0 if (strcasecmp(stype+pvariant,"subscribe") == 0) {
724 0 0 DEBUG_MSG("%s %s %lld", r->element[0]->str, r->element[1]->str, r->element[2]->integer);
727 0 0 } else if (strcasecmp(stype+pvariant,"unsubscribe") == 0) {
728 0 0 DEBUG_MSG("%s %s %lld", r->element[0]->str, r->element[1]->str, r->element[2]->integer);
733 0 0 DEBUG_MSG("%s %s", r->element[0]->str, r->element[1]->str);
737 0 0 if(res.result == NULL) res.result = &PL_sv_undef;
738 0 0 if(res.error == NULL) res.error = &PL_sv_undef;
740 0 0 PUSHMARK(SP);
741 0 0 XPUSHs(res.result);
742 0 0 XPUSHs(res.error);
747 0 0 FREETMPS;
750 0 0 DEBUG_MSG("connect error: %s", c->errstr);
754 0 0 if(is_need_free) {
756 0 0 DEBUG_MSG("destroy %p", cbt);
757 0 0 if(cbt->cb) {
763 0 0 DEBUG_MSG("%s", "finish");
769 0 0 if(!self->ac) {
786 0 0 if(_wait_all_responses(aTHX_ self) == WAIT_FOR_EVENT_OK) {
787 0 0 DEBUG_MSG("%s", "wait_all_responses ok");
788 0 0 if(cbt->ret.result || cbt->ret.error) Safefree(cbt);
0 0 if(cbt->ret.result || cbt->ret.error) Safefree(cbt);
790 0 0 DEBUG_MSG("%s", "wait_all_responses not ok");
791 0 0 if(cbt->ret.result || cbt->ret.error) Safefree(cbt);
0 0 if(cbt->ret.result || cbt->ret.error) Safefree(cbt);
793 0 0 DEBUG_MSG("%s", "finish");
800 0 68 DEBUG_MSG("start %s", argv[0]);
802 0 68 DEBUG_MSG("pid check: previous pid is %d, now %d", self->pid, getpid());
803 0 68 if(self->pid != getpid()) {
804 0 0 DEBUG_MSG("%s", "pid changed. create new connection..");
808 0 68 if(EQUALS_COMMAND(argvlen[0], argv[0], "MULTI")) {
0 0 if(EQUALS_COMMAND(argvlen[0], argv[0], "MULTI")) {
810 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") ||
811 0 0 EQUALS_COMMAND(argvlen[0], argv[0], "DISCARD")) {
813 0 67 } else if(EQUALS_COMMAND(argvlen[0], argv[0], "WATCH")) {
0 0 } else if(EQUALS_COMMAND(argvlen[0], argv[0], "WATCH")) {
815 67 0 } else if(EQUALS_COMMAND(argvlen[0], argv[0], "UNWATCH")) {
0 0 } else if(EQUALS_COMMAND(argvlen[0], argv[0], "UNWATCH")) {
819 1 67 if(cb) {
836 65 2 int i, cnt = (self->reconnect == 0 ? 1 : 2);
838 67 0 for(i = 0; i < cnt; i++) {
847 0 67 DEBUG_MSG("%s", "send command in sync mode");
852 0 67 DEBUG_MSG("%s", "waiting response");
854 66 1 if(res == WAIT_FOR_EVENT_OK && self->need_reconnect == 0) {
66 0 if(res == WAIT_FOR_EVENT_OK && self->need_reconnect == 0) {
856 65 1 if (1 < cnt - i) {
861 0 65 if (_need_reconnect) {
867 11 55 if(cbt->ret.result || cbt->ret.error) Safefree(cbt);
11 0 if(cbt->ret.result || cbt->ret.error) Safefree(cbt);
868 0 66 DEBUG_MSG("finish %s", argv[0]);
873 0 1 if( res == WAIT_FOR_EVENT_READ_TIMEOUT ) break;
875 0 0 if(self->flags & (FLAG_INSIDE_TRANSACTION | FLAG_INSIDE_WATCH)) {
877 0 0 DEBUG_MSG("error: %s", msg);
883 0 0 if(!self->ac) {
885 0 0 DEBUG_MSG("error: %s", msg);
891 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);
894 1 0 if(res == WAIT_FOR_EVENT_READ_TIMEOUT || res == WAIT_FOR_EVENT_WRITE_TIMEOUT) {
895 0 1 snprintf(self->error, MAX_ERROR_SIZE, "Error while reading from Redis server: %s", strerror(EAGAIN));
897 0 1 DEBUG_MSG("error: %s", self->error);
901 0 0 if(!self->ac) {
903 0 0 DEBUG_MSG("error: %s", msg);
908 0 1 DEBUG_MSG("Finish %s", argv[0]);
920 0 0 if(reply->type == REDIS_REPLY_STRING ||
928 0 0 while(len != 0) {
932 0 0 if(line == NULL) {
938 0 0 if(str[0] != '#' && sep != NULL) {
0 0 if(str[0] != '#' && sep != NULL) {
945 0 0 if (ret == NULL) {
950 0 0 if(line == NULL) {
974 0 70 DEBUG_MSG("%s", "start");
981 0 70 DEBUG_MSG("return %p", ST(0));
991 57 149 RETVAL = self->reconnect = val;
1001 0 68 RETVAL = self->reconnect;
1011 57 13 RETVAL = self->every = val;
1021 0 0 RETVAL = self->every;
1030 57 13 RETVAL = self->debug = val;
1039 57 13 RETVAL = self->cnx_timeout = val;
1048 0 0 RETVAL = self->cnx_timeout;
1058 57 13 RETVAL = self->read_timeout = val;
1067 0 0 RETVAL = self->read_timeout;
1077 57 13 RETVAL = self->write_timeout = val;
1086 0 0 RETVAL = self->write_timeout;
1096 0 0 RETVAL = self->current_database = val;
1106 0 0 RETVAL = self->current_database;
1116 0 0 RETVAL = self->ac ? self->ac->c.fd : 0;
1130 0 0 RETVAL = addr.sin_port;
1179 0 0 if ( -1 < val ) {
1185 0 0 RETVAL = self->next_reconnect_on_error_at = val;
1194 57 13 RETVAL = self->ssl = ssl;
1203 0 0 if (verify_mode != NULL) {
1204 0 0 DEBUG_MSG("SSL verify mode: %s", verify_mode);
1205 0 0 if (strcmp(verify_mode, "SSL_VERIFY_NONE") == 0 ) {
1207 0 0 } else if (strcmp(verify_mode, "SSL_VERIFY_PEER") == 0 ) {
1209 0 0 } else if (strcmp(verify_mode, "SSL_VERIFY_FAIL_IF_NO_PEER_CERT") == 0 ) {
1211 0 0 } else if (strcmp(verify_mode, "SSL_VERIFY_CLIENT_ONCE") == 0 ) {
1214 0 0 DEBUG_MSG("Invalid SSL verify mode (%s), setting SSL_VERIFY_PEER", verify_mode);
1237 0 70 DEBUG_MSG("%s", "start");
1238 62 8 if (self->ac) {
1239 0 62 DEBUG_MSG("%s", "free ac");
1245 4 66 if(self->hostname) {
1246 0 4 DEBUG_MSG("%s", "free hostname");
1251 66 4 if(self->path) {
1252 0 66 DEBUG_MSG("%s", "free path");
1257 70 0 if(self->error) {
1258 0 70 DEBUG_MSG("%s", "free error");
1263 70 0 if(self->on_connect) {
1264 0 70 DEBUG_MSG("%s", "free on_connect");
1269 0 70 if(self->on_build_sock) {
1270 0 0 DEBUG_MSG("%s", "free on_build_sock");
1275 70 0 if(self->data) {
1276 0 70 DEBUG_MSG("%s", "free data");
1281 0 70 if(self->reconnect_on_error) {
1282 0 0 DEBUG_MSG("%s", "free reconnect_on_error");
1287 0 70 DEBUG_MSG("%s", "finish");
1296 0 4 if(self->hostname) {
1301 0 4 if(self->path) {
1306 4 0 if(hostname) {
1318 0 66 if(self->hostname) {
1323 0 66 if(self->path) {
1328 66 0 if(path) {
1347 0 1 if(res != WAIT_FOR_EVENT_OK) {
1351 1 0 if (0 < self->reconnect && self->need_reconnect) {
0 1 if (0 < self->reconnect && self->need_reconnect) {
1364 0 0 if(res != WAIT_FOR_EVENT_OK) {
1368 0 0 if (0 < self->reconnect && self->need_reconnect) {
0 0 if (0 < self->reconnect && self->need_reconnect) {
1388 0 68 if(!self->ac) {
1393 1 67 if (SvROK(cb) && SvTYPE(SvRV(cb)) == SVt_PVCV) {
1 0 if (SvROK(cb) && SvTYPE(SvRV(cb)) == SVt_PVCV) {
1399 0 68 Newx(argv, sizeof(char*) * argc, char*);
1402 136 68 for (i = 0; i < argc; i++) {
1403 0 136 if(!sv_utf8_downgrade(ST(i + 1), 1)) {
1411 67 1 if(cb && EQUALS_COMMAND(argvlen[0], argv[0], "EXEC"))
0 1 if(cb && EQUALS_COMMAND(argvlen[0], argv[0], "EXEC"))
0 1 if(cb && EQUALS_COMMAND(argvlen[0], argv[0], "EXEC"))
1419 56 12 ST(0) = ret.result ? ret.result : &PL_sv_undef;
1420 14 54 ST(1) = ret.error ? ret.error : &PL_sv_undef;
1429 0 0 DEBUG_MSG("%s", "start QUIT");
1430 0 0 if(self->ac) {
1435 0 0 DEBUG_MSG("%s", "finish. there is no connection.");
1445 0 0 DEBUG_MSG("%s", "start SHUTDOWN");
1446 0 0 if(self->ac) {
1456 0 0 DEBUG_MSG("%s", "redis server has alread shutdown");
1474 0 0 if(!self->ac) {
1479 0 0 if (SvROK(cb) && SvTYPE(SvRV(cb)) == SVt_PVCV) {
0 0 if (SvROK(cb) && SvTYPE(SvRV(cb)) == SVt_PVCV) {
1490 0 0 for (i = 1; i < argc; i++) {
1499 0 0 ST(0) = ret.result ? ret.result : &PL_sv_undef;
1500 0 0 ST(1) = ret.error ? ret.error : &PL_sv_undef;
1517 3 0 if(!self->ac) {
1525 0 0 if (SvROK(cb) && SvTYPE(SvRV(cb)) == SVt_PVCV) {
0 0 if (SvROK(cb) && SvTYPE(SvRV(cb)) == SVt_PVCV) {
1536 0 0 for (i = 1; i < argc; i++) {
1545 0 0 ST(0) = ret.result ? ret.result : &PL_sv_undef;
1546 0 0 ST(1) = ret.error ? ret.error : &PL_sv_undef;
1563 0 0 int cnt = (self->reconnect == 0 ? 1 : 2);
1565 0 0 DEBUG_MSG("%s", "start");
1568 0 0 if(!self->ac) {
1572 0 0 if(!self->is_subscriber) {
1576 0 0 if (SvROK(cb) && SvTYPE(SvRV(cb)) == SVt_PVCV) {
0 0 if (SvROK(cb) && SvTYPE(SvRV(cb)) == SVt_PVCV) {
1582 0 0 Newx(argv, sizeof(char*) * argc, char*);
1585 0 0 for (i = 0; i < argc; i++) {
1588 0 0 DEBUG_MSG("argv[%d] = %s", i, argv[i]);
1591 0 0 for(i = 0; i < cnt; i++) {
1593 0 0 if (strcasecmp(argv[0]+pvariant,"unsubscribe") != 0) {
1594 0 0 DEBUG_MSG("%s", "command is not unsubscribe");
1596 0 0 cbt->self = self;
1599 0 0 DEBUG_MSG("%s", "command is unsubscribe");
1607 0 0 while(self->expected_subs > 0 && wait_for_event(aTHX_ self, self->read_timeout, self->write_timeout) == WAIT_FOR_EVENT_OK) ;
0 0 while(self->expected_subs > 0 && wait_for_event(aTHX_ self, self->read_timeout, self->write_timeout) == WAIT_FOR_EVENT_OK) ;
1608 0 0 if(self->expected_subs == 0) break;
1610 0 0 if(!self->ac) {
1619 0 0 DEBUG_MSG("%s", "finish");
1627 0 0 int i, cnt = (self->reconnect == 0 ? 1 : 2);
1629 0 0 DEBUG_MSG("%s", "start");
1631 0 0 for(i = 0; i < cnt; i++) {
1632 0 0 while((res = wait_for_event(aTHX_ self, timeout, timeout)) == WAIT_FOR_EVENT_OK) ;
1633 0 0 if(res == WAIT_FOR_EVENT_READ_TIMEOUT || res == WAIT_FOR_EVENT_WRITE_TIMEOUT) break;
1635 0 0 if(!self->ac) {
1639 0 0 if(res == WAIT_FOR_EVENT_EXCEPTION) {
1640 0 0 if(!self->ac) {
1641 0 0 DEBUG_MSG("%s", "Connection not found");
1643 0 0 } else if(self->ac->c.err == REDIS_ERR_EOF) {
1644 0 0 DEBUG_MSG("hiredis returns error: %s", self->ac->c.errstr);
1647 0 0 DEBUG_MSG("hiredis returns error: %s", self->ac->c.errstr);
1653 0 0 DEBUG_MSG("finish with %d", res);
1661 0 0 DEBUG_MSG("%s", "start");
1663 0 0 DEBUG_MSG("%s", "finish");