5
5
#include "common.h"
6
6
#include "php_network.h"
7
7
#include <sys/types.h>
8
+ #ifndef _MSC_VER
8
9
#include <netinet/tcp.h> /* TCP_NODELAY */
9
10
#include <sys/socket.h>
11
+ #endif
10
12
#include <ext/standard/php_smart_str.h>
11
13
#include <ext/standard/php_var.h>
12
14
@@ -61,6 +63,8 @@ PHPAPI int redis_check_eof(RedisSock *redis_sock TSRMLS_DC)
61
63
62
64
PHPAPI zval * redis_sock_read_multibulk_reply_zval (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock ) {
63
65
char inbuf [1024 ];
66
+ int numElems ;
67
+ zval * z_tab ;
64
68
65
69
if (-1 == redis_check_eof (redis_sock TSRMLS_CC )) {
66
70
return NULL ;
@@ -78,9 +82,8 @@ PHPAPI zval *redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAMETERS,
78
82
if (inbuf [0 ] != '*' ) {
79
83
return NULL ;
80
84
}
81
- int numElems = atoi (inbuf + 1 );
85
+ numElems = atoi (inbuf + 1 );
82
86
83
- zval * z_tab ;
84
87
MAKE_STD_ZVAL (z_tab );
85
88
array_init (z_tab );
86
89
@@ -106,14 +109,15 @@ PHPAPI char *redis_sock_read_bulk_reply(RedisSock *redis_sock, int bytes TSRMLS_
106
109
if (bytes == -1 ) {
107
110
return NULL ;
108
111
} else {
109
- reply = emalloc (bytes + 1 );
112
+ char c ;
113
+ int i ;
114
+
115
+ reply = emalloc (bytes + 1 );
110
116
111
117
while (offset < bytes ) {
112
118
got = php_stream_read (redis_sock -> stream , reply + offset , bytes - offset );
113
119
offset += got ;
114
120
}
115
- char c ;
116
- int i ;
117
121
for (i = 0 ; i < 2 ; i ++ ) {
118
122
php_stream_read (redis_sock -> stream , & c , 1 );
119
123
}
@@ -128,7 +132,6 @@ PHPAPI char *redis_sock_read_bulk_reply(RedisSock *redis_sock, int bytes TSRMLS_
128
132
*/
129
133
PHPAPI char * redis_sock_read (RedisSock * redis_sock , int * buf_len TSRMLS_DC )
130
134
{
131
-
132
135
char inbuf [1024 ];
133
136
char * resp = NULL ;
134
137
@@ -146,7 +149,6 @@ PHPAPI char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC)
146
149
}
147
150
148
151
switch (inbuf [0 ]) {
149
-
150
152
case '-' :
151
153
return NULL ;
152
154
@@ -156,6 +158,7 @@ PHPAPI char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC)
156
158
return resp ;
157
159
158
160
case '+' :
161
+ case '*' :
159
162
case ':' :
160
163
// Single Line Reply
161
164
/* :123\r\n */
@@ -180,7 +183,6 @@ PHPAPI char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC)
180
183
}
181
184
182
185
void add_constant_long (zend_class_entry * ce , char * name , int value ) {
183
-
184
186
zval * constval ;
185
187
constval = pemalloc (sizeof (zval ), 1 );
186
188
INIT_PZVAL (constval );
@@ -330,12 +332,13 @@ PHPAPI void redis_bulk_double_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *
330
332
331
333
char * response ;
332
334
int response_len ;
335
+ double ret ;
333
336
334
337
if ((response = redis_sock_read (redis_sock , & response_len TSRMLS_CC )) == NULL ) {
335
338
RETURN_FALSE ;
336
339
}
337
340
338
- double ret = atof (response );
341
+ ret = atof (response );
339
342
efree (response );
340
343
IF_MULTI_OR_PIPELINE () {
341
344
add_next_index_double (z_tab , ret );
@@ -347,12 +350,12 @@ PHPAPI void redis_bulk_double_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *
347
350
PHPAPI void redis_type_response (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock , zval * z_tab , void * ctx ) {
348
351
char * response ;
349
352
int response_len ;
353
+ long l ;
350
354
351
355
if ((response = redis_sock_read (redis_sock , & response_len TSRMLS_CC )) == NULL ) {
352
356
RETURN_FALSE ;
353
357
}
354
358
355
- long l ;
356
359
if (strncmp (response , "+string" , 7 ) == 0 ) {
357
360
l = REDIS_STRING ;
358
361
} else if (strncmp (response , "+set" , 4 ) == 0 ){
@@ -378,22 +381,23 @@ PHPAPI void redis_type_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_s
378
381
PHPAPI void redis_info_response (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock , zval * z_tab , void * ctx ) {
379
382
char * response ;
380
383
int response_len ;
384
+ char * pos , * cur ;
385
+ char * key , * value , * p ;
386
+ int is_numeric ;
387
+ zval * z_multi_result ;
381
388
382
389
if ((response = redis_sock_read (redis_sock , & response_len TSRMLS_CC )) == NULL ) {
383
390
RETURN_FALSE ;
384
391
}
385
392
386
- zval * z_multi_result ;
387
393
MAKE_STD_ZVAL (z_multi_result );
388
394
array_init (z_multi_result ); /* pre-allocate array for multi's results. */
389
395
/* response :: [response_line]
390
396
* response_line :: key ':' value CRLF
391
397
*/
392
398
393
- char * pos , * cur = response ;
399
+ cur = response ;
394
400
while (1 ) {
395
- char * key , * value , * p ;
396
- int is_numeric ;
397
401
/* key */
398
402
pos = strchr (cur , ':' );
399
403
if (pos == NULL ) {
@@ -488,16 +492,16 @@ PHPAPI void redis_long_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_s
488
492
}
489
493
490
494
if (response [0 ] == ':' ) {
491
- long long ret = atoll (response + 1 );
495
+ long ret = atol (response + 1 );
492
496
IF_MULTI_OR_PIPELINE () {
493
- if (ret > (long long )LONG_MAX ) { /* overflow */
497
+ if (ret > (long )LONG_MAX ) { /* overflow */
494
498
add_next_index_stringl (z_tab , response + 1 , response_len - 1 , 1 );
495
499
} else {
496
500
efree (response );
497
501
add_next_index_long (z_tab , (long )ret );
498
502
}
499
503
} else {
500
- if (ret > (long long )LONG_MAX ) { /* overflow */
504
+ if (ret > (long )LONG_MAX ) { /* overflow */
501
505
RETURN_STRINGL (response + 1 , response_len - 1 , 1 );
502
506
} else {
503
507
efree (response );
@@ -522,6 +526,8 @@ PHPAPI int redis_sock_read_multibulk_reply_zipped_with_flag(INTERNAL_FUNCTION_PA
522
526
*/
523
527
524
528
char inbuf [1024 ];
529
+ int numElems ;
530
+ zval * z_multi_result ;
525
531
526
532
if (-1 == redis_check_eof (redis_sock TSRMLS_CC )) {
527
533
return -1 ;
@@ -539,8 +545,7 @@ PHPAPI int redis_sock_read_multibulk_reply_zipped_with_flag(INTERNAL_FUNCTION_PA
539
545
if (inbuf [0 ] != '*' ) {
540
546
return -1 ;
541
547
}
542
- int numElems = atoi (inbuf + 1 );
543
- zval * z_multi_result ;
548
+ numElems = atoi (inbuf + 1 );
544
549
MAKE_STD_ZVAL (z_multi_result );
545
550
array_init (z_multi_result ); /* pre-allocate array for multi's results. */
546
551
@@ -699,6 +704,8 @@ PHPAPI int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
699
704
struct timeval tv , * tv_ptr = NULL ;
700
705
char * host = NULL , * persistent_id = NULL , * errstr = NULL ;
701
706
int host_len , err = 0 ;
707
+ php_netstream_data_t * sock ;
708
+ int tcp_flag = 1 ;
702
709
703
710
if (redis_sock -> stream != NULL ) {
704
711
redis_sock_disconnect (redis_sock TSRMLS_CC );
@@ -742,8 +749,7 @@ PHPAPI int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
742
749
}
743
750
744
751
/* set TCP_NODELAY */
745
- php_netstream_data_t * sock = (php_netstream_data_t * )redis_sock -> stream -> abstract ;
746
- int tcp_flag = 1 ;
752
+ sock = (php_netstream_data_t * )redis_sock -> stream -> abstract ;
747
753
setsockopt (sock -> socket , IPPROTO_TCP , TCP_NODELAY , (char * ) & tcp_flag , sizeof (int ));
748
754
749
755
php_stream_auto_cleanup (redis_sock -> stream );
@@ -820,6 +826,8 @@ PHPAPI int redis_sock_disconnect(RedisSock *redis_sock TSRMLS_DC)
820
826
PHPAPI int redis_sock_read_multibulk_reply (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock , zval * z_tab , void * ctx )
821
827
{
822
828
char inbuf [1024 ];
829
+ int numElems ;
830
+ zval * z_multi_result ;
823
831
824
832
if (-1 == redis_check_eof (redis_sock TSRMLS_CC )) {
825
833
return -1 ;
@@ -836,8 +844,7 @@ PHPAPI int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSo
836
844
if (inbuf [0 ] != '*' ) {
837
845
return -1 ;
838
846
}
839
- int numElems = atoi (inbuf + 1 );
840
- zval * z_multi_result ;
847
+ numElems = atoi (inbuf + 1 );
841
848
MAKE_STD_ZVAL (z_multi_result );
842
849
array_init (z_multi_result ); /* pre-allocate array for multi's results. */
843
850
@@ -860,6 +867,8 @@ PHPAPI int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSo
860
867
PHPAPI int redis_sock_read_multibulk_reply_raw (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock , zval * z_tab , void * ctx )
861
868
{
862
869
char inbuf [1024 ];
870
+ int numElems ;
871
+ zval * z_multi_result ;
863
872
864
873
if (-1 == redis_check_eof (redis_sock TSRMLS_CC )) {
865
874
return -1 ;
@@ -876,8 +885,7 @@ PHPAPI int redis_sock_read_multibulk_reply_raw(INTERNAL_FUNCTION_PARAMETERS, Red
876
885
if (inbuf [0 ] != '*' ) {
877
886
return -1 ;
878
887
}
879
- int numElems = atoi (inbuf + 1 );
880
- zval * z_multi_result ;
888
+ numElems = atoi (inbuf + 1 );
881
889
MAKE_STD_ZVAL (z_multi_result );
882
890
array_init (z_multi_result ); /* pre-allocate array for multi's results. */
883
891
@@ -926,6 +934,8 @@ PHPAPI int redis_sock_read_multibulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, R
926
934
{
927
935
char inbuf [1024 ], * response ;
928
936
int response_len ;
937
+ int i , numElems ;
938
+ zval * z_multi_result ;
929
939
930
940
zval * * z_keys = ctx ;
931
941
@@ -944,8 +954,7 @@ PHPAPI int redis_sock_read_multibulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, R
944
954
if (inbuf [0 ] != '*' ) {
945
955
return -1 ;
946
956
}
947
- int i , numElems = atoi (inbuf + 1 );
948
- zval * z_multi_result ;
957
+ numElems = atoi (inbuf + 1 );
949
958
MAKE_STD_ZVAL (z_multi_result );
950
959
array_init (z_multi_result ); /* pre-allocate array for multi's results. */
951
960
@@ -1122,12 +1131,15 @@ redis_unserialize(RedisSock *redis_sock, const char *val, int val_len, zval **re
1122
1131
1123
1132
PHPAPI int
1124
1133
redis_key_prefix (RedisSock * redis_sock , char * * key , int * key_len TSRMLS_DC ) {
1134
+ int ret_len ;
1135
+ char * ret ;
1136
+
1125
1137
if (redis_sock -> prefix == NULL || redis_sock -> prefix_len == 0 ) {
1126
1138
return 0 ;
1127
1139
}
1128
1140
1129
- int ret_len = redis_sock -> prefix_len + * key_len ;
1130
- char * ret = ecalloc (1 + ret_len , 1 );
1141
+ ret_len = redis_sock -> prefix_len + * key_len ;
1142
+ ret = ecalloc (1 + ret_len , 1 );
1131
1143
memcpy (ret , redis_sock -> prefix , redis_sock -> prefix_len );
1132
1144
memcpy (ret + redis_sock -> prefix_len , * key , * key_len );
1133
1145
0 commit comments