Skip to content

Commit 29055a3

Browse files
committed
Merge branch '1.9'
2 parents e8c111e + 8af4679 commit 29055a3

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

include/Client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,6 @@ typedef struct
150150
} swDNSResolver_result;
151151

152152
int swDNSResolver_request(char *domain, void (*callback)(char *, swDNSResolver_result *, void *), void *data);
153+
int swDNSResolver_free();
153154

154155
#endif /* SW_CLIENT_H_ */

include/hashmap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ int swHashMap_move_int(swHashMap *hmap, uint64_t old_key, uint64_t new_key);
4646
void* swHashMap_each(swHashMap* hmap, char **key);
4747
void* swHashMap_each_int(swHashMap* hmap, uint64_t *key);
4848
#define swHashMap_each_reset(hmap) (hmap->iterator = NULL)
49+
uint32_t swHashMap_count(swHashMap* hmap);
4950

5051
#ifdef __cplusplus
5152
}

src/core/hashmap.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,15 @@ void* swHashMap_each_int(swHashMap* hmap, uint64_t *key)
358358
}
359359
}
360360

361+
uint32_t swHashMap_count(swHashMap* hmap)
362+
{
363+
if (hmap == NULL)
364+
{
365+
return 0;
366+
}
367+
return HASH_COUNT(hmap->root);
368+
}
369+
361370
void swHashMap_free(swHashMap* hmap)
362371
{
363372
swHashMap_node *find, *tmp = NULL;

src/network/DNS.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,32 @@ int swDNSResolver_request(char *domain, void (*callback)(char *, swDNSResolver_r
395395
return SW_OK;
396396
}
397397

398+
int swDNSResolver_free()
399+
{
400+
if (resolver_socket == NULL)
401+
{
402+
return SW_ERR;
403+
}
404+
if (SwooleG.main_reactor == NULL)
405+
{
406+
return SW_ERR;
407+
}
408+
if (swHashMap_count(request_map) > 0)
409+
{
410+
return SW_ERR;
411+
}
412+
413+
SwooleG.main_reactor->del(SwooleG.main_reactor, resolver_socket->socket->fd);
414+
resolver_socket->close(resolver_socket);
415+
swClient_free(resolver_socket);
416+
sw_free(resolver_socket);
417+
resolver_socket = NULL;
418+
swHashMap_free(request_map);
419+
request_map = NULL;
420+
421+
return SW_OK;
422+
}
423+
398424
/**
399425
* The function converts the dot-based hostname into the DNS format
400426
* (i.e. www.apple.com into 3www5apple3com0)

src/network/Worker.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,8 @@ void swWorker_try_to_exit()
475475
swAio_free();
476476
}
477477

478+
swDNSResolver_free();
479+
478480
uint8_t call_worker_exit_func = 0;
479481

480482
while (1)

0 commit comments

Comments
 (0)