From 00c7936e1fb6969b41d1cc6b86f1d42537011072 Mon Sep 17 00:00:00 2001 From: fumiama Date: Fri, 17 Dec 2021 14:48:29 +0800 Subject: [PATCH] reduce mem use --- dict.c | 4 ++++ dict.h | 1 + server.c | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/dict.c b/dict.c index 75e645d..9e55982 100644 --- a/dict.c +++ b/dict.c @@ -90,6 +90,10 @@ FILE* get_dict_fp(uint32_t index) { else return NULL; } +FILE* get_unique_dict_fp() { + return fp5; +} + void close_dict(uint8_t lock_type, uint32_t index) { puts("Close dict"); lock &= ~lock_type; diff --git a/dict.h b/dict.h index 33268b3..6c20248 100644 --- a/dict.h +++ b/dict.h @@ -21,6 +21,7 @@ void close_dict(uint8_t lock_type, uint32_t index); int fill_md5(); FILE* get_dict_fp(uint32_t index); off_t get_dict_size(); +FILE* get_unique_dict_fp(); int is_md5_equal(uint8_t* digest); FILE *open_dict(uint8_t lock_type, uint32_t index); diff --git a/server.c b/server.c index efe1cfb..f24fbfb 100644 --- a/server.c +++ b/server.c @@ -550,6 +550,7 @@ static void accept_client() { pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, 1); init_crypto(); + init_dict_pool(get_unique_dict_fp()); if(pid < 0) puts("Error when forking a subprocess."); else while(1) { puts("Ready for accept, waitting..."); @@ -612,7 +613,6 @@ int main(int argc, char *argv[]) { fp = fopen(argv[as_daemon?4:3], "rb+"); if(!fp) fp = fopen(argv[as_daemon?4:3], "wb+"); if(fp) { - init_dict_pool(fp); fclose(fp); if(init_dict(argv[as_daemon?4:3])) { fp = NULL;