Merge pull request #135 from DavidLin1577/patch-6
Fixed some stackover flow bugs in tcp_client.c/tcp_server.c
This commit is contained in:
@@ -23,7 +23,11 @@ void application_entry(void *arg)
|
|||||||
MX_LWIP_Init();
|
MX_LWIP_Init();
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
socketfd = socket(AF_INET, SOCK_STREAM, 0);
|
if ((socketfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||||
|
printf("create socket error %s errno: %d\n", strerror(errno), errno);
|
||||||
|
goto tcp_client_exit;
|
||||||
|
}
|
||||||
|
|
||||||
setsockopt(socketfd, SOL_SOCKET, SO_RCVTIMEO, (char*)&tv, sizeof(struct timeval));
|
setsockopt(socketfd, SOL_SOCKET, SO_RCVTIMEO, (char*)&tv, sizeof(struct timeval));
|
||||||
memset(&sockaddr, 0, sizeof(sockaddr));
|
memset(&sockaddr, 0, sizeof(sockaddr));
|
||||||
|
|
||||||
|
@@ -48,8 +48,13 @@ void application_entry(void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
n = recv(connfd, buff, sizeof(buff), 0);
|
n = recv(connfd, buff, sizeof(buff), 0);
|
||||||
|
if(n > 0) {
|
||||||
buff[n] = '\0';
|
buff[n] = '\0';
|
||||||
printf("recv(%d) msg from client:%s\n", ++cnt, buff);
|
printf("recv(%d) msg from client:%s\n", ++cnt, buff);
|
||||||
|
} else {
|
||||||
|
printf("recv err(%d)\n", n);
|
||||||
|
}
|
||||||
|
|
||||||
if ((send(connfd, buff, strlen(buff), 0)) < 0) {
|
if ((send(connfd, buff, strlen(buff), 0)) < 0) {
|
||||||
printf("send msg error: %s errno : %d\n", strerror(errno), errno);
|
printf("send msg error: %s errno : %d\n", strerror(errno), errno);
|
||||||
break;
|
break;
|
||||||
@@ -59,4 +64,3 @@ void application_entry(void *arg)
|
|||||||
|
|
||||||
close(listenfd);
|
close(listenfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user