@@ -74,7 +74,7 @@ static const zend_function_entry swoole_client_methods[] =
74
74
PHP_FE_END
75
75
};
76
76
77
- HashTable php_sw_long_connections ;
77
+ static swHashMap * php_sw_long_connections ;
78
78
79
79
zend_class_entry swoole_client_ce ;
80
80
zend_class_entry * swoole_client_class_entry_ptr ;
@@ -87,7 +87,7 @@ void swoole_client_init(int module_number TSRMLS_DC)
87
87
zend_declare_property_long (swoole_client_class_entry_ptr , SW_STRL ("errCode" )- 1 , 0 , ZEND_ACC_PUBLIC TSRMLS_CC );
88
88
zend_declare_property_long (swoole_client_class_entry_ptr , SW_STRL ("sock" )- 1 , 0 , ZEND_ACC_PUBLIC TSRMLS_CC );
89
89
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 );
91
91
}
92
92
93
93
/**
@@ -114,11 +114,12 @@ static int client_close(zval *zobject, int fd TSRMLS_DC)
114
114
}
115
115
else if (Z_LVAL_P (ztype ) & SW_FLAG_KEEP )
116
116
{
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 ))
118
118
{
119
119
swoole_php_fatal_error (E_WARNING , "delete from hashtable failed." );
120
120
}
121
121
sw_free (cli -> server_str );
122
+ pefree (cli , 1 );
122
123
ZVAL_LONG (ztype , 0 );
123
124
}
124
125
else
@@ -805,12 +806,11 @@ static swClient* client_create_socket(zval *object, char *host, int host_len, in
805
806
//keep the tcp connection
806
807
if (type & SW_FLAG_KEEP )
807
808
{
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 )
811
811
{
812
812
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 )
814
814
{
815
815
swoole_php_fatal_error (E_WARNING , "swoole_client_create_socket add to hashtable failed." );
816
816
}
0 commit comments