Skip to content

Commit f01a971

Browse files
committed
Allow TCP recvfrom in FIN-WAIT states
F/1166
1 parent f7e9f00 commit f01a971

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/test/unit/unit_tests_dns_dhcp.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ START_TEST(test_sock_recvfrom_tcp_states)
154154
struct wolfIP s;
155155
int tcp_sd;
156156
struct tsocket *ts;
157+
uint8_t payload[4] = {1, 2, 3, 4};
157158
uint8_t buf[4];
158159
int ret;
159160

@@ -177,6 +178,20 @@ START_TEST(test_sock_recvfrom_tcp_states)
177178
ts->events = 0;
178179
ret = wolfIP_sock_recvfrom(&s, tcp_sd, buf, sizeof(buf), 0, NULL, 0);
179180
ck_assert_int_eq(ret, -WOLFIP_EAGAIN);
181+
182+
queue_init(&ts->sock.tcp.rxbuf, ts->rxmem, RXBUF_SIZE, 0);
183+
ck_assert_int_eq(queue_insert(&ts->sock.tcp.rxbuf, payload, 0, sizeof(payload)), 0);
184+
ts->sock.tcp.state = TCP_FIN_WAIT_1;
185+
ret = wolfIP_sock_recvfrom(&s, tcp_sd, buf, sizeof(buf), 0, NULL, 0);
186+
ck_assert_int_eq(ret, sizeof(payload));
187+
ck_assert_mem_eq(buf, payload, sizeof(payload));
188+
189+
queue_init(&ts->sock.tcp.rxbuf, ts->rxmem, RXBUF_SIZE, 0);
190+
ck_assert_int_eq(queue_insert(&ts->sock.tcp.rxbuf, payload, 0, sizeof(payload)), 0);
191+
ts->sock.tcp.state = TCP_FIN_WAIT_2;
192+
ret = wolfIP_sock_recvfrom(&s, tcp_sd, buf, sizeof(buf), 0, NULL, 0);
193+
ck_assert_int_eq(ret, sizeof(payload));
194+
ck_assert_mem_eq(buf, payload, sizeof(payload));
180195
}
181196
END_TEST
182197

@@ -3788,4 +3803,3 @@ START_TEST(test_dns_callback_abort_clears_query_state)
37883803
ck_assert_ptr_eq(s.dns_lookup_cb, NULL);
37893804
}
37903805
END_TEST
3791-

src/wolfip.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4563,7 +4563,9 @@ int wolfIP_sock_recvfrom(struct wolfIP *s, int sockfd, void *buf, size_t len, in
45634563
}
45644564
return ret;
45654565
}
4566-
} else if (ts->sock.tcp.state == TCP_ESTABLISHED) {
4566+
} else if (ts->sock.tcp.state == TCP_ESTABLISHED ||
4567+
ts->sock.tcp.state == TCP_FIN_WAIT_1 ||
4568+
ts->sock.tcp.state == TCP_FIN_WAIT_2) {
45674569
uint16_t win_before = tcp_adv_win(ts, 1);
45684570
int ret = queue_pop(&ts->sock.tcp.rxbuf, buf, len);
45694571
if (ret > 0) {

0 commit comments

Comments
 (0)