~alexlawn/php-redis/alex-redis-hmget

« back to all changes in this revision

Viewing changes to library.c

  • Committer: GitHub
  • Author(s): Pavlo Yatsukhnenko
  • Date: 2016-08-08 19:33:22 UTC
  • mfrom: (524.1.1)
  • Revision ID: git-v1:77c8c0fd9740f3f8aa2fff0cf38c05f2a9758b48
Merge pull request #920 from yatsukhnenko/develop

REDIS_STREAM_CLOSE_MARK_FAILED macro

Show diffs side-by-side

added added

removed removed

Lines of Context:
159
159
        if((MULTI == redis_sock->mode) || redis_sock->watching || count == 10) {
160
160
            /* too many failures */
161
161
            if(redis_sock->stream) { /* close stream if still here */
162
 
                redis_stream_close(redis_sock TSRMLS_CC);
163
 
                redis_sock->stream = NULL;
164
 
                redis_sock->mode   = ATOMIC;
165
 
                redis_sock->status = REDIS_SOCK_STATUS_FAILED;
166
 
                redis_sock->watching = 0;
 
162
                REDIS_STREAM_CLOSE_MARK_FAILED(redis_sock);
167
163
            }
168
164
            if(!no_throw) {
169
165
                zend_throw_exception(redis_exception_ce, "Connection lost", 
432
428
    }
433
429
 
434
430
    if(php_stream_gets(redis_sock->stream, inbuf, 1024) == NULL) {
435
 
        redis_stream_close(redis_sock TSRMLS_CC);
436
 
        redis_sock->stream = NULL;
437
 
        redis_sock->status = REDIS_SOCK_STATUS_FAILED;
438
 
        redis_sock->mode = ATOMIC;
439
 
        redis_sock->watching = 0;
 
431
        REDIS_STREAM_CLOSE_MARK_FAILED(redis_sock);
440
432
        zend_throw_exception(redis_exception_ce, 
441
433
            "read error on connection", 0 TSRMLS_CC);
442
434
        return NULL;
502
494
    }
503
495
 
504
496
    if(php_stream_gets(redis_sock->stream, inbuf, 1024) == NULL) {
505
 
        redis_stream_close(redis_sock TSRMLS_CC);
506
 
        redis_sock->stream = NULL;
507
 
        redis_sock->status = REDIS_SOCK_STATUS_FAILED;
508
 
        redis_sock->mode = ATOMIC;
509
 
        redis_sock->watching = 0;
 
497
        REDIS_STREAM_CLOSE_MARK_FAILED(redis_sock);
510
498
        zend_throw_exception(redis_exception_ce, "read error on connection", 
511
499
                             0 TSRMLS_CC);
512
500
        return NULL;
528
516
            return NULL;
529
517
        case '$':
530
518
            *buf_len = atoi(inbuf + 1);
531
 
            resp = redis_sock_read_bulk_reply(redis_sock, *buf_len TSRMLS_CC);
532
 
            return resp;
 
519
            return redis_sock_read_bulk_reply(redis_sock, *buf_len TSRMLS_CC);
533
520
 
534
521
        case '*':
535
522
            /* For null multi-bulk replies (like timeouts from brpoplpush): */
544
531
            /* :123\r\n */
545
532
            *buf_len = strlen(inbuf) - 2;
546
533
            if(*buf_len >= 2) {
547
 
                resp = emalloc(1+*buf_len);
548
 
                memcpy(resp, inbuf, *buf_len);
549
 
                resp[*buf_len] = 0;
550
 
                return resp;
 
534
                return estrndup(inbuf, *buf_len);
551
535
            }
552
536
        default:
553
537
            zend_throw_exception_ex(
1061
1045
                   have a key and value, but check anyway. */
1062
1046
                if(kpos && vpos) {
1063
1047
                    /* Allocate, copy in our key */
1064
 
                    key = emalloc(klen + 1);
1065
 
                    strncpy(key, kpos, klen);
1066
 
                    key[klen] = 0;
 
1048
                    key = estrndup(kpos, klen);
1067
1049
 
1068
1050
                    /* Allocate, copy in our value */
1069
 
                    value = emalloc(p-lpos+1);
1070
 
                    strncpy(value,lpos,p-lpos+1);
1071
 
                    value[p-lpos]=0;
 
1051
                    value = estrndup(lpos, p - lpos);
1072
1052
 
1073
1053
                    /* Treat numbers as numbers, strings as strings */
1074
1054
                    is_numeric = 1;
1312
1292
        return -1;
1313
1293
    }
1314
1294
    if(php_stream_gets(redis_sock->stream, inbuf, 1024) == NULL) {
1315
 
        redis_stream_close(redis_sock TSRMLS_CC);
1316
 
        redis_sock->stream = NULL;
1317
 
        redis_sock->status = REDIS_SOCK_STATUS_FAILED;
1318
 
        redis_sock->mode = ATOMIC;
1319
 
        redis_sock->watching = 0;
 
1295
        REDIS_STREAM_CLOSE_MARK_FAILED(redis_sock);
1320
1296
        zend_throw_exception(redis_exception_ce, "read error on connection", 0 TSRMLS_CC);
1321
1297
        return -1;
1322
1298
    }
1560
1536
    redis_sock->retry_interval = retry_interval * 1000;
1561
1537
    redis_sock->persistent = persistent;
1562
1538
    redis_sock->lazy_connect = lazy_connect;
 
1539
    redis_sock->persistent_id = NULL;
1563
1540
 
1564
1541
    if(persistent_id) {
1565
 
        size_t persistent_id_len = strlen(persistent_id);
1566
 
        redis_sock->persistent_id = ecalloc(persistent_id_len + 1, 1);
1567
 
        memcpy(redis_sock->persistent_id, persistent_id, persistent_id_len);
1568
 
    } else {
1569
 
        redis_sock->persistent_id = NULL;
 
1542
        redis_sock->persistent_id = estrdup(persistent_id);
1570
1543
    }
1571
1544
 
1572
 
    memcpy(redis_sock->host, host, host_len);
1573
 
    redis_sock->host[host_len] = '\0';
1574
 
 
1575
1545
    redis_sock->port    = port;
1576
1546
    redis_sock->timeout = timeout;
1577
1547
    redis_sock->read_timeout = timeout;
1809
1779
        return -1;
1810
1780
    }
1811
1781
    if(php_stream_gets(redis_sock->stream, inbuf, 1024) == NULL) {
1812
 
        redis_stream_close(redis_sock TSRMLS_CC);
1813
 
        redis_sock->stream = NULL;
1814
 
        redis_sock->status = REDIS_SOCK_STATUS_FAILED;
1815
 
        redis_sock->mode = ATOMIC;
1816
 
        redis_sock->watching = 0;
 
1782
        REDIS_STREAM_CLOSE_MARK_FAILED(redis_sock);
1817
1783
        zend_throw_exception(redis_exception_ce, "read error on connection", 0 
1818
1784
            TSRMLS_CC);
1819
1785
        return -1;
1860
1826
        return -1;
1861
1827
    }
1862
1828
    if(php_stream_gets(redis_sock->stream, inbuf, 1024) == NULL) {
1863
 
        redis_stream_close(redis_sock TSRMLS_CC);
1864
 
        redis_sock->stream = NULL;
1865
 
        redis_sock->status = REDIS_SOCK_STATUS_FAILED;
1866
 
        redis_sock->mode = ATOMIC;
1867
 
        redis_sock->watching = 0;
 
1829
        REDIS_STREAM_CLOSE_MARK_FAILED(redis_sock);
1868
1830
        zend_throw_exception(redis_exception_ce, "read error on connection", 0 TSRMLS_CC);
1869
1831
        return -1;
1870
1832
    }
1947
1909
        return -1;
1948
1910
    }
1949
1911
    if(php_stream_gets(redis_sock->stream, inbuf, 1024) == NULL) {
1950
 
        redis_stream_close(redis_sock TSRMLS_CC);
1951
 
        redis_sock->stream = NULL;
1952
 
        redis_sock->status = REDIS_SOCK_STATUS_FAILED;
1953
 
        redis_sock->mode = ATOMIC;
1954
 
        redis_sock->watching = 0;
 
1912
        REDIS_STREAM_CLOSE_MARK_FAILED(redis_sock);
1955
1913
        zend_throw_exception(redis_exception_ce, "read error on connection", 0 TSRMLS_CC);
1956
1914
        return -1;
1957
1915
    }
2231
2189
                           == NULL) 
2232
2190
    {
2233
2191
        // Close, put our socket state into error
2234
 
        redis_stream_close(redis_sock TSRMLS_CC);
2235
 
        redis_sock->stream = NULL;
2236
 
        redis_sock->status = REDIS_SOCK_STATUS_FAILED;
2237
 
        redis_sock->mode = ATOMIC;
2238
 
        redis_sock->watching = 0;
 
2192
        REDIS_STREAM_CLOSE_MARK_FAILED(redis_sock);
2239
2193
 
2240
2194
        // Throw a read error exception
2241
2195
        zend_throw_exception(redis_exception_ce, "read error on connection", 
2465
2419
        return 0;
2466
2420
}
2467
2421
 
2468
 
/* vim: set tabstop=4 softtabstop=4 noexpandtab shiftwidth=4: */
 
2422
/* vim: set tabstop=4 softtabstop=4 expandtab shiftwidth=4: */