diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-04-29 09:58:11 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-04-29 09:58:11 +0200 |
commit | 0f8192a8fc2329141b6222315dd5712a132a647e (patch) | |
tree | 7914e09d5015064f8f55f0a5b65337c2c437d342 /src | |
parent | make struct tcp_server opaque (diff) | |
download | cimple-0f8192a8fc2329141b6222315dd5712a132a647e.tar.gz cimple-0f8192a8fc2329141b6222315dd5712a132a647e.zip |
make struct server opaque
Diffstat (limited to 'src')
-rw-r--r-- | src/server.c | 30 | ||||
-rw-r--r-- | src/server.h | 15 | ||||
-rw-r--r-- | src/server_main.c | 6 |
3 files changed, 32 insertions, 19 deletions
diff --git a/src/server.c b/src/server.c index 933a3b7..f35b781 100644 --- a/src/server.c +++ b/src/server.c @@ -20,15 +20,36 @@ #include <stdlib.h> #include <string.h> -int server_create(struct server *server, const struct settings *settings) +struct server { + pthread_mutex_t server_mtx; + pthread_cond_t server_cv; + + int stopping; + + struct storage storage; + + struct tcp_server *tcp_server; + + struct ci_queue ci_queue; +}; + +int server_create(struct server **_server, const struct settings *settings) { + struct server *server; struct storage_settings storage_settings; int ret = 0; + *_server = malloc(sizeof(struct server)); + if (!*_server) { + log_errno("malloc"); + return -1; + } + server = *_server; + ret = pthread_mutex_init(&server->server_mtx, NULL); if (ret) { pthread_errno(ret, "pthread_mutex_init"); - goto fail; + goto free; } ret = pthread_cond_init(&server->server_cv, NULL); @@ -65,7 +86,9 @@ destroy_cv: destroy_mtx: pthread_errno_if(pthread_mutex_destroy(&server->server_mtx), "pthread_mutex_destroy"); -fail: +free: + free(server); + return ret; } @@ -78,6 +101,7 @@ void server_destroy(struct server *server) storage_destroy(&server->storage); pthread_errno_if(pthread_cond_destroy(&server->server_cv), "pthread_cond_destroy"); pthread_errno_if(pthread_mutex_destroy(&server->server_mtx), "pthread_mutex_destroy"); + free(server); } static int server_has_runs(const struct server *server) diff --git a/src/server.h b/src/server.h index 0e5c030..9c96db2 100644 --- a/src/server.h +++ b/src/server.h @@ -20,20 +20,9 @@ struct settings { const char *sqlite_path; }; -struct server { - pthread_mutex_t server_mtx; - pthread_cond_t server_cv; +struct server; - int stopping; - - struct storage storage; - - struct tcp_server *tcp_server; - - struct ci_queue ci_queue; -}; - -int server_create(struct server *, const struct settings *); +int server_create(struct server **, const struct settings *); void server_destroy(struct server *); int server_main(struct server *); diff --git a/src/server_main.c b/src/server_main.c index 3d77ec8..4295b2d 100644 --- a/src/server_main.c +++ b/src/server_main.c @@ -87,7 +87,7 @@ static int parse_settings(struct settings *settings, int argc, char *argv[]) int main(int argc, char *argv[]) { struct settings settings; - struct server server; + struct server *server; int ret = 0; ret = parse_settings(&settings, argc, argv); @@ -98,12 +98,12 @@ int main(int argc, char *argv[]) if (ret < 0) return ret; - ret = server_main(&server); + ret = server_main(server); if (ret < 0) goto destroy_server; destroy_server: - server_destroy(&server); + server_destroy(server); return ret; } |