optimize the codes with lwip and opcua

This commit is contained in:
wlyu
2022-03-21 16:47:32 +08:00
parent a52854efb6
commit f74d1dafd7
25 changed files with 452 additions and 2257 deletions
@@ -245,7 +245,6 @@ netconn_delete(struct netconn *conn)
err = ERR_OK;
} else
#endif /* LWIP_NETCONN_FULLDUPLEX */
//tst by wly
{
err = netconn_prepare_delete(conn);
}
@@ -497,18 +497,6 @@ get_socket(int fd)
return sock;
}
void pr_socket_buf(void)
{
int i;
lw_debug("socket:\n");
for (i = 0; i < NUM_SOCKETS; ++i) {
// if (!sockets[i].conn)
lw_debug("%d: conn %p rcv %d send %d wait %d\n", i, sockets[i].conn, sockets[i].rcvevent, sockets[i].sendevent,
sockets[i].select_waiting);
}
}
/**
* Allocate a new socket for a given netconn.
*
@@ -600,7 +588,6 @@ free_socket_free_elements(int is_tcp, struct netconn *conn, union lwip_sock_last
}
if (conn != NULL) {
/* netconn_prepare_delete() has already been called, here we only free the conn */
lw_debug("lw: [%s] tcp %d socket %d accept %d recv %d\n", __func__, is_tcp, conn->socket, conn->acceptmbox, conn->recvmbox);
netconn_delete(conn);
}
}
@@ -673,8 +660,6 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
newsock = alloc_socket(newconn, 1);
if (newsock == -1) {
lw_debug("lw: [%s] recv %d\n", __func__, newconn->recvmbox);
pr_socket_buf();
netconn_delete(newconn);
sock_set_errno(sock, ENFILE);
done_socket(sock);
@@ -711,8 +696,6 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
err = netconn_peer(newconn, &naddr, &port);
if (err != ERR_OK) {
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d): netconn_peer failed, err=%d\n", s, err));
lw_debug("lw: [%s] recv %x\n", __func__, newconn->recvmbox);
netconn_delete(newconn);
free_socket(nsock, 1);
sock_set_errno(sock, err_to_errno(err));
@@ -1756,8 +1739,6 @@ lwip_socket(int domain, int type, int protocol)
i = alloc_socket(conn, 0);
if (i == -1) {
lw_debug("lw: [%s] recv %d delete no socket\n", __func__, conn->recvmbox);
pr_socket_buf();
netconn_delete(conn);
set_errno(ENFILE);
return -1;
@@ -1766,7 +1747,6 @@ lwip_socket(int domain, int type, int protocol)
done_socket(&sockets[i - LWIP_SOCKET_OFFSET]);
LWIP_DEBUGF(SOCKETS_DEBUG, ("%d\n", i));
set_errno(0);
lw_debug("lw: [%s] new socket %d %p\n", __func__, i, conn);
return i;
}
@@ -250,10 +250,9 @@ typedef unsigned int nfds_t;
#define MEMP_MEM_MALLOC 1
#define lw_print //KPrintf
#define lw_trace() //KPrintf("lw: [%s][%d] passed!\n", __func__, __LINE__)
#define lw_error() //KPrintf("lw: [%s][%d] failed!\n", __func__, __LINE__)
#define lw_debug KPrintf
#define lw_error KPrintf
#define lw_notice KPrintf
#endif /* __LWIPOPTS_H__ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
@@ -355,7 +355,7 @@ tcp_write_checks(struct tcp_pcb *pcb, u16_t len)
* it can send them more efficiently by combining them together).
* To prompt the system to send data now, call tcp_output() after
* calling tcp_write().
*
*
* This function enqueues the data pointed to by the argument dataptr. The length of
* the data is passed as the len parameter. The apiflags can be one or more of:
* - TCP_WRITE_FLAG_COPY: indicates whether the new memory should be allocated
@@ -1386,17 +1386,13 @@ tcp_output(struct tcp_pcb *pcb)
/* In the case of fast retransmit, the packet should not go to the tail
* of the unacked queue, but rather somewhere before it. We need to check for
* this case. -STJ Jul 27, 2004 */
lw_debug("check %s seg %p useg %p\n", __func__, seg, useg);
if (TCP_SEQ_LT(lwip_ntohl(seg->tcphdr->seqno), lwip_ntohl(useg->tcphdr->seqno))) {
/* add segment to before tail of unacked list, keeping the list sorted */
struct tcp_seg **cur_seg = &(pcb->unacked);
lw_debug("check %s ", __func__);
while (*cur_seg &&
TCP_SEQ_LT(lwip_ntohl((*cur_seg)->tcphdr->seqno), lwip_ntohl(seg->tcphdr->seqno))) {
lw_debug("%p -> ", *cur_seg);
cur_seg = &((*cur_seg)->next );
}
lw_debug("\n");
seg->next = (*cur_seg);
(*cur_seg) = seg;
} else {