Skip to content

Commit 39ceda6

Browse files
dgarskedanielinux
authored andcommitted
Peer review fixes
1 parent 45ceca1 commit 39ceda6

4 files changed

Lines changed: 22 additions & 5 deletions

File tree

src/port/rtl8735b/main.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ static void echo_cb(int fd, uint16_t event, void *arg)
9696
{
9797
struct wolfIP *s = (struct wolfIP *)arg;
9898
int ret;
99+
int sent;
99100

100101
if ((fd == listen_fd) && (event & CB_EVENT_READABLE) && (client_fd == -1)) {
101102
int c = wolfIP_sock_accept(s, listen_fd, NULL, NULL);
@@ -112,9 +113,15 @@ static void echo_cb(int fd, uint16_t event, void *arg)
112113
do {
113114
ret = wolfIP_sock_recvfrom(s, client_fd, rx_buf, sizeof(rx_buf), 0,
114115
NULL, NULL);
115-
if (ret > 0)
116-
(void)wolfIP_sock_sendto(s, client_fd, rx_buf, (uint32_t)ret, 0,
117-
NULL, 0);
116+
if (ret > 0) {
117+
/* Demo echo: no TX backpressure buffering. If the TX buffer
118+
* is full (EAGAIN) or the write is short, the excess is
119+
* dropped; log it so the drop is visible instead of silent. */
120+
sent = wolfIP_sock_sendto(s, client_fd, rx_buf, (uint32_t)ret,
121+
0, NULL, 0);
122+
if (sent != ret)
123+
printf("echo: TX drop (sent=%d of %d)\r\n", sent, ret);
124+
}
118125
} while (ret > 0);
119126
if (ret == 0) {
120127
wolfIP_sock_close(s, client_fd);

src/port/rtl8735b/tls_client.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,17 @@ static void tls_client_teardown(void)
9292
}
9393
}
9494

95-
/* Enter a terminal state (DONE/ERROR), freeing the SSL object first. */
95+
/* Enter a terminal state (DONE/ERROR): free the SSL object and release the
96+
* socket so the fd is not orphaned if the caller never calls
97+
* tls_client_close(). tls_client_close() then guards on fd >= 0, so its own
98+
* close becomes a safe no-op. */
9699
static void tls_client_finish(tls_client_state_t st)
97100
{
98101
tls_client_teardown();
102+
if (client.fd >= 0 && client.stack) {
103+
wolfIP_sock_close(client.stack, client.fd);
104+
client.fd = -1;
105+
}
99106
client.state = st;
100107
}
101108

src/port/rtl8735b/wolfip_eth.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ set(WOLFIP_PORT_DIR ${WOLFIP_ROOT}/src/port/rtl8735b)
3131
### ---- header search paths (example dir first so our config.h wins) ---- ###
3232
list(APPEND app_example_inc_path
3333
${CMAKE_CURRENT_LIST_DIR} # user_settings.h (this example dir)
34-
${WOLFIP_PORT_DIR} # config.h, rtl8735b_eth.h, tls_client.h
34+
${WOLFIP_PORT_DIR} # config.h, wolfip_rtl8735b.h, tls_client.h
3535
${WOLFIP_ROOT} # wolfip.h
3636
)
3737

src/port/rtl8735b/wolfip_rtl8735b.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ int rtl8735b_eth_init(struct wolfIP_ll_dev *ll, const uint8_t *mac)
189189
if (ll == NULL)
190190
return -1;
191191

192+
/* Release any buffers from a prior init so a re-init does not leak. */
193+
free_eth_bufs();
194+
192195
/* Descriptor rings in reserved SRAM: TX first, RX right after. */
193196
tx_desc = (uint8_t *)__sram_rev_start__;
194197
rx_desc = tx_desc + (RTL8735B_TX_DESC_NO * ETH_TX_DESC_SIZE);

0 commit comments

Comments
 (0)