Skip to content

Commit b71428d

Browse files
committed
use swoole hashmap.
1 parent 84c86e3 commit b71428d

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

php_swoole.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ extern zend_class_entry *swoole_http_server_class_entry_ptr;
168168

169169
extern zval *php_sw_callback[PHP_SERVER_CALLBACK_NUM];
170170

171-
extern HashTable php_sw_long_connections;
172-
173171
#define PHP_MEMORY_DEBUG 0
174172

175173
#if PHP_MEMORY_DEBUG

swoole_client.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static const zend_function_entry swoole_client_methods[] =
7474
PHP_FE_END
7575
};
7676

77-
HashTable php_sw_long_connections;
77+
static swHashMap *php_sw_long_connections;
7878

7979
zend_class_entry swoole_client_ce;
8080
zend_class_entry *swoole_client_class_entry_ptr;
@@ -87,7 +87,7 @@ void swoole_client_init(int module_number TSRMLS_DC)
8787
zend_declare_property_long(swoole_client_class_entry_ptr, SW_STRL("errCode")-1, 0, ZEND_ACC_PUBLIC TSRMLS_CC);
8888
zend_declare_property_long(swoole_client_class_entry_ptr, SW_STRL("sock")-1, 0, ZEND_ACC_PUBLIC TSRMLS_CC);
8989

90-
zend_hash_init(&php_sw_long_connections, 16, NULL, ZVAL_PTR_DTOR, 1);
90+
php_sw_long_connections = swHashMap_new(SW_HASHMAP_INIT_BUCKET_N, NULL);
9191
}
9292

9393
/**
@@ -114,11 +114,12 @@ static int client_close(zval *zobject, int fd TSRMLS_DC)
114114
}
115115
else if (Z_LVAL_P(ztype) & SW_FLAG_KEEP)
116116
{
117-
if (sw_zend_hash_del(&php_sw_long_connections, cli->server_str, cli->server_strlen) == SUCCESS)
117+
if (swHashMap_del(php_sw_long_connections, cli->server_str, cli->server_strlen))
118118
{
119119
swoole_php_fatal_error(E_WARNING, "delete from hashtable failed.");
120120
}
121121
sw_free(cli->server_str);
122+
pefree(cli, 1);
122123
ZVAL_LONG(ztype, 0);
123124
}
124125
else
@@ -805,12 +806,11 @@ static swClient* client_create_socket(zval *object, char *host, int host_len, in
805806
//keep the tcp connection
806807
if (type & SW_FLAG_KEEP)
807808
{
808-
swClient *find;
809-
810-
if (sw_zend_hash_find(&php_sw_long_connections, conn_key, conn_key_len, (void **) &find) == FAILURE)
809+
swClient *find = swHashMap_find(php_sw_long_connections, conn_key, conn_key_len);
810+
if (find == NULL)
811811
{
812812
cli = (swClient*) pemalloc(sizeof(swClient), 1);
813-
if (sw_zend_hash_update(&php_sw_long_connections, conn_key, conn_key_len, (void*)cli, sizeof(cli), NULL) == FAILURE)
813+
if (swHashMap_add(php_sw_long_connections, conn_key, conn_key_len, cli, NULL) == FAILURE)
814814
{
815815
swoole_php_fatal_error(E_WARNING, "swoole_client_create_socket add to hashtable failed.");
816816
}

0 commit comments

Comments
 (0)