1195972f6Sopenharmony_ciFrom 1f0f3742019e2fa62ba1669c5a880fb63a3fee12 Mon Sep 17 00:00:00 2001 2195972f6Sopenharmony_ciFrom: jiangheng <jiangheng12@huawei.com> 3195972f6Sopenharmony_ciDate: Thu, 24 Feb 2022 20:08:46 +0800 4195972f6Sopenharmony_ciSubject: [PATCH] lstack support mysql mode 5195972f6Sopenharmony_ci 6195972f6Sopenharmony_ci--- 7195972f6Sopenharmony_ci src/api/api_msg.c | 26 +-- 8195972f6Sopenharmony_ci src/api/posix_api.c | 5 +- 9195972f6Sopenharmony_ci src/api/sockets.c | 350 ++----------------------------- 10195972f6Sopenharmony_ci src/api/sys_arch.c | 12 +- 11195972f6Sopenharmony_ci src/core/tcp_out.c | 13 ++ 12195972f6Sopenharmony_ci src/include/eventpoll.h | 6 +- 13195972f6Sopenharmony_ci src/include/lwip/priv/tcp_priv.h | 2 +- 14195972f6Sopenharmony_ci src/include/lwip/sockets.h | 2 +- 15195972f6Sopenharmony_ci src/include/lwipsock.h | 29 ++- 16195972f6Sopenharmony_ci src/include/posix_api.h | 2 +- 17195972f6Sopenharmony_ci src/include/reg_sock.h | 8 +- 18195972f6Sopenharmony_ci 11 files changed, 85 insertions(+), 370 deletions(-) 19195972f6Sopenharmony_ci 20195972f6Sopenharmony_cidiff --git a/src/api/api_msg.c b/src/api/api_msg.c 21195972f6Sopenharmony_ciindex d5a738f..3072dd9 100644 22195972f6Sopenharmony_ci--- a/src/api/api_msg.c 23195972f6Sopenharmony_ci+++ b/src/api/api_msg.c 24195972f6Sopenharmony_ci@@ -342,6 +342,12 @@ recv_tcp(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) 25195972f6Sopenharmony_ci #endif /* LWIP_SO_RCVBUF */ 26195972f6Sopenharmony_ci /* Register event with callback */ 27195972f6Sopenharmony_ci API_EVENT(conn, NETCONN_EVT_RCVPLUS, len); 28195972f6Sopenharmony_ci+#if USE_LIBOS 29195972f6Sopenharmony_ci+ if (conn->state == NETCONN_WRITE || conn->state == NETCONN_CLOSE || 30195972f6Sopenharmony_ci+ conn->state == NETCONN_CONNECT) { 31195972f6Sopenharmony_ci+ add_recv_list(conn->socket); 32195972f6Sopenharmony_ci+ } 33195972f6Sopenharmony_ci+#endif 34195972f6Sopenharmony_ci } 35195972f6Sopenharmony_ci 36195972f6Sopenharmony_ci return ERR_OK; 37195972f6Sopenharmony_ci@@ -457,14 +463,6 @@ err_tcp(void *arg, err_t err) 38195972f6Sopenharmony_ci old_state = conn->state; 39195972f6Sopenharmony_ci conn->state = NETCONN_NONE; 40195972f6Sopenharmony_ci 41195972f6Sopenharmony_ci-#if USE_LIBOS 42195972f6Sopenharmony_ci- if (CONN_TYPE_IS_HOST(conn)) { 43195972f6Sopenharmony_ci- LWIP_DEBUGF(API_MSG_DEBUG, 44195972f6Sopenharmony_ci- ("linux localhost connection already success, ignore lwip err_tcp fd=%d\n", conn->socket)); 45195972f6Sopenharmony_ci- return; 46195972f6Sopenharmony_ci- } 47195972f6Sopenharmony_ci-#endif /* USE_LIBOS */ 48195972f6Sopenharmony_ci- 49195972f6Sopenharmony_ci SYS_ARCH_UNPROTECT(lev); 50195972f6Sopenharmony_ci 51195972f6Sopenharmony_ci /* Notify the user layer about a connection error. Used to signal select. */ 52195972f6Sopenharmony_ci@@ -479,6 +477,12 @@ err_tcp(void *arg, err_t err) 53195972f6Sopenharmony_ci if (NETCONN_MBOX_VALID(conn, &conn->recvmbox)) { 54195972f6Sopenharmony_ci /* use trypost to prevent deadlock */ 55195972f6Sopenharmony_ci sys_mbox_trypost(&conn->recvmbox, mbox_msg); 56195972f6Sopenharmony_ci+#if USE_LIBOS 57195972f6Sopenharmony_ci+ if ((old_state == NETCONN_WRITE) || (old_state == NETCONN_CLOSE) || 58195972f6Sopenharmony_ci+ (old_state == NETCONN_CONNECT)) { 59195972f6Sopenharmony_ci+ add_recv_list(conn->socket); 60195972f6Sopenharmony_ci+ } 61195972f6Sopenharmony_ci+#endif 62195972f6Sopenharmony_ci } 63195972f6Sopenharmony_ci /* pass error message to acceptmbox to wake up pending accept */ 64195972f6Sopenharmony_ci if (NETCONN_MBOX_VALID(conn, &conn->acceptmbox)) { 65195972f6Sopenharmony_ci@@ -1344,11 +1348,7 @@ lwip_netconn_do_connected(void *arg, struct tcp_pcb *pcb, err_t err) 66195972f6Sopenharmony_ci int s = conn->socket; 67195972f6Sopenharmony_ci struct lwip_sock *sock = get_socket_without_errno(s); 68195972f6Sopenharmony_ci 69195972f6Sopenharmony_ci- if (!!sock && !!sock->epoll_data) { 70195972f6Sopenharmony_ci- struct epoll_event ee = {0}; 71195972f6Sopenharmony_ci- ee.data.fd = s; 72195972f6Sopenharmony_ci- ee.events |= EPOLLIN | EPOLLOUT | EPOLLERR; 73195972f6Sopenharmony_ci- posix_api->epoll_ctl_fn(sock->epoll_data->fd, EPOLL_CTL_DEL, s, &ee); 74195972f6Sopenharmony_ci+ if (!!sock) { 75195972f6Sopenharmony_ci posix_api->shutdown_fn(s, SHUT_RDWR); 76195972f6Sopenharmony_ci LWIP_DEBUGF(API_MSG_DEBUG, 77195972f6Sopenharmony_ci ("linux outgoing connection abort fd=%d\n", s)); 78195972f6Sopenharmony_cidiff --git a/src/api/posix_api.c b/src/api/posix_api.c 79195972f6Sopenharmony_ciindex a917cea..eff9f46 100644 80195972f6Sopenharmony_ci--- a/src/api/posix_api.c 81195972f6Sopenharmony_ci+++ b/src/api/posix_api.c 82195972f6Sopenharmony_ci@@ -143,11 +143,10 @@ int posix_api_init(void) 83195972f6Sopenharmony_ci 84195972f6Sopenharmony_ci /* lstack helper api */ 85195972f6Sopenharmony_ci posix_api->get_socket = get_socket; 86195972f6Sopenharmony_ci- posix_api->is_epfd = lwip_is_epfd; 87195972f6Sopenharmony_ci- posix_api->epoll_close_fn = lwip_epoll_close; 88195972f6Sopenharmony_ci+ posix_api->epoll_close_fn = lstack_epoll_close; 89195972f6Sopenharmony_ci 90195972f6Sopenharmony_ci /* support fork */ 91195972f6Sopenharmony_ci- posix_api->is_chld = 0; 92195972f6Sopenharmony_ci+ posix_api->is_chld = 1; 93195972f6Sopenharmony_ci return ERR_OK; 94195972f6Sopenharmony_ci 95195972f6Sopenharmony_ci err_out: 96195972f6Sopenharmony_cidiff --git a/src/api/sockets.c b/src/api/sockets.c 97195972f6Sopenharmony_ciindex f44c34f..b032ce9 100644 98195972f6Sopenharmony_ci--- a/src/api/sockets.c 99195972f6Sopenharmony_ci+++ b/src/api/sockets.c 100195972f6Sopenharmony_ci@@ -90,14 +90,6 @@ 101195972f6Sopenharmony_ci #define API_SELECT_CB_VAR_ALLOC(name, retblock) API_VAR_ALLOC_EXT(struct lwip_select_cb, MEMP_SELECT_CB, name, retblock) 102195972f6Sopenharmony_ci #define API_SELECT_CB_VAR_FREE(name) API_VAR_FREE(MEMP_SELECT_CB, name) 103195972f6Sopenharmony_ci 104195972f6Sopenharmony_ci-#if USE_LIBOS 105195972f6Sopenharmony_ci-enum KERNEL_LWIP_PATH { 106195972f6Sopenharmony_ci- PATH_KERNEL = 0, 107195972f6Sopenharmony_ci- PATH_LWIP, 108195972f6Sopenharmony_ci- PATH_ERR, 109195972f6Sopenharmony_ci-}; 110195972f6Sopenharmony_ci-#endif 111195972f6Sopenharmony_ci- 112195972f6Sopenharmony_ci #if LWIP_IPV4 113195972f6Sopenharmony_ci #if USE_LIBOS 114195972f6Sopenharmony_ci #define IP4ADDR_PORT_TO_SOCKADDR(sin, ipaddr, port) do { \ 115195972f6Sopenharmony_ci@@ -604,8 +596,6 @@ alloc_socket(struct netconn *newconn, int accepted) 116195972f6Sopenharmony_ci * (unless it has been created by accept()). */ 117195972f6Sopenharmony_ci sockets[i].sendevent = (NETCONNTYPE_GROUP(newconn->type) == NETCONN_TCP ? (accepted != 0) : 1); 118195972f6Sopenharmony_ci sockets[i].errevent = 0; 119195972f6Sopenharmony_ci- sockets[i].epoll_data = NULL; 120195972f6Sopenharmony_ci- init_list_node_null(&sockets[i].list); 121195972f6Sopenharmony_ci return i + LWIP_SOCKET_OFFSET; 122195972f6Sopenharmony_ci } 123195972f6Sopenharmony_ci 124195972f6Sopenharmony_ci@@ -714,13 +704,6 @@ free_socket(struct lwip_sock *sock, int is_tcp) 125195972f6Sopenharmony_ci /* Protect socket array */ 126195972f6Sopenharmony_ci SYS_ARCH_PROTECT(lev); 127195972f6Sopenharmony_ci 128195972f6Sopenharmony_ci-#if USE_LIBOS 129195972f6Sopenharmony_ci- sock->epoll = LIBOS_EPOLLNONE; 130195972f6Sopenharmony_ci- sock->events = 0; 131195972f6Sopenharmony_ci- sock->epoll_data = NULL; 132195972f6Sopenharmony_ci- list_del_node_null(&sock->list); 133195972f6Sopenharmony_ci-#endif 134195972f6Sopenharmony_ci- 135195972f6Sopenharmony_ci freed = free_socket_locked(sock, is_tcp, &conn, &lastdata); 136195972f6Sopenharmony_ci SYS_ARCH_UNPROTECT(lev); 137195972f6Sopenharmony_ci /* don't use 'sock' after this line, as another task might have allocated it */ 138195972f6Sopenharmony_ci@@ -749,34 +732,11 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen) 139195972f6Sopenharmony_ci SYS_ARCH_DECL_PROTECT(lev); 140195972f6Sopenharmony_ci 141195972f6Sopenharmony_ci LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d)...\n", s)); 142195972f6Sopenharmony_ci-#if USE_LIBOS 143195972f6Sopenharmony_ci- int sys_errno = 0; 144195972f6Sopenharmony_ci- 145195972f6Sopenharmony_ci- sock = posix_api->get_socket(s); 146195972f6Sopenharmony_ci- /*AF_UNIX case*/ 147195972f6Sopenharmony_ci- if (!sock) { 148195972f6Sopenharmony_ci- return posix_api->accept_fn(s, addr, addrlen); 149195972f6Sopenharmony_ci- } 150195972f6Sopenharmony_ci- 151195972f6Sopenharmony_ci- /*for AF_INET, we may try both linux and lwip*/ 152195972f6Sopenharmony_ci- if (!CONN_TYPE_HAS_LIBOS_AND_HOST(sock->conn)) { 153195972f6Sopenharmony_ci- LWIP_DEBUGF(SOCKETS_DEBUG, ("conn->type has libos and host bits")); 154195972f6Sopenharmony_ci- set_errno(EINVAL); 155195972f6Sopenharmony_ci- return -1; 156195972f6Sopenharmony_ci- } 157195972f6Sopenharmony_ci- 158195972f6Sopenharmony_ci- /* raise accept syscall in palce */ 159195972f6Sopenharmony_ci- newsock = posix_api->accept_fn(s, addr, addrlen); 160195972f6Sopenharmony_ci- if (newsock >= 0) { 161195972f6Sopenharmony_ci- return newsock; 162195972f6Sopenharmony_ci- } 163195972f6Sopenharmony_ci- sys_errno = errno; 164195972f6Sopenharmony_ci-#else 165195972f6Sopenharmony_ci+ 166195972f6Sopenharmony_ci sock = get_socket(s); 167195972f6Sopenharmony_ci if (!sock) { 168195972f6Sopenharmony_ci return -1; 169195972f6Sopenharmony_ci } 170195972f6Sopenharmony_ci-#endif 171195972f6Sopenharmony_ci 172195972f6Sopenharmony_ci /* wait for a new connection */ 173195972f6Sopenharmony_ci err = netconn_accept(sock->conn, &newconn); 174195972f6Sopenharmony_ci@@ -790,9 +750,6 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen) 175195972f6Sopenharmony_ci sock_set_errno(sock, err_to_errno(err)); 176195972f6Sopenharmony_ci } 177195972f6Sopenharmony_ci done_socket(sock); 178195972f6Sopenharmony_ci-#if USE_LIBOS 179195972f6Sopenharmony_ci- set_errno(sys_errno); 180195972f6Sopenharmony_ci-#endif /* USE_LIBOS */ 181195972f6Sopenharmony_ci return -1; 182195972f6Sopenharmony_ci } 183195972f6Sopenharmony_ci LWIP_ASSERT("newconn != NULL", newconn != NULL); 184195972f6Sopenharmony_ci@@ -875,24 +832,11 @@ lwip_bind(int s, const struct sockaddr *name, socklen_t namelen) 185195972f6Sopenharmony_ci ip_addr_t local_addr; 186195972f6Sopenharmony_ci u16_t local_port; 187195972f6Sopenharmony_ci err_t err; 188195972f6Sopenharmony_ci-#if USE_LIBOS 189195972f6Sopenharmony_ci- sock = posix_api->get_socket(s); 190195972f6Sopenharmony_ci- /*AF_UNIX case*/ 191195972f6Sopenharmony_ci- if (!sock) { 192195972f6Sopenharmony_ci- return posix_api->bind_fn(s, name, namelen); 193195972f6Sopenharmony_ci- } 194195972f6Sopenharmony_ci- /*for AF_INET, we may try both linux and lwip*/ 195195972f6Sopenharmony_ci- if (!CONN_TYPE_HAS_LIBOS_AND_HOST(sock->conn)) { 196195972f6Sopenharmony_ci- LWIP_DEBUGF(SOCKETS_DEBUG, ("conn->type has libos and host bits")); 197195972f6Sopenharmony_ci- set_errno(EINVAL); 198195972f6Sopenharmony_ci- return -1; 199195972f6Sopenharmony_ci- } 200195972f6Sopenharmony_ci-#else 201195972f6Sopenharmony_ci+ 202195972f6Sopenharmony_ci sock = get_socket(s); 203195972f6Sopenharmony_ci if (!sock) { 204195972f6Sopenharmony_ci return -1; 205195972f6Sopenharmony_ci } 206195972f6Sopenharmony_ci-#endif 207195972f6Sopenharmony_ci 208195972f6Sopenharmony_ci if (!SOCK_ADDR_TYPE_MATCH(name, sock)) { 209195972f6Sopenharmony_ci /* sockaddr does not match socket type (IPv4/IPv6) */ 210195972f6Sopenharmony_ci@@ -912,18 +856,6 @@ lwip_bind(int s, const struct sockaddr *name, socklen_t namelen) 211195972f6Sopenharmony_ci ip_addr_debug_print_val(SOCKETS_DEBUG, local_addr); 212195972f6Sopenharmony_ci LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F")\n", local_port)); 213195972f6Sopenharmony_ci 214195972f6Sopenharmony_ci-#if USE_LIBOS 215195972f6Sopenharmony_ci- /* Supports kernel NIC IP address. */ 216195972f6Sopenharmony_ci- int ret = posix_api->bind_fn(s, name, namelen); 217195972f6Sopenharmony_ci- if (ret < 0) { 218195972f6Sopenharmony_ci- LWIP_DEBUGF(SOCKETS_DEBUG, ("bind syscall failed\n")); 219195972f6Sopenharmony_ci- /* bind must succeed on both linux and libos */ 220195972f6Sopenharmony_ci- if (!is_host_ipv4(local_addr.addr)) { 221195972f6Sopenharmony_ci- return ret; 222195972f6Sopenharmony_ci- } 223195972f6Sopenharmony_ci- } 224195972f6Sopenharmony_ci-#endif /* USE_LIBOS */ 225195972f6Sopenharmony_ci- 226195972f6Sopenharmony_ci #if LWIP_IPV4 && LWIP_IPV6 227195972f6Sopenharmony_ci /* Dual-stack: Unmap IPv4 mapped IPv6 addresses */ 228195972f6Sopenharmony_ci if (IP_IS_V6_VAL(local_addr) && ip6_addr_isipv4mappedipv6(ip_2_ip6(&local_addr))) { 229195972f6Sopenharmony_ci@@ -953,32 +885,13 @@ lwip_close(int s) 230195972f6Sopenharmony_ci struct lwip_sock *sock; 231195972f6Sopenharmony_ci int is_tcp = 0; 232195972f6Sopenharmony_ci err_t err; 233195972f6Sopenharmony_ci- int ret = 0; 234195972f6Sopenharmony_ci 235195972f6Sopenharmony_ci LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_close(%d)\n", s)); 236195972f6Sopenharmony_ci 237195972f6Sopenharmony_ci-#if USE_LIBOS 238195972f6Sopenharmony_ci- if (posix_api->is_epfd(s)) { 239195972f6Sopenharmony_ci- return posix_api->epoll_close_fn(s); 240195972f6Sopenharmony_ci- } 241195972f6Sopenharmony_ci- 242195972f6Sopenharmony_ci- /* No matter what the result of close, lwip_sock resources should release 243195972f6Sopenharmony_ci- * to prevent the potential double freee problem caused by reporting events after the close */ 244195972f6Sopenharmony_ci- ret = posix_api->close_fn(s); 245195972f6Sopenharmony_ci- if ((ret < 0) && (errno == EINTR)) 246195972f6Sopenharmony_ci- ret = posix_api->close_fn(s); 247195972f6Sopenharmony_ci- 248195972f6Sopenharmony_ci- sock = posix_api->get_socket(s); 249195972f6Sopenharmony_ci- /*AF_UNIX case*/ 250195972f6Sopenharmony_ci- if (!sock) { 251195972f6Sopenharmony_ci- return ret; 252195972f6Sopenharmony_ci- } 253195972f6Sopenharmony_ci-#else 254195972f6Sopenharmony_ci sock = get_socket(s); 255195972f6Sopenharmony_ci if (!sock) { 256195972f6Sopenharmony_ci return -1; 257195972f6Sopenharmony_ci } 258195972f6Sopenharmony_ci-#endif /* USE_LIBOS */ 259195972f6Sopenharmony_ci 260195972f6Sopenharmony_ci if (sock->conn != NULL) { 261195972f6Sopenharmony_ci is_tcp = NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP; 262195972f6Sopenharmony_ci@@ -1004,7 +917,7 @@ lwip_close(int s) 263195972f6Sopenharmony_ci 264195972f6Sopenharmony_ci free_socket(sock, is_tcp); 265195972f6Sopenharmony_ci set_errno(0); 266195972f6Sopenharmony_ci- return ret; 267195972f6Sopenharmony_ci+ return 0; 268195972f6Sopenharmony_ci } 269195972f6Sopenharmony_ci 270195972f6Sopenharmony_ci int 271195972f6Sopenharmony_ci@@ -1013,28 +926,10 @@ lwip_connect(int s, const struct sockaddr *name, socklen_t namelen) 272195972f6Sopenharmony_ci struct lwip_sock *sock; 273195972f6Sopenharmony_ci err_t err; 274195972f6Sopenharmony_ci 275195972f6Sopenharmony_ci-#if USE_LIBOS 276195972f6Sopenharmony_ci- int ret; 277195972f6Sopenharmony_ci- 278195972f6Sopenharmony_ci- sock = posix_api->get_socket(s); 279195972f6Sopenharmony_ci- if (!sock) { 280195972f6Sopenharmony_ci- return posix_api->connect_fn(s, name, namelen); 281195972f6Sopenharmony_ci- } 282195972f6Sopenharmony_ci- 283195972f6Sopenharmony_ci- /* raise connect syscall in place */ 284195972f6Sopenharmony_ci- ADD_CONN_TYPE_INPRG(sock->conn); 285195972f6Sopenharmony_ci- ret = posix_api->connect_fn(s, name, namelen); 286195972f6Sopenharmony_ci- if (!ret) { 287195972f6Sopenharmony_ci- SET_CONN_TYPE_HOST(sock->conn); 288195972f6Sopenharmony_ci- LWIP_DEBUGF(SOCKETS_DEBUG, ("linux connect succeed fd=%d\n", s)); 289195972f6Sopenharmony_ci- return ret; 290195972f6Sopenharmony_ci- } 291195972f6Sopenharmony_ci-#else 292195972f6Sopenharmony_ci sock = get_socket(s); 293195972f6Sopenharmony_ci if (!sock) { 294195972f6Sopenharmony_ci return -1; 295195972f6Sopenharmony_ci } 296195972f6Sopenharmony_ci-#endif 297195972f6Sopenharmony_ci 298195972f6Sopenharmony_ci if (!SOCK_ADDR_TYPE_MATCH_OR_UNSPEC(name, sock)) { 299195972f6Sopenharmony_ci /* sockaddr does not match socket type (IPv4/IPv6) */ 300195972f6Sopenharmony_ci@@ -1106,29 +1001,10 @@ lwip_listen(int s, int backlog) 301195972f6Sopenharmony_ci 302195972f6Sopenharmony_ci LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_listen(%d, backlog=%d)\n", s, backlog)); 303195972f6Sopenharmony_ci 304195972f6Sopenharmony_ci-#if USE_LIBOS 305195972f6Sopenharmony_ci- int ret; 306195972f6Sopenharmony_ci- 307195972f6Sopenharmony_ci- sock = posix_api->get_socket(s); 308195972f6Sopenharmony_ci- /*AF_UNIX case*/ 309195972f6Sopenharmony_ci- if (!sock) { 310195972f6Sopenharmony_ci- return posix_api->listen_fn(s, backlog); 311195972f6Sopenharmony_ci- } 312195972f6Sopenharmony_ci- /*for AF_INET, we may try both linux and lwip*/ 313195972f6Sopenharmony_ci- if (!CONN_TYPE_HAS_LIBOS_AND_HOST(sock->conn)) { 314195972f6Sopenharmony_ci- LWIP_DEBUGF(SOCKETS_DEBUG, ("conn->type has libos and host bits")); 315195972f6Sopenharmony_ci- set_errno(EADDRINUSE); 316195972f6Sopenharmony_ci- return -1; 317195972f6Sopenharmony_ci- } 318195972f6Sopenharmony_ci- 319195972f6Sopenharmony_ci- if ((ret = posix_api->listen_fn(s, backlog)) == -1) 320195972f6Sopenharmony_ci- return ret; 321195972f6Sopenharmony_ci-#else 322195972f6Sopenharmony_ci sock = get_socket(s); 323195972f6Sopenharmony_ci if (!sock) { 324195972f6Sopenharmony_ci return -1; 325195972f6Sopenharmony_ci } 326195972f6Sopenharmony_ci-#endif 327195972f6Sopenharmony_ci 328195972f6Sopenharmony_ci /* limit the "backlog" parameter to fit in an u8_t */ 329195972f6Sopenharmony_ci backlog = LWIP_MIN(LWIP_MAX(backlog, 0), 0xff); 330195972f6Sopenharmony_ci@@ -1160,11 +1036,12 @@ static ssize_t 331195972f6Sopenharmony_ci lwip_recv_tcp(struct lwip_sock *sock, void *mem, size_t len, int flags) 332195972f6Sopenharmony_ci { 333195972f6Sopenharmony_ci u8_t apiflags = NETCONN_NOAUTORCVD; 334195972f6Sopenharmony_ci+ ssize_t recvd = 0; 335195972f6Sopenharmony_ci #if USE_LIBOS 336195972f6Sopenharmony_ci apiflags = 0; 337195972f6Sopenharmony_ci-#endif 338195972f6Sopenharmony_ci- ssize_t recvd = 0; 339195972f6Sopenharmony_ci+#else 340195972f6Sopenharmony_ci ssize_t recv_left = (len <= SSIZE_MAX) ? (ssize_t)len : SSIZE_MAX; 341195972f6Sopenharmony_ci+#endif 342195972f6Sopenharmony_ci 343195972f6Sopenharmony_ci LWIP_ASSERT("no socket given", sock != NULL); 344195972f6Sopenharmony_ci LWIP_ASSERT("this should be checked internally", NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP); 345195972f6Sopenharmony_ci@@ -1173,6 +1050,7 @@ lwip_recv_tcp(struct lwip_sock *sock, void *mem, size_t len, int flags) 346195972f6Sopenharmony_ci apiflags |= NETCONN_DONTBLOCK; 347195972f6Sopenharmony_ci } 348195972f6Sopenharmony_ci 349195972f6Sopenharmony_ci+#if !USE_LIBOS 350195972f6Sopenharmony_ci do { 351195972f6Sopenharmony_ci struct pbuf *p; 352195972f6Sopenharmony_ci err_t err; 353195972f6Sopenharmony_ci@@ -1182,13 +1060,6 @@ lwip_recv_tcp(struct lwip_sock *sock, void *mem, size_t len, int flags) 354195972f6Sopenharmony_ci /* Check if there is data left from the last recv operation. */ 355195972f6Sopenharmony_ci if (sock->lastdata.pbuf) { 356195972f6Sopenharmony_ci p = sock->lastdata.pbuf; 357195972f6Sopenharmony_ci-#if USE_LIBOS 358195972f6Sopenharmony_ci- if (((flags & MSG_PEEK) == 0) && ((sock->epoll & EPOLLET) == 0)) { 359195972f6Sopenharmony_ci- if ((NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP)) { 360195972f6Sopenharmony_ci- del_epoll_event(sock->conn, EPOLLIN); 361195972f6Sopenharmony_ci- } 362195972f6Sopenharmony_ci- } 363195972f6Sopenharmony_ci-#endif 364195972f6Sopenharmony_ci } else { 365195972f6Sopenharmony_ci /* No data was left from the previous operation, so we try to get 366195972f6Sopenharmony_ci some from the network. */ 367195972f6Sopenharmony_ci@@ -1258,23 +1129,21 @@ lwip_recv_tcp(struct lwip_sock *sock, void *mem, size_t len, int flags) 368195972f6Sopenharmony_ci apiflags |= NETCONN_DONTBLOCK | NETCONN_NOFIN; 369195972f6Sopenharmony_ci /* @todo: do we need to support peeking more than one pbuf? */ 370195972f6Sopenharmony_ci } while ((recv_left > 0) && !(flags & MSG_PEEK)); 371195972f6Sopenharmony_ci+ 372195972f6Sopenharmony_ci lwip_recv_tcp_done: 373195972f6Sopenharmony_ci-#if USE_LIBOS 374195972f6Sopenharmony_ci- if (apiflags & NETCONN_NOAUTORCVD) 375195972f6Sopenharmony_ci-#endif 376195972f6Sopenharmony_ci- { 377195972f6Sopenharmony_ci+#else /* USE_LIBOS */ 378195972f6Sopenharmony_ci+ recvd = read_lwip_data(sock, flags, apiflags); 379195972f6Sopenharmony_ci+ if (recvd <= 0) { 380195972f6Sopenharmony_ci+ return recvd; 381195972f6Sopenharmony_ci+ } 382195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 383195972f6Sopenharmony_ci+ if (apiflags & NETCONN_NOAUTORCVD) { 384195972f6Sopenharmony_ci if ((recvd > 0) && !(flags & MSG_PEEK)) { 385195972f6Sopenharmony_ci /* ensure window update after copying all data */ 386195972f6Sopenharmony_ci netconn_tcp_recvd(sock->conn, (size_t)recvd); 387195972f6Sopenharmony_ci } 388195972f6Sopenharmony_ci } 389195972f6Sopenharmony_ci-#if USE_LIBOS 390195972f6Sopenharmony_ci- if ((flags & MSG_PEEK) == 0) { 391195972f6Sopenharmony_ci- if (((NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP)) && sock->lastdata.pbuf) { 392195972f6Sopenharmony_ci- add_epoll_event(sock->conn, EPOLLIN); 393195972f6Sopenharmony_ci- } 394195972f6Sopenharmony_ci- } 395195972f6Sopenharmony_ci-#endif 396195972f6Sopenharmony_ci+ 397195972f6Sopenharmony_ci sock_set_errno(sock, 0); 398195972f6Sopenharmony_ci return recvd; 399195972f6Sopenharmony_ci } 400195972f6Sopenharmony_ci@@ -1461,37 +1330,6 @@ lwip_recvfrom_udp_raw(struct lwip_sock *sock, int flags, struct msghdr *msg, u16 401195972f6Sopenharmony_ci return ERR_OK; 402195972f6Sopenharmony_ci } 403195972f6Sopenharmony_ci 404195972f6Sopenharmony_ci-#if USE_LIBOS 405195972f6Sopenharmony_ci-static inline enum KERNEL_LWIP_PATH select_path(int s) 406195972f6Sopenharmony_ci-{ 407195972f6Sopenharmony_ci- struct lwip_sock *sock; 408195972f6Sopenharmony_ci- 409195972f6Sopenharmony_ci- sock = posix_api->get_socket(s); 410195972f6Sopenharmony_ci- /*AF_UNIX case*/ 411195972f6Sopenharmony_ci- if (!sock) { 412195972f6Sopenharmony_ci- return PATH_KERNEL; 413195972f6Sopenharmony_ci- } 414195972f6Sopenharmony_ci- 415195972f6Sopenharmony_ci- if (CONN_TYPE_HAS_INPRG(sock->conn)) { 416195972f6Sopenharmony_ci- set_errno(EWOULDBLOCK); 417195972f6Sopenharmony_ci- return PATH_ERR; 418195972f6Sopenharmony_ci- } 419195972f6Sopenharmony_ci- 420195972f6Sopenharmony_ci- /*for AF_INET, we can try erther linux or lwip*/ 421195972f6Sopenharmony_ci- if (CONN_TYPE_IS_HOST(sock->conn)) { 422195972f6Sopenharmony_ci- return PATH_KERNEL; 423195972f6Sopenharmony_ci- } 424195972f6Sopenharmony_ci- 425195972f6Sopenharmony_ci- if (!CONN_TYPE_IS_LIBOS(sock->conn)) { 426195972f6Sopenharmony_ci- LWIP_DEBUGF(SOCKETS_DEBUG, ("conn->type is not libos bit type=%x", netconn_type(sock->conn))); 427195972f6Sopenharmony_ci- set_errno(EINVAL); 428195972f6Sopenharmony_ci- return PATH_ERR; 429195972f6Sopenharmony_ci- } 430195972f6Sopenharmony_ci- 431195972f6Sopenharmony_ci- return PATH_LWIP; 432195972f6Sopenharmony_ci-} 433195972f6Sopenharmony_ci-#endif 434195972f6Sopenharmony_ci- 435195972f6Sopenharmony_ci ssize_t 436195972f6Sopenharmony_ci lwip_recvfrom(int s, void *mem, size_t len, int flags, 437195972f6Sopenharmony_ci struct sockaddr *from, socklen_t *fromlen) 438195972f6Sopenharmony_ci@@ -1499,15 +1337,6 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags, 439195972f6Sopenharmony_ci struct lwip_sock *sock; 440195972f6Sopenharmony_ci ssize_t ret; 441195972f6Sopenharmony_ci 442195972f6Sopenharmony_ci-#if USE_LIBOS 443195972f6Sopenharmony_ci- enum KERNEL_LWIP_PATH path = select_path(s); 444195972f6Sopenharmony_ci- if (path == PATH_ERR) { 445195972f6Sopenharmony_ci- return -1; 446195972f6Sopenharmony_ci- } else if (path == PATH_KERNEL) { 447195972f6Sopenharmony_ci- return posix_api->recv_from(s, mem, len, flags, from, fromlen); 448195972f6Sopenharmony_ci- } 449195972f6Sopenharmony_ci-#endif 450195972f6Sopenharmony_ci- 451195972f6Sopenharmony_ci LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d, %p, %"SZT_F", 0x%x, ..)\n", s, mem, len, flags)); 452195972f6Sopenharmony_ci sock = get_socket(s); 453195972f6Sopenharmony_ci if (!sock) { 454195972f6Sopenharmony_ci@@ -1557,14 +1386,6 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags, 455195972f6Sopenharmony_ci ssize_t 456195972f6Sopenharmony_ci lwip_read(int s, void *mem, size_t len) 457195972f6Sopenharmony_ci { 458195972f6Sopenharmony_ci-#if USE_LIBOS 459195972f6Sopenharmony_ci- enum KERNEL_LWIP_PATH path = select_path(s); 460195972f6Sopenharmony_ci- if (path == PATH_ERR) { 461195972f6Sopenharmony_ci- return -1; 462195972f6Sopenharmony_ci- } else if (path == PATH_KERNEL) { 463195972f6Sopenharmony_ci- return posix_api->read_fn(s, mem, len); 464195972f6Sopenharmony_ci- } 465195972f6Sopenharmony_ci-#endif 466195972f6Sopenharmony_ci return lwip_recvfrom(s, mem, len, 0, NULL, NULL); 467195972f6Sopenharmony_ci } 468195972f6Sopenharmony_ci 469195972f6Sopenharmony_ci@@ -1598,15 +1419,6 @@ lwip_recvmsg(int s, struct msghdr *message, int flags) 470195972f6Sopenharmony_ci int i; 471195972f6Sopenharmony_ci ssize_t buflen; 472195972f6Sopenharmony_ci 473195972f6Sopenharmony_ci-#if USE_LIBOS 474195972f6Sopenharmony_ci- enum KERNEL_LWIP_PATH path = select_path(s); 475195972f6Sopenharmony_ci- if (path == PATH_ERR) { 476195972f6Sopenharmony_ci- return -1; 477195972f6Sopenharmony_ci- } else if (path == PATH_KERNEL) { 478195972f6Sopenharmony_ci- return posix_api->recv_msg(s, message, flags); 479195972f6Sopenharmony_ci- } 480195972f6Sopenharmony_ci-#endif 481195972f6Sopenharmony_ci- 482195972f6Sopenharmony_ci LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvmsg(%d, message=%p, flags=0x%x)\n", s, (void *)message, flags)); 483195972f6Sopenharmony_ci LWIP_ERROR("lwip_recvmsg: invalid message pointer", message != NULL, return ERR_ARG;); 484195972f6Sopenharmony_ci LWIP_ERROR("lwip_recvmsg: unsupported flags", (flags & ~(MSG_PEEK|MSG_DONTWAIT)) == 0, 485195972f6Sopenharmony_ci@@ -1751,15 +1563,6 @@ lwip_sendmsg(int s, const struct msghdr *msg, int flags) 486195972f6Sopenharmony_ci #endif 487195972f6Sopenharmony_ci err_t err = ERR_OK; 488195972f6Sopenharmony_ci 489195972f6Sopenharmony_ci-#if USE_LIBOS 490195972f6Sopenharmony_ci- enum KERNEL_LWIP_PATH path = select_path(s); 491195972f6Sopenharmony_ci- if (path == PATH_ERR) { 492195972f6Sopenharmony_ci- return -1; 493195972f6Sopenharmony_ci- } else if (path == PATH_KERNEL) { 494195972f6Sopenharmony_ci- return posix_api->send_msg(s, msg, flags); 495195972f6Sopenharmony_ci- } 496195972f6Sopenharmony_ci-#endif 497195972f6Sopenharmony_ci- 498195972f6Sopenharmony_ci sock = get_socket(s); 499195972f6Sopenharmony_ci if (!sock) { 500195972f6Sopenharmony_ci return -1; 501195972f6Sopenharmony_ci@@ -1923,15 +1726,6 @@ lwip_sendto(int s, const void *data, size_t size, int flags, 502195972f6Sopenharmony_ci u16_t remote_port; 503195972f6Sopenharmony_ci struct netbuf buf; 504195972f6Sopenharmony_ci 505195972f6Sopenharmony_ci-#if USE_LIBOS 506195972f6Sopenharmony_ci- enum KERNEL_LWIP_PATH path = select_path(s); 507195972f6Sopenharmony_ci- if (path == PATH_ERR) { 508195972f6Sopenharmony_ci- return -1; 509195972f6Sopenharmony_ci- } else if (path == PATH_KERNEL) { 510195972f6Sopenharmony_ci- return posix_api->send_to(s, data, size, flags, to, tolen); 511195972f6Sopenharmony_ci- } 512195972f6Sopenharmony_ci-#endif 513195972f6Sopenharmony_ci- 514195972f6Sopenharmony_ci sock = get_socket(s); 515195972f6Sopenharmony_ci if (!sock) { 516195972f6Sopenharmony_ci return -1; 517195972f6Sopenharmony_ci@@ -2030,11 +1824,6 @@ lwip_socket(int domain, int type, int protocol) 518195972f6Sopenharmony_ci 519195972f6Sopenharmony_ci LWIP_UNUSED_ARG(domain); /* @todo: check this */ 520195972f6Sopenharmony_ci 521195972f6Sopenharmony_ci-#if USE_LIBOS 522195972f6Sopenharmony_ci- if ((domain != AF_INET && domain != AF_UNSPEC) || posix_api->is_chld) 523195972f6Sopenharmony_ci- return posix_api->socket_fn(domain, type, protocol); 524195972f6Sopenharmony_ci-#endif 525195972f6Sopenharmony_ci- 526195972f6Sopenharmony_ci /* create a netconn */ 527195972f6Sopenharmony_ci switch (type) { 528195972f6Sopenharmony_ci case SOCK_RAW: 529195972f6Sopenharmony_ci@@ -2091,14 +1880,6 @@ lwip_socket(int domain, int type, int protocol) 530195972f6Sopenharmony_ci ssize_t 531195972f6Sopenharmony_ci lwip_write(int s, const void *data, size_t size) 532195972f6Sopenharmony_ci { 533195972f6Sopenharmony_ci-#if USE_LIBOS 534195972f6Sopenharmony_ci- enum KERNEL_LWIP_PATH path = select_path(s); 535195972f6Sopenharmony_ci- if (path == PATH_ERR) { 536195972f6Sopenharmony_ci- return -1; 537195972f6Sopenharmony_ci- } else if (path == PATH_KERNEL) { 538195972f6Sopenharmony_ci- return posix_api->write_fn(s, data, size); 539195972f6Sopenharmony_ci- } 540195972f6Sopenharmony_ci-#endif 541195972f6Sopenharmony_ci return lwip_send(s, data, size, 0); 542195972f6Sopenharmony_ci } 543195972f6Sopenharmony_ci 544195972f6Sopenharmony_ci@@ -2884,20 +2665,16 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len) 545195972f6Sopenharmony_ci check_waiters = 0; 546195972f6Sopenharmony_ci } 547195972f6Sopenharmony_ci #if USE_LIBOS 548195972f6Sopenharmony_ci- if (sock->epoll & EPOLLET) { 549195972f6Sopenharmony_ci- list_del_node_null(&sock->list); 550195972f6Sopenharmony_ci+ if (conn->state == NETCONN_LISTEN) { 551195972f6Sopenharmony_ci+ add_epoll_event(conn, EPOLLIN); 552195972f6Sopenharmony_ci+ } else { 553195972f6Sopenharmony_ci+ add_recv_list(conn->socket); 554195972f6Sopenharmony_ci } 555195972f6Sopenharmony_ci- add_epoll_event(conn, EPOLLIN); 556195972f6Sopenharmony_ci #endif 557195972f6Sopenharmony_ci break; 558195972f6Sopenharmony_ci case NETCONN_EVT_RCVMINUS: 559195972f6Sopenharmony_ci sock->rcvevent--; 560195972f6Sopenharmony_ci check_waiters = 0; 561195972f6Sopenharmony_ci-#if USE_LIBOS 562195972f6Sopenharmony_ci- if ((sock->epoll & EPOLLET) == 0) { 563195972f6Sopenharmony_ci- del_epoll_event(conn, EPOLLIN); 564195972f6Sopenharmony_ci- } 565195972f6Sopenharmony_ci-#endif 566195972f6Sopenharmony_ci break; 567195972f6Sopenharmony_ci case NETCONN_EVT_SENDPLUS: 568195972f6Sopenharmony_ci if (sock->sendevent) { 569195972f6Sopenharmony_ci@@ -2905,27 +2682,16 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len) 570195972f6Sopenharmony_ci } 571195972f6Sopenharmony_ci sock->sendevent = 1; 572195972f6Sopenharmony_ci #if USE_LIBOS 573195972f6Sopenharmony_ci- if (sock->epoll & EPOLLET) { 574195972f6Sopenharmony_ci- list_del_node_null(&sock->list); 575195972f6Sopenharmony_ci- } 576195972f6Sopenharmony_ci add_epoll_event(conn, EPOLLOUT); 577195972f6Sopenharmony_ci #endif 578195972f6Sopenharmony_ci break; 579195972f6Sopenharmony_ci case NETCONN_EVT_SENDMINUS: 580195972f6Sopenharmony_ci sock->sendevent = 0; 581195972f6Sopenharmony_ci check_waiters = 0; 582195972f6Sopenharmony_ci-#if USE_LIBOS 583195972f6Sopenharmony_ci- if ((sock->epoll & EPOLLET) == 0) { 584195972f6Sopenharmony_ci- del_epoll_event(conn, EPOLLOUT); 585195972f6Sopenharmony_ci- } 586195972f6Sopenharmony_ci-#endif 587195972f6Sopenharmony_ci break; 588195972f6Sopenharmony_ci case NETCONN_EVT_ERROR: 589195972f6Sopenharmony_ci sock->errevent = 1; 590195972f6Sopenharmony_ci #if USE_LIBOS 591195972f6Sopenharmony_ci- if (sock->epoll & EPOLLET) { 592195972f6Sopenharmony_ci- list_del_node_null(&sock->list); 593195972f6Sopenharmony_ci- } 594195972f6Sopenharmony_ci add_epoll_event(conn, EPOLLERR); 595195972f6Sopenharmony_ci #endif 596195972f6Sopenharmony_ci break; 597195972f6Sopenharmony_ci@@ -3139,41 +2905,12 @@ lwip_getaddrname(int s, struct sockaddr *name, socklen_t *namelen, u8_t local) 598195972f6Sopenharmony_ci int 599195972f6Sopenharmony_ci lwip_getpeername(int s, struct sockaddr *name, socklen_t *namelen) 600195972f6Sopenharmony_ci { 601195972f6Sopenharmony_ci-#if USE_LIBOS 602195972f6Sopenharmony_ci- struct lwip_sock *sock; 603195972f6Sopenharmony_ci- 604195972f6Sopenharmony_ci- sock = posix_api->get_socket(s); 605195972f6Sopenharmony_ci- if (!sock) { 606195972f6Sopenharmony_ci- return posix_api->getpeername_fn(s, name, namelen); 607195972f6Sopenharmony_ci- } 608195972f6Sopenharmony_ci- /*for AF_INET, if has only host type bit, just call linux api, 609195972f6Sopenharmony_ci- *if has libos and host type bits, it's a not connected fd, call 610195972f6Sopenharmony_ci- *linux api and return -1(errno == ENOTCONN) is also ok*/ 611195972f6Sopenharmony_ci- if (CONN_TYPE_HAS_HOST(sock->conn)) { 612195972f6Sopenharmony_ci- return posix_api->getpeername_fn(s, name, namelen); 613195972f6Sopenharmony_ci- } 614195972f6Sopenharmony_ci-#endif 615195972f6Sopenharmony_ci- 616195972f6Sopenharmony_ci return lwip_getaddrname(s, name, namelen, 0); 617195972f6Sopenharmony_ci } 618195972f6Sopenharmony_ci 619195972f6Sopenharmony_ci int 620195972f6Sopenharmony_ci lwip_getsockname(int s, struct sockaddr *name, socklen_t *namelen) 621195972f6Sopenharmony_ci { 622195972f6Sopenharmony_ci-#if USE_LIBOS 623195972f6Sopenharmony_ci- struct lwip_sock *sock; 624195972f6Sopenharmony_ci- 625195972f6Sopenharmony_ci- sock = posix_api->get_socket(s); 626195972f6Sopenharmony_ci- if (!sock) { 627195972f6Sopenharmony_ci- return posix_api->getsockname_fn(s, name, namelen); 628195972f6Sopenharmony_ci- } 629195972f6Sopenharmony_ci- /*for AF_INET, if has only host type bit, just call linux api, 630195972f6Sopenharmony_ci- *if has libos and host type bits, also call linux api*/ 631195972f6Sopenharmony_ci- if (CONN_TYPE_HAS_HOST(sock->conn)) { 632195972f6Sopenharmony_ci- return posix_api->getsockname_fn(s, name, namelen); 633195972f6Sopenharmony_ci- } 634195972f6Sopenharmony_ci-#endif 635195972f6Sopenharmony_ci- 636195972f6Sopenharmony_ci return lwip_getaddrname(s, name, namelen, 1); 637195972f6Sopenharmony_ci } 638195972f6Sopenharmony_ci 639195972f6Sopenharmony_ci@@ -3186,23 +2923,11 @@ lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) 640195972f6Sopenharmony_ci LWIP_SETGETSOCKOPT_DATA_VAR_DECLARE(data); 641195972f6Sopenharmony_ci #endif /* !LWIP_TCPIP_CORE_LOCKING */ 642195972f6Sopenharmony_ci 643195972f6Sopenharmony_ci-#if USE_LIBOS 644195972f6Sopenharmony_ci- struct lwip_sock *sock = posix_api->get_socket(s); 645195972f6Sopenharmony_ci- 646195972f6Sopenharmony_ci- if (!sock) { 647195972f6Sopenharmony_ci- return posix_api->getsockopt_fn(s, level, optname, optval, optlen); 648195972f6Sopenharmony_ci- } 649195972f6Sopenharmony_ci- /*for AF_INET, we return linux result? */ 650195972f6Sopenharmony_ci- if (CONN_TYPE_HAS_HOST(sock->conn)) { 651195972f6Sopenharmony_ci- return posix_api->getsockopt_fn(s, level, optname, optval, optlen); 652195972f6Sopenharmony_ci- } 653195972f6Sopenharmony_ci-#else 654195972f6Sopenharmony_ci struct lwip_sock *sock = get_socket(s); 655195972f6Sopenharmony_ci 656195972f6Sopenharmony_ci if (!sock) { 657195972f6Sopenharmony_ci return -1; 658195972f6Sopenharmony_ci } 659195972f6Sopenharmony_ci-#endif /* USE_LIBOS */ 660195972f6Sopenharmony_ci 661195972f6Sopenharmony_ci if ((NULL == optval) || (NULL == optlen)) { 662195972f6Sopenharmony_ci sock_set_errno(sock, EFAULT); 663195972f6Sopenharmony_ci@@ -3645,25 +3370,11 @@ lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t opt 664195972f6Sopenharmony_ci LWIP_SETGETSOCKOPT_DATA_VAR_DECLARE(data); 665195972f6Sopenharmony_ci #endif /* !LWIP_TCPIP_CORE_LOCKING */ 666195972f6Sopenharmony_ci 667195972f6Sopenharmony_ci-#if USE_LIBOS 668195972f6Sopenharmony_ci- struct lwip_sock *sock = posix_api->get_socket(s); 669195972f6Sopenharmony_ci- 670195972f6Sopenharmony_ci- if (!sock) { 671195972f6Sopenharmony_ci- return posix_api->setsockopt_fn(s, level, optname, optval, optlen); 672195972f6Sopenharmony_ci- } 673195972f6Sopenharmony_ci- /*for AF_INET, we may try both linux and lwip*/ 674195972f6Sopenharmony_ci- if (CONN_TYPE_HAS_HOST(sock->conn)) { 675195972f6Sopenharmony_ci- if (posix_api->setsockopt_fn(s, level, optname, optval, optlen) < 0) { 676195972f6Sopenharmony_ci- return -1; 677195972f6Sopenharmony_ci- } 678195972f6Sopenharmony_ci- } 679195972f6Sopenharmony_ci-#else 680195972f6Sopenharmony_ci struct lwip_sock *sock = get_socket(s); 681195972f6Sopenharmony_ci 682195972f6Sopenharmony_ci if (!sock) { 683195972f6Sopenharmony_ci return -1; 684195972f6Sopenharmony_ci } 685195972f6Sopenharmony_ci-#endif /* USE_LIBOS */ 686195972f6Sopenharmony_ci 687195972f6Sopenharmony_ci if (NULL == optval) { 688195972f6Sopenharmony_ci sock_set_errno(sock, EFAULT); 689195972f6Sopenharmony_ci@@ -4308,26 +4019,6 @@ lwip_ioctl(int s, long cmd, void *argp) 690195972f6Sopenharmony_ci * the flag O_NONBLOCK is implemented for F_SETFL. 691195972f6Sopenharmony_ci */ 692195972f6Sopenharmony_ci int 693195972f6Sopenharmony_ci-#if USE_LIBOS 694195972f6Sopenharmony_ci-lwip_fcntl(int s, int cmd, ...) 695195972f6Sopenharmony_ci-{ 696195972f6Sopenharmony_ci- struct lwip_sock *sock = posix_api->get_socket(s); 697195972f6Sopenharmony_ci- int val, ret = -1; 698195972f6Sopenharmony_ci- int op_mode = 0; 699195972f6Sopenharmony_ci- va_list ap; 700195972f6Sopenharmony_ci- 701195972f6Sopenharmony_ci- va_start(ap, cmd); 702195972f6Sopenharmony_ci- val = va_arg(ap, int); 703195972f6Sopenharmony_ci- va_end(ap); 704195972f6Sopenharmony_ci- 705195972f6Sopenharmony_ci- if (!sock) { 706195972f6Sopenharmony_ci- return posix_api->fcntl_fn(s, cmd, val); 707195972f6Sopenharmony_ci- } 708195972f6Sopenharmony_ci- if (CONN_TYPE_HAS_HOST(sock->conn)) { 709195972f6Sopenharmony_ci- if ((ret = posix_api->fcntl_fn(s, cmd, val)) == -1) 710195972f6Sopenharmony_ci- return ret; 711195972f6Sopenharmony_ci- } 712195972f6Sopenharmony_ci-#else /* USE_LIBOS */ 713195972f6Sopenharmony_ci lwip_fcntl(int s, int cmd, int val) 714195972f6Sopenharmony_ci { 715195972f6Sopenharmony_ci struct lwip_sock *sock = get_socket(s); 716195972f6Sopenharmony_ci@@ -4337,7 +4028,6 @@ lwip_fcntl(int s, int cmd, int val) 717195972f6Sopenharmony_ci if (!sock) { 718195972f6Sopenharmony_ci return -1; 719195972f6Sopenharmony_ci } 720195972f6Sopenharmony_ci-#endif /* USE_LIBOS */ 721195972f6Sopenharmony_ci 722195972f6Sopenharmony_ci switch (cmd) { 723195972f6Sopenharmony_ci case F_GETFL: 724195972f6Sopenharmony_cidiff --git a/src/api/sys_arch.c b/src/api/sys_arch.c 725195972f6Sopenharmony_ciindex 55561b1..9a92143 100644 726195972f6Sopenharmony_ci--- a/src/api/sys_arch.c 727195972f6Sopenharmony_ci+++ b/src/api/sys_arch.c 728195972f6Sopenharmony_ci@@ -76,8 +76,8 @@ struct sys_mem_stats { 729195972f6Sopenharmony_ci 730195972f6Sopenharmony_ci static PER_THREAD struct sys_mem_stats hugepage_stats; 731195972f6Sopenharmony_ci 732195972f6Sopenharmony_ci-static PER_THREAD uint64_t cycles_per_ms __attribute__((aligned(64))); 733195972f6Sopenharmony_ci-static PER_THREAD uint64_t sys_start_ms __attribute__((aligned(64))); 734195972f6Sopenharmony_ci+static uint64_t cycles_per_ms __attribute__((aligned(64))); 735195972f6Sopenharmony_ci+static uint64_t sys_start_ms __attribute__((aligned(64))); 736195972f6Sopenharmony_ci 737195972f6Sopenharmony_ci /* 738195972f6Sopenharmony_ci * Mailbox 739195972f6Sopenharmony_ci@@ -337,8 +337,12 @@ void sys_calibrate_tsc(void) 740195972f6Sopenharmony_ci #define MS_PER_SEC 1E3 741195972f6Sopenharmony_ci uint64_t freq = rte_get_tsc_hz(); 742195972f6Sopenharmony_ci 743195972f6Sopenharmony_ci- cycles_per_ms = (freq + MS_PER_SEC - 1) / MS_PER_SEC; 744195972f6Sopenharmony_ci- sys_start_ms = rte_rdtsc() / cycles_per_ms; 745195972f6Sopenharmony_ci+ if (cycles_per_ms == 0) { 746195972f6Sopenharmony_ci+ cycles_per_ms = (freq + MS_PER_SEC - 1) / MS_PER_SEC; 747195972f6Sopenharmony_ci+ } 748195972f6Sopenharmony_ci+ if (sys_start_ms == 0) { 749195972f6Sopenharmony_ci+ sys_start_ms = rte_rdtsc() / cycles_per_ms; 750195972f6Sopenharmony_ci+ } 751195972f6Sopenharmony_ci } 752195972f6Sopenharmony_ci 753195972f6Sopenharmony_ci uint32_t sys_now(void) 754195972f6Sopenharmony_cidiff --git a/src/core/tcp_out.c b/src/core/tcp_out.c 755195972f6Sopenharmony_ciindex dac498e..b99974d 100644 756195972f6Sopenharmony_ci--- a/src/core/tcp_out.c 757195972f6Sopenharmony_ci+++ b/src/core/tcp_out.c 758195972f6Sopenharmony_ci@@ -472,6 +472,7 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags) 759195972f6Sopenharmony_ci * pos records progress as data is segmented. 760195972f6Sopenharmony_ci */ 761195972f6Sopenharmony_ci 762195972f6Sopenharmony_ci+#if !USE_LIBOS 763195972f6Sopenharmony_ci /* Find the tail of the unsent queue. */ 764195972f6Sopenharmony_ci if (pcb->unsent != NULL) { 765195972f6Sopenharmony_ci u16_t space; 766195972f6Sopenharmony_ci@@ -587,6 +588,13 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags) 767195972f6Sopenharmony_ci pcb->unsent_oversize == 0); 768195972f6Sopenharmony_ci #endif /* TCP_OVERSIZE */ 769195972f6Sopenharmony_ci } 770195972f6Sopenharmony_ci+#else /* USE_LIBOS */ 771195972f6Sopenharmony_ci+ if (pcb->unsent != NULL) { 772195972f6Sopenharmony_ci+ /* @todo: this could be sped up by keeping last_unsent in the pcb */ 773195972f6Sopenharmony_ci+ for (last_unsent = pcb->unsent; last_unsent->next != NULL; 774195972f6Sopenharmony_ci+ last_unsent = last_unsent->next); 775195972f6Sopenharmony_ci+ } 776195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 777195972f6Sopenharmony_ci 778195972f6Sopenharmony_ci /* 779195972f6Sopenharmony_ci * Phase 3: Create new segments. 780195972f6Sopenharmony_ci@@ -604,6 +612,7 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags) 781195972f6Sopenharmony_ci u8_t chksum_swapped = 0; 782195972f6Sopenharmony_ci #endif /* TCP_CHECKSUM_ON_COPY */ 783195972f6Sopenharmony_ci 784195972f6Sopenharmony_ci+#if !USE_LIBOS 785195972f6Sopenharmony_ci if (apiflags & TCP_WRITE_FLAG_COPY) { 786195972f6Sopenharmony_ci /* If copy is set, memory should be allocated and data copied 787195972f6Sopenharmony_ci * into pbuf */ 788195972f6Sopenharmony_ci@@ -650,6 +659,10 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags) 789195972f6Sopenharmony_ci /* Concatenate the headers and data pbufs together. */ 790195972f6Sopenharmony_ci pbuf_cat(p/*header*/, p2/*data*/); 791195972f6Sopenharmony_ci } 792195972f6Sopenharmony_ci+#else /* USE_LIBOS */ 793195972f6Sopenharmony_ci+ p = (struct pbuf *)arg; 794195972f6Sopenharmony_ci+ seglen = p->len; 795195972f6Sopenharmony_ci+#endif /* USE_LIBOS */ 796195972f6Sopenharmony_ci 797195972f6Sopenharmony_ci queuelen += pbuf_clen(p); 798195972f6Sopenharmony_ci 799195972f6Sopenharmony_cidiff --git a/src/include/eventpoll.h b/src/include/eventpoll.h 800195972f6Sopenharmony_ciindex f525bc2..aacc1d2 100644 801195972f6Sopenharmony_ci--- a/src/include/eventpoll.h 802195972f6Sopenharmony_ci+++ b/src/include/eventpoll.h 803195972f6Sopenharmony_ci@@ -63,9 +63,7 @@ struct libos_epoll { 804195972f6Sopenharmony_ci int efd; /* eventfd */ 805195972f6Sopenharmony_ci }; 806195972f6Sopenharmony_ci 807195972f6Sopenharmony_ci-extern int add_epoll_event(struct netconn*, uint32_t); 808195972f6Sopenharmony_ci-extern int del_epoll_event(struct netconn*, uint32_t); 809195972f6Sopenharmony_ci-extern int lwip_epoll_close(int); 810195972f6Sopenharmony_ci-extern int lwip_is_epfd(int); 811195972f6Sopenharmony_ci+extern void add_epoll_event(struct netconn*, uint32_t); 812195972f6Sopenharmony_ci+extern int32_t lstack_epoll_close(int32_t); 813195972f6Sopenharmony_ci 814195972f6Sopenharmony_ci #endif /* __EVENTPOLL_H__ */ 815195972f6Sopenharmony_cidiff --git a/src/include/lwip/priv/tcp_priv.h b/src/include/lwip/priv/tcp_priv.h 816195972f6Sopenharmony_ciindex f771725..83208bf 100644 817195972f6Sopenharmony_ci--- a/src/include/lwip/priv/tcp_priv.h 818195972f6Sopenharmony_ci+++ b/src/include/lwip/priv/tcp_priv.h 819195972f6Sopenharmony_ci@@ -349,7 +349,7 @@ static inline int vdev_reg_done(enum reg_ring_type reg_type, const struct tcp_pc 820195972f6Sopenharmony_ci { 821195972f6Sopenharmony_ci LWIP_ASSERT("Invalid parameter", pcb != NULL); 822195972f6Sopenharmony_ci 823195972f6Sopenharmony_ci- struct libnet_quintuple qtuple; 824195972f6Sopenharmony_ci+ struct gazelle_quintuple qtuple; 825195972f6Sopenharmony_ci qtuple.protocol = 0; 826195972f6Sopenharmony_ci qtuple.src_ip = pcb->local_ip.addr; 827195972f6Sopenharmony_ci qtuple.src_port = lwip_htons(pcb->local_port); 828195972f6Sopenharmony_cidiff --git a/src/include/lwip/sockets.h b/src/include/lwip/sockets.h 829195972f6Sopenharmony_ciindex 345e26c..4e7e671 100644 830195972f6Sopenharmony_ci--- a/src/include/lwip/sockets.h 831195972f6Sopenharmony_ci+++ b/src/include/lwip/sockets.h 832195972f6Sopenharmony_ci@@ -647,7 +647,7 @@ int lwip_poll(struct pollfd *fds, nfds_t nfds, int timeout); 833195972f6Sopenharmony_ci 834195972f6Sopenharmony_ci #if USE_LIBOS 835195972f6Sopenharmony_ci int lwip_ioctl(int s, long cmd, ...); 836195972f6Sopenharmony_ci-int lwip_fcntl(int s, int cmd, ...); 837195972f6Sopenharmony_ci+int lwip_fcntl(int s, int cmd, int val); 838195972f6Sopenharmony_ci #else 839195972f6Sopenharmony_ci int lwip_ioctl(int s, long cmd, void *argp); 840195972f6Sopenharmony_ci int lwip_fcntl(int s, int cmd, int val); 841195972f6Sopenharmony_cidiff --git a/src/include/lwipsock.h b/src/include/lwipsock.h 842195972f6Sopenharmony_ciindex e9ffbb1..069cdcb 100644 843195972f6Sopenharmony_ci--- a/src/include/lwipsock.h 844195972f6Sopenharmony_ci+++ b/src/include/lwipsock.h 845195972f6Sopenharmony_ci@@ -60,6 +60,10 @@ union lwip_sock_lastdata { 846195972f6Sopenharmony_ci struct pbuf *pbuf; 847195972f6Sopenharmony_ci }; 848195972f6Sopenharmony_ci 849195972f6Sopenharmony_ci+#if USE_LIBOS 850195972f6Sopenharmony_ci+struct protocol_stack; 851195972f6Sopenharmony_ci+struct weakup_poll; 852195972f6Sopenharmony_ci+#endif 853195972f6Sopenharmony_ci /** Contains all internal pointers and states used for a socket */ 854195972f6Sopenharmony_ci struct lwip_sock { 855195972f6Sopenharmony_ci /** sockets currently are built on netconns, each socket has one netconn */ 856195972f6Sopenharmony_ci@@ -88,14 +92,19 @@ struct lwip_sock { 857195972f6Sopenharmony_ci #endif 858195972f6Sopenharmony_ci 859195972f6Sopenharmony_ci #if USE_LIBOS 860195972f6Sopenharmony_ci- struct list_node list; 861195972f6Sopenharmony_ci- /* registered events */ 862195972f6Sopenharmony_ci- uint32_t epoll; 863195972f6Sopenharmony_ci- /* available events */ 864195972f6Sopenharmony_ci- uint32_t events; 865195972f6Sopenharmony_ci+ uint32_t epoll_events; /* registered events */ 866195972f6Sopenharmony_ci+ uint32_t events; /* available events */ 867195972f6Sopenharmony_ci+ int32_t in_event; /* avoid recurring events */ 868195972f6Sopenharmony_ci epoll_data_t ep_data; 869195972f6Sopenharmony_ci- /* libos_epoll pointer in use */ 870195972f6Sopenharmony_ci- struct libos_epoll *epoll_data; 871195972f6Sopenharmony_ci+ struct weakup_poll *weakup; 872195972f6Sopenharmony_ci+ struct protocol_stack *stack; 873195972f6Sopenharmony_ci+ void *recv_ring; 874195972f6Sopenharmony_ci+ struct pbuf *recv_lastdata; /* unread data in one pbuf */ 875195972f6Sopenharmony_ci+ struct pbuf *send_lastdata; /* unread data in one pbuf */ 876195972f6Sopenharmony_ci+ void *send_ring; 877195972f6Sopenharmony_ci+ int32_t recv_flags; 878195972f6Sopenharmony_ci+ int32_t nextfd; /* listenfd list */ 879195972f6Sopenharmony_ci+ struct list_node recv_list; 880195972f6Sopenharmony_ci #endif 881195972f6Sopenharmony_ci }; 882195972f6Sopenharmony_ci 883195972f6Sopenharmony_ci@@ -138,6 +147,10 @@ get_socket_without_errno(int s) 884195972f6Sopenharmony_ci 885195972f6Sopenharmony_ci return sock; 886195972f6Sopenharmony_ci } 887195972f6Sopenharmony_ci+ 888195972f6Sopenharmony_ci+extern void add_recv_list(int32_t fd); 889195972f6Sopenharmony_ci+extern ssize_t read_lwip_data(struct lwip_sock *sock, int32_t flags, u8_t apiflags); 890195972f6Sopenharmony_ci+extern void gazelle_clean_sock(int32_t fd); 891195972f6Sopenharmony_ci #endif /* USE_LIBOS */ 892195972f6Sopenharmony_ci 893195972f6Sopenharmony_ci struct lwip_sock *get_socket(int s); 894195972f6Sopenharmony_ci@@ -145,6 +158,4 @@ struct lwip_sock *get_socket_by_fd(int s); 895195972f6Sopenharmony_ci void lwip_sock_init(void); 896195972f6Sopenharmony_ci void lwip_exit(void); 897195972f6Sopenharmony_ci 898195972f6Sopenharmony_ci-extern int is_host_ipv4(uint32_t ipv4); 899195972f6Sopenharmony_ci- 900195972f6Sopenharmony_ci #endif /* __LWIPSOCK_H__ */ 901195972f6Sopenharmony_cidiff --git a/src/include/posix_api.h b/src/include/posix_api.h 902195972f6Sopenharmony_ciindex 0dca8eb..2afd266 100644 903195972f6Sopenharmony_ci--- a/src/include/posix_api.h 904195972f6Sopenharmony_ci+++ b/src/include/posix_api.h 905195972f6Sopenharmony_ci@@ -34,7 +34,7 @@ 906195972f6Sopenharmony_ci #define __POSIX_API_H__ 907195972f6Sopenharmony_ci 908195972f6Sopenharmony_ci #include <signal.h> 909195972f6Sopenharmony_ci-#include <poll.h> 910195972f6Sopenharmony_ci+#include <sys/poll.h> 911195972f6Sopenharmony_ci #include <sys/epoll.h> 912195972f6Sopenharmony_ci #include <sys/eventfd.h> 913195972f6Sopenharmony_ci 914195972f6Sopenharmony_cidiff --git a/src/include/reg_sock.h b/src/include/reg_sock.h 915195972f6Sopenharmony_ciindex 76d4c48..76673da 100644 916195972f6Sopenharmony_ci--- a/src/include/reg_sock.h 917195972f6Sopenharmony_ci+++ b/src/include/reg_sock.h 918195972f6Sopenharmony_ci@@ -41,7 +41,7 @@ enum reg_ring_type { 919195972f6Sopenharmony_ci RING_REG_MAX, 920195972f6Sopenharmony_ci }; 921195972f6Sopenharmony_ci 922195972f6Sopenharmony_ci-struct libnet_quintuple { 923195972f6Sopenharmony_ci+struct gazelle_quintuple { 924195972f6Sopenharmony_ci uint32_t protocol; 925195972f6Sopenharmony_ci /* net byte order */ 926195972f6Sopenharmony_ci uint16_t src_port; 927195972f6Sopenharmony_ci@@ -54,9 +54,9 @@ struct reg_ring_msg { 928195972f6Sopenharmony_ci enum reg_ring_type type; 929195972f6Sopenharmony_ci 930195972f6Sopenharmony_ci uint32_t tid; 931195972f6Sopenharmony_ci- struct libnet_quintuple qtuple; 932195972f6Sopenharmony_ci+ struct gazelle_quintuple qtuple; 933195972f6Sopenharmony_ci }; 934195972f6Sopenharmony_ci 935195972f6Sopenharmony_ci-extern int vdev_reg_xmit(enum reg_ring_type type, struct libnet_quintuple *qtuple); 936195972f6Sopenharmony_ci+extern int vdev_reg_xmit(enum reg_ring_type type, struct gazelle_quintuple *qtuple); 937195972f6Sopenharmony_ci 938195972f6Sopenharmony_ci-#endif /* __REG_SOCK_H__ */ 939195972f6Sopenharmony_ci\ No newline at end of file 940195972f6Sopenharmony_ci+#endif /* __REG_SOCK_H__ */ 941195972f6Sopenharmony_ci-- 942195972f6Sopenharmony_ci2.30.0 943195972f6Sopenharmony_ci 944