1From 87166f699e0febd36b81d914713b770119ead471 Mon Sep 17 00:00:00 2001 2From: wuchangsheng <wuchangsheng2@huawei.com> 3Date: Thu, 6 Oct 2022 20:16:06 +0800 4Subject: [PATCH] refactor add event, limit send pkts num 5 6--- 7 src/api/sockets.c | 4 ++-- 8 src/core/tcp_out.c | 8 ++++++++ 9 src/include/eventpoll.h | 3 ++- 10 3 files changed, 12 insertions(+), 3 deletions(-) 11 12diff --git a/src/api/sockets.c b/src/api/sockets.c 13index 4d4cea1..d5b69eb 100644 14--- a/src/api/sockets.c 15+++ b/src/api/sockets.c 16@@ -2665,7 +2665,7 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len) 17 } 18 #if USE_LIBOS 19 if (conn->acceptmbox != NULL && !sys_mbox_empty(conn->acceptmbox)) { 20- add_epoll_event(conn, POLLIN); 21+ add_sock_event(sock, POLLIN); 22 } 23 #endif 24 break; 25@@ -2686,7 +2686,7 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len) 26 case NETCONN_EVT_ERROR: 27 sock->errevent = 1; 28 #if USE_LIBOS 29- add_epoll_event(conn, EPOLLERR); 30+ add_sock_event(sock, EPOLLERR); 31 #endif 32 break; 33 default: 34diff --git a/src/core/tcp_out.c b/src/core/tcp_out.c 35index 1b0af8d..dd780d3 100644 36--- a/src/core/tcp_out.c 37+++ b/src/core/tcp_out.c 38@@ -1358,8 +1358,16 @@ tcp_output(struct tcp_pcb *pcb) 39 for (; useg->next != NULL; useg = useg->next); 40 } 41 /* data available and window allows it to be sent? */ 42+#if USE_LIBOS 43+ /* avoid send cose too much time, limit send pkts num max 10 */ 44+ uint16_t send_pkt = 0; 45+ while (seg != NULL && send_pkt < 10 && 46+ lwip_ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len <= wnd) { 47+ send_pkt++; 48+#else 49 while (seg != NULL && 50 lwip_ntohl(seg->tcphdr->seqno) - pcb->lastack + seg->len <= wnd) { 51+#endif 52 LWIP_ASSERT("RST not expected here!", 53 (TCPH_FLAGS(seg->tcphdr) & TCP_RST) == 0); 54 /* Stop sending if the nagle algorithm would prevent it 55diff --git a/src/include/eventpoll.h b/src/include/eventpoll.h 56index aacc1d2..a10c84b 100644 57--- a/src/include/eventpoll.h 58+++ b/src/include/eventpoll.h 59@@ -63,7 +63,8 @@ struct libos_epoll { 60 int efd; /* eventfd */ 61 }; 62 63-extern void add_epoll_event(struct netconn*, uint32_t); 64+struct lwip_sock; 65+extern void add_sock_event(struct lwip_sock *sock, uint32_t event); 66 extern int32_t lstack_epoll_close(int32_t); 67 68 #endif /* __EVENTPOLL_H__ */ 69-- 702.27.0 71 72