zhhyu7 opened a new pull request, #17707:
URL: https://github.com/apache/nuttx/pull/17707
## Summary
support recv packet in the TCP_FIN_WAIT_1/2 state and optimize the handling
of the tcp_event TCP_CLOSE process.
## Impact
tcp receive/shutdown/close.
## Testing
sim:matter with test code:
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <signal.h>
#include <poll.h>
#define SERVER_IP "10.0.1.1"
#define PORT 7777
#define BUFFER_SIZE 1024
int main(int argc, char *argv[]) {
int sockfd;
struct sockaddr_in server_addr;
char buffer[BUFFER_SIZE];
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror("socket creation failed");
exit(EXIT_FAILURE);
}
memset(&server_addr, 0, sizeof(server_addr));
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(PORT);
if (inet_pton(AF_INET, SERVER_IP, &server_addr.sin_addr) <= 0) {
perror("invalid address");
close(sockfd);
exit(EXIT_FAILURE);
}
if (connect(sockfd, (struct sockaddr *)&server_addr,
sizeof(server_addr))) {
perror("connection failed");
close(sockfd);
exit(EXIT_FAILURE);
}
printf("Connected to server %s:%d\n", SERVER_IP, PORT);
shutdown(sockfd, SHUT_WR);
recv(sockfd, buffer, BUFFER_SIZE, 0);
printf("time: %ld Received: %s\n", time(NULL), buffer);
recv(sockfd, buffer, BUFFER_SIZE, 0);
printf("time: %ld Received: %s\n", time(NULL), buffer);
recv(sockfd, buffer, BUFFER_SIZE, 0);
printf("time: %ld Received: %s\n", time(NULL), buffer);
sleep(2);
close(sockfd);
return 0;
}
```
NuttX log:
```
NuttShell (NSH) NuttX-12.12.0-RC0
MOTD: username=admin password=Administrator
nsh> hello
Connected to server 10.0.1.1:7777
time: 1212278848 Received: hello0
time: 1212278849 Received: hello1
time: 1212278851 Received: hello2
nsh>
```
tcpdump log:
```
10:47:34.995432 IP 10.0.1.2.15151 >
zhhyu-HP-Pro-Tower-480-G9-PCI-Desktop-PC.7777: Flags [S], seq 1282192174, win
16384, options [mss 1460], length 0
10:47:34.995559 IP zhhyu-HP-Pro-Tower-480-G9-PCI-Desktop-PC.7777 >
10.0.1.2.15151: Flags [S.], seq 3092689854, ack 1282192175, win 64240, options
[mss 1460], length 0
10:47:34.995668 IP 10.0.1.2.15151 >
zhhyu-HP-Pro-Tower-480-G9-PCI-Desktop-PC.7777: Flags [.], ack 1, win 16384,
length 0
10:47:34.995882 IP zhhyu-HP-Pro-Tower-480-G9-PCI-Desktop-PC.7777 >
10.0.1.2.15151: Flags [P.], seq 1:7, ack 1, win 64240, length 6
10:47:34.995890 IP 10.0.1.2.15151 >
zhhyu-HP-Pro-Tower-480-G9-PCI-Desktop-PC.7777: Flags [F.], seq 1, ack 1, win
16384, length 0
10:47:34.995994 IP 10.0.1.2.15151 >
zhhyu-HP-Pro-Tower-480-G9-PCI-Desktop-PC.7777: Flags [.], ack 7, win 16378,
length 0
10:47:34.996020 IP zhhyu-HP-Pro-Tower-480-G9-PCI-Desktop-PC.7777 >
10.0.1.2.15151: Flags [.], ack 2, win 64239, length 0
10:47:35.996056 IP zhhyu-HP-Pro-Tower-480-G9-PCI-Desktop-PC.7777 >
10.0.1.2.15151: Flags [P.], seq 7:13, ack 2, win 64239, length 6
10:47:36.005036 IP 10.0.1.2.15151 >
zhhyu-HP-Pro-Tower-480-G9-PCI-Desktop-PC.7777: Flags [.], ack 13, win 16384,
length 0
10:47:37.996382 IP zhhyu-HP-Pro-Tower-480-G9-PCI-Desktop-PC.7777 >
10.0.1.2.15151: Flags [P.], seq 13:19, ack 2, win 64239, length 6
10:47:38.005139 IP 10.0.1.2.15151 >
zhhyu-HP-Pro-Tower-480-G9-PCI-Desktop-PC.7777: Flags [.], ack 19, win 16384,
length 0
10:47:38.996588 IP zhhyu-HP-Pro-Tower-480-G9-PCI-Desktop-PC.7777 >
10.0.1.2.15151: Flags [F.], seq 19, ack 2, win 64239, length 0
10:47:39.005047 IP 10.0.1.2.15151 >
zhhyu-HP-Pro-Tower-480-G9-PCI-Desktop-PC.7777: Flags [.], ack 20, win 16384,
length 0
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]