1 Star 0 Fork 32

hantwofish/gazelle_1

forked from src-openEuler/gazelle 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0285-suport-kernel-accept-for-openGauss.patch 2.72 KB
一键复制 编辑 原始数据 按行查看 历史
yinbin6 提交于 2024-11-15 19:22 . sync suport kernel accept for openGauss
From be28f36adfebb0e5f7f2340638120a19f5b2eaa6 Mon Sep 17 00:00:00 2001
From: hankangkang <hankangkang5@huawei.com>
Date: Thu, 14 Nov 2024 20:16:14 +0800
Subject: [PATCH] suport kernel accept for openGauss
---
src/lstack/api/lstack_wrap.c | 34 ++++++++++++++++++++++++++++++----
1 file changed, 30 insertions(+), 4 deletions(-)
diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c
index 66cea51..6ab31f6 100644
--- a/src/lstack/api/lstack_wrap.c
+++ b/src/lstack/api/lstack_wrap.c
@@ -14,6 +14,7 @@
#include <ifaddrs.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
+#include <fcntl.h>
#include <linux/if_xdp.h>
#include <lwip/lwipgz_posix_api.h>
@@ -102,14 +103,22 @@ static inline int32_t do_accept(int32_t s, struct sockaddr *addr, socklen_t *add
return posix_api->accept_fn(s, addr, addrlen);
}
- int32_t fd = g_wrap_api->accept_fn(s, addr, addrlen);
+ int fd = 0;
+ struct lwip_sock *sock = lwip_get_socket(s);
+ if (POSIX_HAS_TYPE(sock, POSIX_KERNEL)) {
+ fd = posix_api->accept4_fn(s, addr, addrlen, SOCK_NONBLOCK);
+ if (fd >= 0) {
+ return fd;
+ }
+ }
+
+ fd = g_wrap_api->accept_fn(s, addr, addrlen);
if (fd >= 0) {
- struct lwip_sock *sock = lwip_get_socket(fd);
+ sock = lwip_get_socket(fd);
POSIX_SET_TYPE(sock, POSIX_LWIP);
- return fd;
}
- return posix_api->accept_fn(s, addr, addrlen);
+ return fd;
}
static int32_t do_accept4(int32_t s, struct sockaddr *addr, socklen_t *addrlen, int32_t flags)
@@ -132,6 +141,22 @@ static int32_t do_accept4(int32_t s, struct sockaddr *addr, socklen_t *addrlen,
return posix_api->accept4_fn(s, addr, addrlen, flags);
}
+static inline int sock_set_nonblocking(int fd)
+{
+ int flags = posix_api->fcntl_fn(fd, F_GETFL, 0);
+ if (flags == -1) {
+ LSTACK_LOG(ERR, LSTACK, " get block status faild errno %d.\n", errno);
+ return -1;
+ }
+ // set nonblock
+ flags |= O_NONBLOCK;
+ if (posix_api->fcntl_fn(fd, F_SETFL, flags) == -1) {
+ LSTACK_LOG(ERR, LSTACK, " set non_block status faild errno %d.\n", errno);
+ return -1;
+ }
+ return 0;
+}
+
static int kernel_bind_process(int32_t s, const struct sockaddr *name, socklen_t namelen)
{
struct lwip_sock *sock = lwip_get_socket(s);
@@ -165,6 +190,7 @@ static int kernel_bind_process(int32_t s, const struct sockaddr *name, socklen_t
((struct sockaddr_in *)name)->sin_port = kerneladdr.sin_port;
}
/* not sure POSIX_LWIP or POSIX_KERNEL */
+ sock_set_nonblocking(s);
} else {
POSIX_SET_TYPE(sock, POSIX_LWIP);
LSTACK_LOG(ERR, LSTACK, "kernel bind failed ret %d errno %d sa_family %u times %u\n",
--
2.33.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hantwofish/gazelle_1.git
git@gitee.com:hantwofish/gazelle_1.git
hantwofish
gazelle_1
gazelle_1
master

搜索帮助