标签:tin color stdout shu socket select oid isset turn
void str_cli(FILE *fp, int sockfd) { int maxfdp1, stdineof; fd_set rset; char buf[MAXLINE]; int n; stdineof = 0; FD_SET(&rset); for ( ; ; ) { if (stdineof == 0) { FD_SET(fileno(fp), &rset); } FD_SET(sockfd, &rset); maxfdp1 = max(fileno(fp), sockfd) + 1; select(maxfdp1, &rset, NULL, NULL, NULL); if (FD_ISSET(sockfd, *rset)) { /* socket is readable */ if ( (n = read(sockfd, recvline, MAXLINE)) == 0) { if (stdineof == 1) { return; } else { exit(1); } } write(fileno(stdout), buf, n); } if (FD_ISSET(fileno(fp), &rset)) { /* inout is readable */ if ( (n = read(fileno(fp), buf, MAXLINE)) == 0) { stdineof = 1; shutdown(sockfd, SHUT_WR); /* send FIN */ FD_CLR(fileno(fp), &rset); continue; } writen(sockfd, buf, n); } } }
标签:tin color stdout shu socket select oid isset turn
原文地址:https://www.cnblogs.com/soldierback/p/10700791.html