1 #include "unp.h"
2
3 void
str_cli(FILE * fp,int sockfd)4 str_cli(FILE *fp, int sockfd)
5 {
6 int maxfdp1;
7 fd_set rset;
8 char sendline[MAXLINE], recvline[MAXLINE];
9
10 FD_ZERO(&rset);
11 for ( ; ; ) {
12 FD_SET(fileno(fp), &rset);
13 FD_SET(sockfd, &rset);
14 maxfdp1 = max(fileno(fp), sockfd) + 1;
15 Select(maxfdp1, &rset, NULL, NULL, NULL);
16
17 if (FD_ISSET(sockfd, &rset)) { /* socket is readable */
18 if (Readline(sockfd, recvline, MAXLINE) == 0)
19 err_quit("str_cli: server terminated prematurely");
20 Fputs(recvline, stdout);
21 }
22
23 if (FD_ISSET(fileno(fp), &rset)) { /* input is readable */
24 if (Fgets(sendline, MAXLINE, fp) == NULL)
25 return; /* all done */
26 Writen(sockfd, sendline, strlen(sendline));
27 }
28 }
29 }
30