@@ -29,6 +29,14 @@ PHPAPI void redis_stream_close(RedisSock *redis_sock TSRMLS_DC) {
29
29
}
30
30
}
31
31
32
+ PHPAPI void redis_throw_exception (RedisSock * redis_sock , zend_class_entry * ce , char * msg , int code TSRMLS_DC ) {
33
+
34
+ if (redis_sock && redis_sock -> nothrow )
35
+ return ;
36
+
37
+ zend_throw_exception (ce , msg , code TSRMLS_CC );
38
+ }
39
+
32
40
PHPAPI int redis_check_eof (RedisSock * redis_sock TSRMLS_DC )
33
41
{
34
42
int eof ;
@@ -47,7 +55,7 @@ PHPAPI int redis_check_eof(RedisSock *redis_sock TSRMLS_DC)
47
55
redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
48
56
redis_sock -> watching = 0 ;
49
57
}
50
- zend_throw_exception ( redis_exception_ce , "Connection lost" , 0 TSRMLS_CC );
58
+ redis_throw_exception ( redis_sock , redis_exception_ce , "Connection lost" , 0 TSRMLS_CC );
51
59
return -1 ;
52
60
}
53
61
if (redis_sock -> stream ) { /* close existing stream before reconnecting */
@@ -104,7 +112,7 @@ PHPAPI zval *redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAMETERS,
104
112
redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
105
113
redis_sock -> mode = ATOMIC ;
106
114
redis_sock -> watching = 0 ;
107
- zend_throw_exception ( redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
115
+ redis_throw_exception ( redis_sock , redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
108
116
return NULL ;
109
117
}
110
118
@@ -147,7 +155,7 @@ PHPAPI char *redis_sock_read_bulk_reply(RedisSock *redis_sock, int bytes TSRMLS_
147
155
got = php_stream_read (redis_sock -> stream , reply + offset , bytes - offset );
148
156
if (got <= 0 ) {
149
157
/* Error or EOF */
150
- zend_throw_exception ( redis_exception_ce , "socket error on read socket" , 0 TSRMLS_CC );
158
+ redis_throw_exception ( redis_sock , redis_exception_ce , "socket error on read socket" , 0 TSRMLS_CC );
151
159
break ;
152
160
}
153
161
offset += got ;
@@ -179,15 +187,15 @@ PHPAPI char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC)
179
187
redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
180
188
redis_sock -> mode = ATOMIC ;
181
189
redis_sock -> watching = 0 ;
182
- zend_throw_exception ( redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
190
+ redis_throw_exception ( redis_sock , redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
183
191
return NULL ;
184
192
}
185
193
186
194
switch (inbuf [0 ]) {
187
195
case '-' :
188
196
/* stale data */
189
197
if (memcmp (inbuf + 1 , "-ERR SYNC " , 10 ) == 0 ) {
190
- zend_throw_exception ( redis_exception_ce , "SYNC with master in progress" , 0 TSRMLS_CC );
198
+ redis_throw_exception ( redis_sock , redis_exception_ce , "SYNC with master in progress" , 0 TSRMLS_CC );
191
199
}
192
200
return NULL ;
193
201
@@ -687,7 +695,7 @@ PHPAPI int redis_sock_read_multibulk_reply_zipped_with_flag(INTERNAL_FUNCTION_PA
687
695
redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
688
696
redis_sock -> mode = ATOMIC ;
689
697
redis_sock -> watching = 0 ;
690
- zend_throw_exception ( redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
698
+ redis_throw_exception ( redis_sock , redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
691
699
return -1 ;
692
700
}
693
701
@@ -1051,7 +1059,7 @@ PHPAPI int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSo
1051
1059
redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
1052
1060
redis_sock -> mode = ATOMIC ;
1053
1061
redis_sock -> watching = 0 ;
1054
- zend_throw_exception ( redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
1062
+ redis_throw_exception ( redis_sock , redis_exception_ce , "read err
F438
or on connection" , 0 TSRMLS_CC );
1055
1063
return -1 ;
1056
1064
}
1057
1065
@@ -1093,7 +1101,7 @@ PHPAPI int redis_sock_read_multibulk_reply_raw(INTERNAL_FUNCTION_PARAMETERS, Red
1093
1101
redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
1094
1102
redis_sock -> mode = ATOMIC ;
1095
1103
redis_sock -> watching = 0 ;
1096
- zend_throw_exception ( redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
1104
+ redis_throw_exception ( redis_sock , redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
1097
1105
return -1 ;
1098
1106
}
1099
1107
@@ -1167,7 +1175,7 @@ PHPAPI int redis_sock_read_multibulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, R
1167
1175
redis_sock -> status = REDIS_SOCK_STATUS_FAILED ;
1168
1176
redis_sock -> mode = ATOMIC ;
1169
1177
redis_sock -> watching = 0 ;
1170
- zend_throw_exception ( redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
1178
+ redis_throw_exception ( redis_sock , redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
1171
1179
return -1 ;
1172
1180
}
1173
1181
@@ -1214,7 +1222,7 @@ PHPAPI int redis_sock_read_multibulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, R
1214
1222
PHPAPI int redis_sock_write (RedisSock * redis_sock , char * cmd , size_t sz TSRMLS_DC )
1215
1223
{
1216
1224
if (redis_sock && redis_sock -> status == REDIS_SOCK_STATUS_DISCONNECTED ) {
1217
- zend_throw_exception ( redis_exception_ce , "Connection closed" , 0 TSRMLS_CC );
1225
+ redis_throw_exception ( redis_sock , redis_exception_ce , "Connection closed" , 0 TSRMLS_CC );
1218
1226
return -1 ;
1219
1227
}
1220
1228
if (-1 == redis_check_eof (redis_sock TSRMLS_CC )) {
@@ -1399,7 +1407,7 @@ redis_sock_gets(RedisSock *redis_sock, char *buf, int buf_size, size_t *line_siz
1399
1407
redis_sock -> watching = 0 ;
1400
1408
1401
1409
// Throw a read error exception
1402
- zend_throw_exception ( redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
1410
+ redis_throw_exception ( redis_sock , redis_exception_ce , "read error on connection" , 0 TSRMLS_CC );
1403
1411
}
1404
1412
1405
1413
// We don't need \r\n
@@ -1421,7 +1429,7 @@ redis_read_reply_type(RedisSock *redis_sock, REDIS_REPLY_TYPE *reply_type, int *
1421
1429
1422
1430
// Attempt to read the reply-type byte
1423
1431
if ((* reply_type = php_stream_getc (redis_sock -> stream )) == EOF ) {
1424
- zend_throw_exception ( redis_exception_ce , "socket error on read socket" , 0 TSRMLS_CC );
1432
+ redis_throw_exception ( redis_sock , redis_exception_ce , "socket error on read socket" , 0 TSRMLS_CC );
1425
1433
}
1426
1434
1427
1435
// If this is a BULK, MULTI BULK, or simply an INTEGER response, we can extract the value or size info here
@@ -1459,7 +1467,7 @@ redis_read_variant_line(RedisSock *redis_sock, REDIS_REPLY_TYPE reply_type, zval
1459
1467
// If this is an error response, check if it is a SYNC error, and throw in that case
1460
1468
if (reply_type == TYPE_ERR ) {
1461
1469
if (memcmp (inbuf , "ERR SYNC" , 9 ) == 0 ) {
1462
- zend_throw_exception ( redis_exception_ce , "SYNC with master in progress" , 0 TSRMLS_CC );
1470
+ redis_throw_exception ( redis_sock , redis_exception_ce , "SYNC with master in progress" , 0 TSRMLS_CC );
1463
1471
}
1464
1472
1465
1473
// Set our last error
0 commit comments