@@ -435,15 +435,9 @@ redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAMETERS,
435
435
{
436
436
char inbuf [1024 ];
437
437
int numElems ;
438
+ size_t len ;
438
439
439
- if (-1 == redis_check_eof (redis_sock , 0 TSRMLS_CC )) {
440
- return NULL ;
441
- }
442
-
443
- if (php_stream_gets (redis_sock -> stream , inbuf , 1024 ) == NULL ) {
444
- REDIS_STREAM_CLOSE_MARK_FAILED (redis_sock );
445
- zend_throw_exception (redis_exception_ce ,
446
- "read error on connection" , 0 TSRMLS_CC );
440
+ if (redis_sock_gets (redis_sock , inbuf , sizeof (inbuf ) - 1 , & len TSRMLS_CC ) < 0 ) {
447
441
return NULL ;
448
442
}
449
443
@@ -503,30 +497,23 @@ redis_sock_read_bulk_reply(RedisSock *redis_sock, int bytes TSRMLS_DC)
503
497
/**
504
498
* redis_sock_read
505
499
*/
506
- PHP_REDIS_API char * redis_sock_read (RedisSock * redis_sock , int * buf_len TSRMLS_DC )
500
+ PHP_REDIS_API char *
501
+ redis_sock_read (RedisSock * redis_sock , int * buf_len TSRMLS_DC )
507
502
{
508
503
char inbuf [1024 ];
509
- size_t err_len ;
504
+ size_t len ;
510
505
511
506
* buf_len = 0 ;
512
- if (-1 == redis_check_eof (redis_sock , 0 TSRMLS_CC )) {
513
- return NULL ;
514
- }
515
-
516
- if (php_stream_gets (redis_sock -> stream , inbuf , 1024 ) == NULL ) {
517
- REDIS_STREAM_CLOSE_MARK_FAILED (redis_sock );
518
- zend_throw_exception (redis_exception_ce , "read error on connection" ,
519
- 0 TSRMLS_CC );
507
+ if (redis_sock_gets (redis_sock , inbuf , sizeof (inbuf ) - 1 , & len TSRMLS_CC ) < 0 ) {
520
508
return NULL ;
521
509
}
522
510
523
511
switch (inbuf [0 ]) {
524
512
case '-' :
525
- err_len = strlen (inbuf + 1 ) - 2 ;
526
- redis_sock_set_err (redis_sock , inbuf + 1 , err_len );
513
+ redis_sock_set_err (redis_sock , inbuf + 1 , len );
527
514
528
515
/* Filter our ERROR through the few that should actually throw */
529
- redis_error_throw (inbuf + 1 , err_len TSRMLS_CC );
516
+ redis_error_throw (inbuf + 1 , len TSRMLS_CC );
530
517
531
518
/* Handle stale data error */
532
519
if (memcmp (inbuf + 1 , "-ERR SYNC " , 10 ) == 0 ) {
@@ -547,10 +534,10 @@ PHP_REDIS_API char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_D
547
534
548
535
case '+' :
549
536
case ':' :
550
- /* Single Line Reply */
551
- /* :123\r\n */
552
- * buf_len = strlen ( inbuf ) - 2 ;
553
- if ( * buf_len >= 2 ) {
537
+ /* Single Line Reply */
538
+ /* +OK or :123 */
539
+ if ( len > 1 ) {
540
+ * buf_len = len ;
554
541
return estrndup (inbuf , * buf_len );
555
542
}
556
543
default :
@@ -1266,13 +1253,9 @@ redis_mbulk_reply_zipped(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
1266
1253
{
1267
1254
char inbuf [1024 ];
1268
1255
int numElems ;
1256
+ size_t len ;
1269
1257
1270
- if (-1 == redis_check_eof (redis_sock , 0 TSRMLS_CC )) {
1271
- return -1 ;
1272
- }
1273
- if (php_stream_gets (redis_sock -> stream , inbuf , 1024 ) == NULL ) {
1274
- REDIS_STREAM_CLOSE_MARK_FAILED (redis_sock );
1275
- zend_throw_exception (redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
1258
+ if (redis_sock_gets (redis_sock , inbuf , sizeof (inbuf ) - 1 , & len TSRMLS_CC ) < 0 ) {
1276
1259
return -1 ;
1277
1260
}
1278
1261
@@ -1723,15 +1706,10 @@ PHP_REDIS_API int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS,
1723
1706
void * ctx )
1724
1707
{
1725
1708
char inbuf [1024 ];
1726
- int numElems , err_len ;
1709
+ int numElems ;
1710
+ size_t len ;
1727
1711
1728
- if (-1 == redis_check_eof (redis_sock , 0 TSRMLS_CC )) {
1729
- return -1 ;
1730
- }
1731
- if (php_stream_gets (redis_sock -> stream , inbuf , 1024 ) == NULL ) {
1732
- REDIS_STREAM_CLOSE_MARK_FAILED (redis_sock );
1733
- zend_throw_exception (redis_exception_ce , "read error on connection" , 0
1734
- TSRMLS_CC );
1712
+ if (redis_sock_gets (redis_sock , inbuf , sizeof (inbuf ) - 1 , & len TSRMLS_CC ) < 0 ) {
1735
1713
return -1 ;
1736
1714
}
1737
1715
@@ -1740,8 +1718,7 @@ PHP_REDIS_API int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS,
1740
1718
add_next_index_bool (z_tab , 0 );
1741
1719
} else {
1742
1720
if (inbuf [0 ] == '-' ) {
1743
- err_len = strlen (inbuf + 1 ) - 2 ;
1744
- redis_sock_set_err (redis_sock , inbuf + 1 , err_len );
1721
+ redis_sock_set_err (redis_sock , inbuf + 1 , len );
1745
1722
}
1746
1723
RETVAL_FALSE ;
1747
1724
}
@@ -1768,17 +1745,14 @@ PHP_REDIS_API int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS,
1768
1745
1769
1746
/* Like multibulk reply, but don't touch the values, they won't be unserialized
1770
1747
* (this is used by HKEYS). */
1771
- PHP_REDIS_API int redis_mbulk_reply_raw (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock , zval * z_tab , void * ctx )
1748
+ PHP_REDIS_API int
1749
+ redis_mbulk_reply_raw (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock , zval * z_tab , void * ctx )
1772
1750
{
1773
1751
char inbuf [1024 ];
1774
- int numElems , err_len ;
1752
+ int numElems ;
1753
+ size_t len ;
1775
1754
1776
- if (-1 == redis_check_eof (redis_sock , 0 TSRMLS_CC )) {
1777
- return -1 ;
1778
- }
1779
- if (php_stream_gets (redis_sock -> stream , inbuf , 1024 ) == NULL ) {
1780
- REDIS_STREAM_CLOSE_MARK_FAILED (redis_sock );
1781
- zend_throw_exception (redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
1755
+ if (redis_sock_gets (redis_sock , inbuf , sizeof (inbuf ) - 1 , & len TSRMLS_CC ) < 0 ) {
1782
1756
return -1 ;
1783
1757
}
1784
1758
@@ -1787,8 +1761,7 @@ PHP_REDIS_API int redis_mbulk_reply_raw(INTERNAL_FUNCTION_PARAMETERS, RedisSock
1787
1761
add_next_index_bool (z_tab , 0 );
1788
1762
} else {
1789
1763
if (inbuf [0 ] == '-' ) {
1790
- err_len = strlen (inbuf + 1 ) - 2 ;
1791
- redis_sock_set_err (redis_sock , inbuf + 1 , err_len );
1764
+ redis_sock_set_err (redis_sock , inbuf + 1 , len );
1792
1765
}
1793
1766
RETVAL_FALSE ;
1794
1767
}
@@ -1858,15 +1831,11 @@ PHP_REDIS_API int redis_mbulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, RedisSoc
1858
1831
char inbuf [1024 ], * response ;
1859
1832
int response_len ;
1860
1833
int i , numElems ;
1834
+ size_t len ;
1861
1835
1862
1836
zval * z_keys = ctx ;
1863
1837
1864
- if (-1 == redis_check_eof (redis_sock , 0 TSRMLS_CC )) {
1865
- return -1 ;
1866
- }
1867
- if (php_stream_gets (redis_sock -> stream , inbuf , 1024 ) == NULL ) {
1868
- REDIS_STREAM_CLOSE_MARK_FAILED (redis_sock );
1869
- zend_throw_exception (redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
1838
+ if (redis_sock_gets (redis_sock , inbuf , sizeof (inbuf ) - 1 , & len TSRMLS_CC ) < 0 ) {
1870
1839
return -1 ;
1871
1840
}
1872
1841
0 commit comments