1195972f6Sopenharmony_ciFrom b867f6901773def31884a9ae527a1282d274a85d Mon Sep 17 00:00:00 2001 2195972f6Sopenharmony_ciFrom: wuchangsheng <wuchangsheng2@huawei.com> 3195972f6Sopenharmony_ciDate: Sat, 10 Jul 2021 22:27:19 +0800 4195972f6Sopenharmony_ciSubject: [PATCH] fix epoll_ctl EPOLLET mode error 5195972f6Sopenharmony_ci--- 6195972f6Sopenharmony_ci src/api/sockets.c | 33 +++++++++++++++++++++++---------- 7195972f6Sopenharmony_ci 1 file changed, 23 insertions(+), 10 deletions(-) 8195972f6Sopenharmony_ci 9195972f6Sopenharmony_cidiff --git a/src/api/sockets.c b/src/api/sockets.c 10195972f6Sopenharmony_ciindex 658f762..eccc7f9 100644 11195972f6Sopenharmony_ci--- a/src/api/sockets.c 12195972f6Sopenharmony_ci+++ b/src/api/sockets.c 13195972f6Sopenharmony_ci@@ -714,6 +714,13 @@ free_socket(struct lwip_sock *sock, int is_tcp) 14195972f6Sopenharmony_ci /* Protect socket array */ 15195972f6Sopenharmony_ci SYS_ARCH_PROTECT(lev); 16195972f6Sopenharmony_ci 17195972f6Sopenharmony_ci+#if USE_LIBOS 18195972f6Sopenharmony_ci+ sock->epoll = LIBOS_EPOLLNONE; 19195972f6Sopenharmony_ci+ sock->events = 0; 20195972f6Sopenharmony_ci+ sock->epoll_data = NULL; 21195972f6Sopenharmony_ci+ list_del_node_null(&sock->list); 22195972f6Sopenharmony_ci+#endif 23195972f6Sopenharmony_ci+ 24195972f6Sopenharmony_ci freed = free_socket_locked(sock, is_tcp, &conn, &lastdata); 25195972f6Sopenharmony_ci SYS_ARCH_UNPROTECT(lev); 26195972f6Sopenharmony_ci /* don't use 'sock' after this line, as another task might have allocated it */ 27195972f6Sopenharmony_ci@@ -1003,13 +1010,6 @@ lwip_close(int s) 28195972f6Sopenharmony_ci return -1; 29195972f6Sopenharmony_ci } 30195972f6Sopenharmony_ci 31195972f6Sopenharmony_ci-#if USE_LIBOS 32195972f6Sopenharmony_ci- sock->epoll = LIBOS_EPOLLNONE; 33195972f6Sopenharmony_ci- sock->events = 0; 34195972f6Sopenharmony_ci- sock->epoll_data = NULL; 35195972f6Sopenharmony_ci- list_del_node_null(&sock->list); 36195972f6Sopenharmony_ci-#endif 37195972f6Sopenharmony_ci- 38195972f6Sopenharmony_ci free_socket(sock, is_tcp); 39195972f6Sopenharmony_ci set_errno(0); 40195972f6Sopenharmony_ci return 0; 41195972f6Sopenharmony_ci@@ -1191,7 +1191,7 @@ lwip_recv_tcp(struct lwip_sock *sock, void *mem, size_t len, int flags) 42195972f6Sopenharmony_ci if (sock->lastdata.pbuf) { 43195972f6Sopenharmony_ci p = sock->lastdata.pbuf; 44195972f6Sopenharmony_ci #if USE_LIBOS 45195972f6Sopenharmony_ci- if ((flags & MSG_PEEK) == 0) { 46195972f6Sopenharmony_ci+ if (((flags & MSG_PEEK) == 0) && ((sock->epoll & EPOLLET) == 0)) { 47195972f6Sopenharmony_ci if ((NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP)) { 48195972f6Sopenharmony_ci del_epoll_event(sock->conn, EPOLLIN); 49195972f6Sopenharmony_ci } 50195972f6Sopenharmony_ci@@ -2889,6 +2889,9 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len) 51195972f6Sopenharmony_ci check_waiters = 0; 52195972f6Sopenharmony_ci } 53195972f6Sopenharmony_ci #if USE_LIBOS 54195972f6Sopenharmony_ci+ if (sock->epoll & EPOLLET) { 55195972f6Sopenharmony_ci+ list_del_node_null(&sock->list); 56195972f6Sopenharmony_ci+ } 57195972f6Sopenharmony_ci add_epoll_event(conn, EPOLLIN); 58195972f6Sopenharmony_ci #endif 59195972f6Sopenharmony_ci break; 60195972f6Sopenharmony_ci@@ -2896,7 +2899,9 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len) 61195972f6Sopenharmony_ci sock->rcvevent--; 62195972f6Sopenharmony_ci check_waiters = 0; 63195972f6Sopenharmony_ci #if USE_LIBOS 64195972f6Sopenharmony_ci- del_epoll_event(conn, EPOLLIN); 65195972f6Sopenharmony_ci+ if ((sock->epoll & EPOLLET) == 0) { 66195972f6Sopenharmony_ci+ del_epoll_event(conn, EPOLLIN); 67195972f6Sopenharmony_ci+ } 68195972f6Sopenharmony_ci #endif 69195972f6Sopenharmony_ci break; 70195972f6Sopenharmony_ci case NETCONN_EVT_SENDPLUS: 71195972f6Sopenharmony_ci@@ -2905,6 +2910,9 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len) 72195972f6Sopenharmony_ci } 73195972f6Sopenharmony_ci sock->sendevent = 1; 74195972f6Sopenharmony_ci #if USE_LIBOS 75195972f6Sopenharmony_ci+ if (sock->epoll & EPOLLET) { 76195972f6Sopenharmony_ci+ list_del_node_null(&sock->list); 77195972f6Sopenharmony_ci+ } 78195972f6Sopenharmony_ci add_epoll_event(conn, EPOLLOUT); 79195972f6Sopenharmony_ci #endif 80195972f6Sopenharmony_ci break; 81195972f6Sopenharmony_ci@@ -2912,12 +2920,17 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len) 82195972f6Sopenharmony_ci sock->sendevent = 0; 83195972f6Sopenharmony_ci check_waiters = 0; 84195972f6Sopenharmony_ci #if USE_LIBOS 85195972f6Sopenharmony_ci- del_epoll_event(conn, EPOLLOUT); 86195972f6Sopenharmony_ci+ if ((sock->epoll & EPOLLET) == 0) { 87195972f6Sopenharmony_ci+ del_epoll_event(conn, EPOLLOUT); 88195972f6Sopenharmony_ci+ } 89195972f6Sopenharmony_ci #endif 90195972f6Sopenharmony_ci break; 91195972f6Sopenharmony_ci case NETCONN_EVT_ERROR: 92195972f6Sopenharmony_ci sock->errevent = 1; 93195972f6Sopenharmony_ci #if USE_LIBOS 94195972f6Sopenharmony_ci+ if (sock->epoll & EPOLLET) { 95195972f6Sopenharmony_ci+ list_del_node_null(&sock->list); 96195972f6Sopenharmony_ci+ } 97195972f6Sopenharmony_ci add_epoll_event(conn, EPOLLERR); 98195972f6Sopenharmony_ci #endif 99195972f6Sopenharmony_ci break; 100195972f6Sopenharmony_ci-- 101195972f6Sopenharmony_ci2.23.0 102195972f6Sopenharmony_ci 103