@@ -435,15 +435,9 @@ redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAMETERS,
435435{
436436 char inbuf [1024 ];
437437 int numElems ;
438+ size_t len ;
438439
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 ) {
447441 return NULL ;
448442 }
449443
@@ -503,30 +497,23 @@ redis_sock_read_bulk_reply(RedisSock *redis_sock, int bytes TSRMLS_DC)
503497/**
504498 * redis_sock_read
505499 */
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 )
507502{
508503 char inbuf [1024 ];
509- size_t err_len ;
504+ size_t len ;
510505
511506 * 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 ) {
520508 return NULL ;
521509 }
522510
523511 switch (inbuf [0 ]) {
524512 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 );
527514
528515 /* 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 );
530517
531518 /* Handle stale data error */
532519 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
547534
548535 case '+' :
549536 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 ;
554541 return estrndup (inbuf , * buf_len );
555542 }
556543 default :
@@ -1266,13 +1253,9 @@ redis_mbulk_reply_zipped(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
12661253{
12671254 char inbuf [1024 ];
12681255 int numElems ;
1256+ size_t len ;
12691257
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 ) {
12761259 return -1 ;
12771260 }
12781261
@@ -1723,15 +1706,10 @@ PHP_REDIS_API int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS,
17231706 void * ctx )
17241707{
17251708 char inbuf [1024 ];
1726- int numElems , err_len ;
1709+ int numElems ;
1710+ size_t len ;
17271711
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 ) {
17351713 return -1 ;
17361714 }
17371715
@@ -1740,8 +1718,7 @@ PHP_REDIS_API int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS,
17401718 add_next_index_bool (z_tab , 0 );
17411719 } else {
17421720 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 );
17451722 }
17461723 RETVAL_FALSE ;
17471724 }
@@ -1768,17 +1745,14 @@ PHP_REDIS_API int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS,
17681745
17691746/* Like multibulk reply, but don't touch the values, they won't be unserialized
17701747 * (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 )
17721750{
17731751 char inbuf [1024 ];
1774- int numElems , err_len ;
1752+ int numElems ;
1753+ size_t len ;
17751754
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 ) {
17821756 return -1 ;
17831757 }
17841758
@@ -1787,8 +1761,7 @@ PHP_REDIS_API int redis_mbulk_reply_raw(INTERNAL_FUNCTION_PARAMETERS, RedisSock
17871761 add_next_index_bool (z_tab , 0 );
17881762 } else {
17891763 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 );
17921765 }
17931766 RETVAL_FALSE ;
17941767 }
@@ -1858,15 +1831,11 @@ PHP_REDIS_API int redis_mbulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, RedisSoc
18581831 char inbuf [1024 ], * response ;
18591832 int response_len ;
18601833 int i , numElems ;
1834+ size_t len ;
18611835
18621836 zval * z_keys = ctx ;
18631837
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 ) {
18701839 return -1 ;
18711840 }
18721841
0 commit comments