1. 使用read函数返回长度0的情景:对端关闭连接,服务端调用了Close函数。
//intro/daytimetcpcli.c while ((n = read(sockfd, recvline, MAXLINE)) > 0){ recvline[n] = 0; if (fputs(recvline, stdout) == EOF) err_sys("fputs error"); } if (n < 0) err_sys("read error"); /*-------------------------------------------------------------*/ //intro/daytimetcpsrv.c for ( ; ; ) { connfd = Accept(listenfd, (SA *) NULL, NULL); ticks = time(NULL); snprintf(buff, sizeof(buff), "%.24s\r\n", ctime(&ticks)); Write(connfd, buff, strlen(buff)); Close(connfd); }
时间: 2024-10-10 17:36:40