summaryrefslogtreecommitdiff
path: root/main2.c
diff options
context:
space:
mode:
authorfadhil riyanto <me@fadev.org>2024-10-08 13:00:38 +0700
committerfadhil riyanto <me@fadev.org>2024-10-08 13:00:38 +0700
commit1a59e5a4858971b5ceb2c1f7f831e3f119826015 (patch)
tree6145b9c36e721ae20740ed18553171453b3b43fb /main2.c
parent991f86dde715961048dba28b757b66071fc7500d (diff)
fix cpu burst due unjoined thread
Signed-off-by: fadhil riyanto <me@fadev.org>
Diffstat (limited to 'main2.c')
-rw-r--r--main2.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/main2.c b/main2.c
index c4c5911..e6582f5 100644
--- a/main2.c
+++ b/main2.c
@@ -903,8 +903,7 @@ static void* start_exchange_data2_client2srv(void *fd_bridgeptr)
_start_exchange_data2_epfd_install(fd_bridge, fd_bridge->client_fd);
while (1) {
- printf("receiving\n");
-
+ // dbg("client2srv")
event_ret = epoll_wait(fd_bridge->fd_bridge_epfd, fd_bridge->events,
THREAD_MAX_QUEUE_EVENTS, 1000);
@@ -921,6 +920,8 @@ static void* start_exchange_data2_client2srv(void *fd_bridgeptr)
_start_exchange_data2_epfd_uninstall(fd_bridgeptr,
fd_bridge->events[i].data.fd);
+
+ fd_bridge->need_exit = 1;
pthread_exit(&client_ret);
}
@@ -951,7 +952,7 @@ static void* start_exchange_data2_srv2client(void *fd_bridgeptr)
_start_exchange_data2_epfd_install(fd_bridge, fd_bridge->target_fd);
while (1) {
-
+ // dbg("srv2client")
event_ret = epoll_wait(fd_bridge->fd_bridge_epfd, fd_bridge->events,
THREAD_MAX_QUEUE_EVENTS, 1000);
@@ -961,13 +962,16 @@ static void* start_exchange_data2_srv2client(void *fd_bridgeptr)
memset(buf, 0, 4096);
srv_ret = recv(fd_bridge->events[i].data.fd, buf, 4096, 0);
-
+ // printf("srv2clie %d\n", srv_ret);
if (srv_ret == 0) {
log_warn("srv ret is zero, closing connection");
close(fd_bridge->events[i].data.fd);
_start_exchange_data2_epfd_uninstall(fd_bridgeptr,
fd_bridge->events[i].data.fd);
+
+ fd_bridge->need_exit = 1;
+
pthread_exit(&client_ret);
}
if (srv_ret == -1) {
@@ -1008,10 +1012,13 @@ static int start_exchange_data2(int client_fd, int target_fd)
pthread_create(&fd_bridge.srv2client_pthread,
0, start_exchange_data2_srv2client, (void*)&fd_bridge);
- while (!(fd_bridge.need_exit == 1)) {
+ while (fd_bridge.need_exit != 1) {
printf("eh_eventloop running\n");
sleep(1);
}
+
+ pthread_join(fd_bridge.client2srv_pthread, NULL);
+ pthread_join(fd_bridge.srv2client_pthread, NULL);
pthread_mutex_destroy(&fd_bridge.mutex);
close(fd_bridge.fd_bridge_epfd);