From bfaf56c9d1541780de320741ce1241a4e48e10e1 Mon Sep 17 00:00:00 2001 From: none Date: Mon, 23 Oct 2017 23:03:15 +0300 Subject: [PATCH] Method for closing all persistent connections at once --- src/php_tarantool.h | 1 + src/tarantool.c | 16 ++++++++++++++++ src/tarantool_proto.h | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/php_tarantool.h b/src/php_tarantool.h index 5591120..715d3ca 100644 --- a/src/php_tarantool.h +++ b/src/php_tarantool.h @@ -79,6 +79,7 @@ PHP_METHOD(Tarantool, delete); PHP_METHOD(Tarantool, update); PHP_METHOD(Tarantool, upsert); PHP_METHOD(Tarantool, flush_schema); +PHP_METHOD(Tarantool, close_all); ZEND_BEGIN_MODULE_GLOBALS(tarantool) zend_bool persistent; diff --git a/src/tarantool.c b/src/tarantool.c index 4121018..a8d051f 100644 --- a/src/tarantool.c +++ b/src/tarantool.c @@ -562,7 +562,9 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_tarantool_upsert, 0, 0, 3) ZEND_END_ARG_INFO() #define TNT_MEP(name, args) PHP_ME (Tarantool, name, args, ZEND_ACC_PUBLIC) +#define TNT_MES(name, args) PHP_ME (Tarantool, name, args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) #define TNT_MAP(alias, name, args) PHP_MALIAS(Tarantool, alias, name, args, ZEND_ACC_PUBLIC) +#define TNT_MAS(alias, name, args) PHP_MALIAS(Tarantool, alias, name, args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) const zend_function_entry Tarantool_methods[] = { TNT_MEP(__construct, arginfo_tarantool_construct ) TNT_MEP(connect, arginfo_tarantool_void ) @@ -582,10 +584,14 @@ const zend_function_entry Tarantool_methods[] = { TNT_MAP(evaluate, eval, arginfo_tarantool_proc_tuple ) TNT_MAP(flushSchema, flush_schema, arginfo_tarantool_void ) TNT_MAP(disconnect, close, arginfo_tarantool_void ) + TNT_MES(close_all, arginfo_tarantool_void ) + TNT_MAS(closeAll, close_all, arginfo_tarantool_void ) {NULL, NULL, NULL} }; #undef TNT_MEP +#undef TNT_MES #undef TNT_MAP +#undef TNT_MAS /* ####################### HELPERS ####################### */ @@ -1283,6 +1289,16 @@ PHP_METHOD(Tarantool, close) { RETURN_TRUE; } +PHP_METHOD(Tarantool, close_all) { + zval *zle; + + ZEND_HASH_FOREACH_VAL(&EG(persistent_list), zle) { + if (Z_RES_TYPE_P(zle) == php_tarantool_list_entry()) { + tarantool_stream_close((tarantool_connection *) Z_RES_VAL_P(zle)); + } + } ZEND_HASH_FOREACH_END(); +} + PHP_METHOD(Tarantool, ping) { TARANTOOL_FUNCTION_BEGIN(obj, id, ""); TARANTOOL_CONNECT_ON_DEMAND(obj); diff --git a/src/tarantool_proto.h b/src/tarantool_proto.h index 8470923..a7abebc 100644 --- a/src/tarantool_proto.h +++ b/src/tarantool_proto.h @@ -17,7 +17,7 @@ #include -#include +#include "php_tarantool.h" /** * Pack version into uint32_t.