From cba42b0ca25bed62c946a4d902deb82ce0ca74e9 Mon Sep 17 00:00:00 2001
From: jiangheng <jiangheng14@huawei.com>
Date: Sat, 2 Mar 2024 13:44:20 +0800
Subject: [PATCH] rtc: adapt rtc_close

---
 src/lstack/api/lstack_epoll.c   |  4 +++-
 src/lstack/api/lstack_rtc_api.c | 12 +++++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/lstack/api/lstack_epoll.c b/src/lstack/api/lstack_epoll.c
index 7dbef9d..6ae0eec 100644
--- a/src/lstack/api/lstack_epoll.c
+++ b/src/lstack/api/lstack_epoll.c
@@ -322,7 +322,9 @@ int32_t lstack_epoll_close(int32_t fd)
 
     wakeup->type = WAKEUP_CLOSE;
 
-    stack_broadcast_clean_epoll(wakeup);
+    if (!get_global_cfg_params()->stack_mode_rtc) {
+        stack_broadcast_clean_epoll(wakeup);
+    }
 
     struct list_node *node, *temp;
     pthread_spin_lock(&wakeup->event_list_lock);
diff --git a/src/lstack/api/lstack_rtc_api.c b/src/lstack/api/lstack_rtc_api.c
index 2e10e30..18664ca 100644
--- a/src/lstack/api/lstack_rtc_api.c
+++ b/src/lstack/api/lstack_rtc_api.c
@@ -63,7 +63,17 @@ int rtc_socket(int domain, int type, int protocol)
 
 int rtc_close(int s)
 {
-    return lwip_close(s);
+    struct lwip_sock *sock = get_socket(s);
+    if (sock != NULL && sock->wakeup != NULL && sock->wakeup->epollfd == s) {
+        return lstack_epoll_close(s);
+    }
+
+    lwip_close(s);
+    if (sock != NULL) {
+        list_del_node_null(&sock->event_list);
+    }
+
+    return posix_api->close_fn(s);
 }
 
 int rtc_shutdown(int fd, int how)
-- 
2.33.0

