//select/strcliselect01.c
#include "unp.h"
void
str_cli(FILE *fp,int sockfd)
{
int maxfdp1;
fd_set rset;
char sendline[MAXLINE],recvline[MAXLINE];
FD_ZERO(&rset);
for(; ;)
{
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))
{
if(Readline(sockfd,recvline,MAXLINE) == 0)
err_quit("str_cli:server terminated prematurely");
Fputs(recvline,stdout);
}
if(FD_ISSET(fileno(fp),&rset))
{
if(Fgets(sendline,MAXLINE,fp) == NULL)
return;
Writen(sockfd,sendline,strlen(sendline));
}
}
}
UNIX网络编程学习(13)--使用select的str_cli函数的实现
最新推荐文章于 2020-07-18 19:54:55 发布