From 32706b6275c9ada6617bde1ad5b5bc6451bc3ada Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Wed, 10 May 2023 20:29:14 +0800 Subject: [PATCH] add function sf_socket_close --- src/sf_service.c | 13 +++++++++++++ src/sf_service.h | 3 +++ 2 files changed, 16 insertions(+) diff --git a/src/sf_service.c b/src/sf_service.c index d74ebf6..e844ac1 100644 --- a/src/sf_service.c +++ b/src/sf_service.c @@ -400,6 +400,19 @@ int sf_socket_server_ex(SFContext *sf_context) return 0; } +void sf_socket_close_ex(SFContext *sf_context) +{ + if (sf_context->inner_sock >= 0) { + close(sf_context->inner_sock); + sf_context->inner_sock = -1; + } + + if (sf_context->outer_sock >= 0) { + close(sf_context->outer_sock); + sf_context->outer_sock = -1; + } +} + static void accept_run(struct accept_thread_context *accept_context) { int incomesock; diff --git a/src/sf_service.h b/src/sf_service.h index a49bd97..8008485 100644 --- a/src/sf_service.h +++ b/src/sf_service.h @@ -86,6 +86,9 @@ void sf_set_current_time(); int sf_socket_server_ex(SFContext *sf_context); #define sf_socket_server() sf_socket_server_ex(&g_sf_context) +void sf_socket_close_ex(SFContext *sf_context); +#define sf_socket_close() sf_socket_close_ex(&g_sf_context) + void sf_accept_loop_ex(SFContext *sf_context, const bool block); #define sf_accept_loop() sf_accept_loop_ex(&g_sf_context, true)