14
14
15
15
#include "utils.h"
16
16
17
- int __tarantool_authenticate (tarantool_connection * obj );
17
+ static int __tarantool_authenticate (tarantool_connection * obj );
18
+ static void tarantool_stream_close (tarantool_connection * obj );
18
19
19
20
double
20
21
now_gettimeofday (void )
@@ -128,11 +129,12 @@ PHP_INI_END()
128
129
ZEND_GET_MODULE (tarantool )
129
130
#endif
130
131
131
- static int
132
+ inline static int
132
133
tarantool_stream_send (tarantool_connection * obj TSRMLS_DC ) {
133
134
int rv = tntll_stream_send (obj -> stream , SSTR_BEG (obj -> value ),
134
135
SSTR_LEN (obj -> value ));
135
136
if (rv < 0 ) {
137
+ tarantool_stream_close (obj );
136
138
tarantool_throw_ioexception ("Failed to send message" );
137
139
return FAILURE ;
138
140
}
@@ -218,10 +220,11 @@ static zend_string *pid_pzsgen(const char *host, int port, const char *login,
218
220
* Legacy rtsisyk code, php_stream_read made right
219
221
* See https://bugs.launchpad.net/tarantool/+bug/1182474
220
222
*/
221
- static size_t
223
+ inline static int
222
224
tarantool_stream_read (tarantool_connection * obj , char * buf , size_t size ) {
223
225
size_t got = tntll_stream_read2 (obj -> stream , buf , size );
224
226
if (got != size ) {
227
+ tarantool_stream_close (obj );
225
228
tarantool_throw_ioexception ("Failed to read %ld bytes" , size );
226
229
return FAILURE ;
227
230
}
@@ -240,7 +243,7 @@ tarantool_stream_close(tarantool_connection *obj) {
240
243
}
241
244
}
242
245
243
- int __tarantool_connect (tarantool_object * t_obj ) {
246
+ static int __tarantool_connect (tarantool_object * t_obj ) {
244
247
TSRMLS_FETCH ();
245
248
tarantool_connection * obj = t_obj -> obj ;
246
249
int status = SUCCESS ;
@@ -284,7 +287,7 @@ int __tarantool_connect(tarantool_object *t_obj) {
284
287
continue ;
285
288
}
286
289
if (tntll_stream_read2 (obj -> stream , obj -> greeting ,
287
- GREETING_SIZE ) == -1 ) {
290
+ GREETING_SIZE ) != GREETING_SIZE ) {
288
291
continue ;
289
292
}
290
293
if (php_tp_verify_greetings (obj -> greeting ) == 0 ) {
@@ -306,7 +309,7 @@ int __tarantool_connect(tarantool_object *t_obj) {
306
309
return status ;
307
310
}
308
311
309
- int __tarantool_reconnect (tarantool_object * t_obj ) {
312
+ inline static int __tarantool_reconnect (tarantool_object * t_obj ) {
310
313
tarantool_stream_close (t_obj -> obj );
311
314
return __tarantool_connect (t_obj );
312
315
}
@@ -391,54 +394,42 @@ static zend_object *tarantool_create(zend_class_entry *entry) {
391
394
return & obj -> zo ;
392
395
}
393
396
394
- static int64_t tarantool_step_recv (
397
+ static int tarantool_step_recv (
395
398
tarantool_connection * obj ,
396
399
unsigned long sync ,
397
400
zval * header ,
398
401
zval * body ) {
399
402
char pack_len [5 ] = {0 , 0 , 0 , 0 , 0 };
400
403
if (tarantool_stream_read (obj , pack_len , 5 ) == FAILURE ) {
401
- header = NULL ;
402
- body = NULL ;
403
- goto error_con ;
404
+ goto error ;
404
405
}
405
406
if (php_mp_check (pack_len , 5 )) {
406
- header = NULL ;
407
- body = NULL ;
408
407
tarantool_throw_parsingexception ("package length" );
409
408
goto error_con ;
410
409
}
411
410
size_t body_size = php_mp_unpack_package_size (pack_len );
412
411
smart_string_ensure (obj -> value , body_size );
413
412
if (tarantool_stream_read (obj , SSTR_POS (obj -> value ),
414
413
body_size ) == FAILURE ) {
415
- header = NULL ;
416
- body = NULL ;
417
414
goto error ;
418
415
}
419
416
SSTR_LEN (obj -> value ) += body_size ;
420
417
421
418
char * pos = SSTR_BEG (obj -> value );
422
419
if (php_mp_check (pos , body_size )) {
423
- header = NULL ;
424
- body = NULL ;
425
420
tarantool_throw_parsingexception ("package header" );
426
- goto error ;
421
+ goto error_con ;
427
422
}
428
423
if (php_mp_unpack (header , & pos ) == FAILURE ||
429
424
Z_TYPE_P (header ) != IS_ARRAY ) {
430
- header = NULL ;
431
- body = NULL ;
432
- goto error ;
425
+ goto error_con ;
433
426
}
434
427
if (php_mp_check (pos , body_size )) {
435
- body = NULL ;
436
428
tarantool_throw_parsingexception ("package body" );
437
429
goto error_con ;
438
430
}
439
431
if (php_mp_unpack (body , & pos ) == FAILURE ) {
440
- body = NULL ;
441
- goto error ;
432
+ goto error_con ;
442
433
}
443
434
444
435
HashTable * hash = HASH_OF (header );
@@ -488,7 +479,6 @@ static int64_t tarantool_step_recv(
488
479
tarantool_throw_exception ("Failed to retrieve answer code" );
489
480
error_con :
490
481
tarantool_stream_close (obj );
491
- obj -> stream = NULL ;
492
482
error :
493
483
if (header ) zval_ptr_dtor (header );
494
484
if (body ) zval_ptr_dtor (body );
@@ -1174,7 +1164,7 @@ PHP_METHOD(Tarantool, reconnect) {
1174
1164
RETURN_TRUE ;
1175
1165
}
1176
1166
1177
- int __tarantool_authenticate (tarantool_connection * obj ) {
1167
+ static int __tarantool_authenticate (tarantool_connection * obj ) {
1178
1168
TSRMLS_FETCH ();
1179
1169
1180
1170
tarantool_schema_flush (obj -> schema );
0 commit comments