Update tcp_server.c

Fixed a stackover flow bug.
This commit is contained in:
David Lin
2020-04-12 11:12:24 +08:00
committed by GitHub
parent 8832a6477f
commit 23313e8567

View File

@@ -46,10 +46,15 @@ void application_entry(void *arg)
printf("accpet socket error: %s errno :%d\n",strerror(errno),errno);
continue;
}
n = recv(connfd, buff, sizeof(buff), 0);
buff[n] = '\0';
printf("recv(%d) msg from client:%s\n", ++cnt, buff);
if(n > 0) {
buff[n] = '\0';
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) {
printf("send msg error: %s errno : %d\n", strerror(errno), errno);
break;
@@ -59,4 +64,3 @@ void application_entry(void *arg)
close(listenfd);
}