@@ -148,11 +148,7 @@ PHP_REDIS_API int redis_check_eof(RedisSock *redis_sock, int no_throw TSRMLS_DC)
148
148
if ((MULTI == redis_sock -> mode ) || redis_sock -> watching || count == 10 ) {
149
149
/* too many failures */
150
150
if (redis_sock -> stream ) { /* close stream if still here */
151
- redis_stream_close (redis_sock TSRMLS_CC );
152
- redis_sock -> stream = NULL ;
153
- redis_sock -> mode = ATOMIC ;
154
- redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
155
- redis_sock -> watching = 0 ;
151
+ REDIS_STREAM_CLOSE_MARK_FAILED (redis_sock );
156
152
}
157
153
if (!no_throw ) {
158
154
zend_throw_exception (redis_exception_ce , "Connection lost" ,
@@ -411,11 +407,7 @@ redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAMETERS,
411
407
}
412
408
413
409
if (php_stream_gets (redis_sock -> stream , inbuf , 1024 ) == NULL ) {
414
- redis_stream_close (redis_sock TSRMLS_CC );
415
- redis_sock -> stream = NULL ;
416
- redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
417
- redis_sock -> mode = ATOMIC ;
418
- redis_sock -> watching = 0 ;
410
+ REDIS_STREAM_CLOSE_MARK_FAILED (redis_sock );
419
411
zend_throw_exception (redis_exception_ce ,
420
412
"read error on connection" , 0 TSRMLS_CC );
421
413
return ;
@@ -478,12 +470,8 @@ PHP_REDIS_API char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_D
478
470
}
479
471
480
472
if (php_stream_gets (redis_sock -> stream , inbuf , 1024 ) == NULL ) {
481
- redis_stream_close (redis_sock TSRMLS_CC );
482
- redis_sock -> stream = NULL ;
483
- redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
484
- redis_sock -> mode = ATOMIC ;
485
- redis_sock -> watching = 0 ;
486
- zend_throw_exception (redis_exception_ce , "read error on connection" ,
473
+ REDIS_STREAM_CLOSE_MARK_FAILED (redis_sock );
474
+ zend_throw_exception (redis_exception_ce , "read error on connection" ,
487
475
0 TSRMLS_CC );
488
476
return NULL ;
489
477
}
@@ -504,8 +492,7 @@ PHP_REDIS_API char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_D
504
492
return NULL ;
505
493
case '$' :
506
494
* buf_len = atoi (inbuf + 1 );
507
- resp = redis_sock_read_bulk_reply (redis_sock , * buf_len TSRMLS_CC );
508
- return resp ;
495
+ return redis_sock_read_bulk_reply (redis_sock , * buf_len TSRMLS_CC );
509
496
510
497
case '*' :
511
498
/* For null multi-bulk replies (like timeouts from brpoplpush): */
@@ -521,10 +508,7 @@ PHP_REDIS_API char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_D
521
508
/* :123\r\n */
522
509
* buf_len = strlen (inbuf ) - 2 ;
523
510
if (* buf_len >= 2 ) {
524
- resp = emalloc (1 + * buf_len );
525
- memcpy (resp , inbuf , * buf_len );
526
- resp [* buf_len ] = 0 ;
527
- return resp ;
511
+ return estrndup (inbuf , * buf_len );
528
512
}
529
513
default :
530
514
zend_throw_exception_ex (
@@ -1026,14 +1010,10 @@ PHP_REDIS_API void redis_parse_client_list_response(char *response, zval *z_resu
1026
1010
have a key and value, but check anyway. */
1027
1011
if (kpos && vpos ) {
1028
1012
/* Allocate, copy in our key */
1029
- key = emalloc (klen + 1 );
1030
- strncpy (key , kpos , klen );
1031
- key [klen ] = 0 ;
1013
+ key = estrndup (kpos , klen );
1032
1014
1033
1015
/* Allocate, copy in our value */
1034
- value = emalloc (p - lpos + 1 );
1035
- strncpy (value ,lpos ,p - lpos + 1 );
1036
- value [p - lpos ]= 0 ;
1016
+ value = estrndup (lpos , p - lpos );
1037
1017
1038
1018
/* Treat numbers as numbers, strings as strings */
1039
1019
is_numeric = 1 ;
@@ -1270,11 +1250,7 @@ redis_mbulk_reply_zipped(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
1270
1250
return -1 ;
1271
1251
}
1272
1252
if (php_stream_gets (redis_sock -> stream , inbuf , 1024 ) == NULL ) {
1273
- redis_stream_close (redis_sock TSRMLS_CC );
1274
- redis_sock -> stream = NULL ;
1275
- redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
1276
- redis_sock -> mode = ATOMIC ;
1277
- redis_sock -> watching = 0 ;
1253
+ REDIS_STREAM_CLOSE_MARK_FAILED (redis_sock );
1278
1254
zend_throw_exception (redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
1279
1255
return -1 ;
1280
1256
}
@@ -1515,18 +1491,12 @@ redis_sock_create(char *host, int host_len, unsigned short port, double timeout,
1515
1491
redis_sock -> retry_interval = retry_interval * 1000 ;
1516
1492
redis_sock -> persistent = persistent ;
1517
1493
redis_sock -> lazy_connect = lazy_connect ;
1494
+ redis_sock -> persistent_id = NULL ;
1518
1495
1519
1496
if (persistent_id ) {
1520
- size_t persistent_id_len = strlen (persistent_id );
1521
- redis_sock -> persistent_id = ecalloc (persistent_id_len + 1 , 1 );
1522
- memcpy (redis_sock -> persistent_id , persistent_id , persistent_id_len );
1523
- } else {
1524
- redis_sock -> persistent_id = NULL ;
1497
+ redis_sock -> persistent_id = estrdup (persistent_id );
1525
1498
}
1526
1499
1527
- memcpy (redis_sock -> host , host , host_len );
1528
- redis_sock -> host [host_len ] = '\0' ;
1529
-
1530
1500
redis_sock -> port = port ;
1531
1501
redis_sock -> timeout = timeout ;
1532
1502
redis_sock -> read_timeout = timeout ;
@@ -1762,12 +1732,8 @@ PHP_REDIS_API int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS,
1762
1732
return -1 ;
1763
1733
}
1764
1734
if (php_stream_gets (redis_sock -> stream , inbuf , 1024 ) == NULL ) {
1765
- redis_stream_close (redis_sock TSRMLS_CC );
1766
- redis_sock -> stream = NULL ;
1767
- redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
1768
- redis_sock -> mode = ATOMIC ;
1769
- redis_sock -> watching = 0 ;
1770
- zend_throw_exception (redis_exception_ce , "read error on connection" , 0
1735
+ REDIS_STREAM_CLOSE_MARK_FAILED (redis_sock );
1736
+ zend_throw_exception (redis_exception_ce , "read error on connection" , 0
1771
1737
TSRMLS_CC );
1772
1738
return -1 ;
1773
1739
}
@@ -1811,11 +1777,7 @@ PHP_REDIS_API int redis_mbulk_reply_raw(INTERNAL_FUNCTION_PARAMETERS, RedisSock
1811
1777
return -1 ;
1812
1778
}
1813
1779
if (php_stream_gets (redis_sock -> stream , inbuf , 1024 ) == NULL ) {
1814
- redis_stream_close (redis_sock TSRMLS_CC );
1815
- redis_sock -> stream = NULL ;
1816
- redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
1817
- redis_sock -> mode = ATOMIC ;
1818
- redis_sock -> watching = 0 ;
1780
+ REDIS_STREAM_CLOSE_MARK_FAILED (redis_sock );
1819
1781
zend_throw_exception (redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
1820
1782
return -1 ;
1821
1783
}
@@ -1895,11 +1857,7 @@ PHP_REDIS_API int redis_mbulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, RedisSoc
1895
1857
return -1 ;
1896
1858
}
1897
1859
if (php_stream_gets (redis_sock -> stream , inbuf , 1024 ) == NULL ) {
1898
- redis_stream_close (redis_sock TSRMLS_CC );
1899
- redis_sock -> stream = NULL ;
1900
- redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
1901
- redis_sock -> mode = ATOMIC ;
1902
- redis_sock -> watching = 0 ;
1860
+ REDIS_STREAM_CLOSE_MARK_FAILED (redis_sock );
1903
1861
zend_throw_exception (redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
1904
1862
return -1 ;
1905
1863
}
@@ -2119,11 +2077,7 @@ redis_sock_gets(RedisSock *redis_sock, char *buf, int buf_size,
2119
2077
== NULL )
2120
2078
{
2121
2079
// Close, put our socket state into error
2122
- redis_stream_close (redis_sock TSRMLS_CC );
2123
- redis_sock -> stream = NULL ;
2124
- redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
2125
- redis_sock -> mode = ATOMIC ;
2126
- redis_sock -> watching = 0 ;
2080
+ REDIS_STREAM_CLOSE_MARK_FAILED (redis_sock );
2127
2081
2128
2082
// Throw a read error exception
2129
2083
zend_throw_exception (redis_exception_ce , "read error on connection" ,
@@ -2346,4 +2300,4 @@ redis_read_variant_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
2346
2300
return 0 ;
2347
2301
}
2348
2302
2349
- /* vim: set tabstop=4 softtabstop=4 noexpandtab shiftwidth=4: */
2303
+ /* vim: set tabstop=4 softtabstop=4 expandtab shiftwidth=4: */
0 commit comments