亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: 請(qǐng)教關(guān)于管道的問(wèn)題 [打印本頁(yè)]

作者: laojing6    時(shí)間: 2010-01-27 11:06
標(biāo)題: 請(qǐng)教關(guān)于管道的問(wèn)題
代碼如下
static char*  do_parent(int* fd,char* buff)
63 {
64     static int index;
65     //FILE*   fp;
66     int read_ret;
67     int sel_fd = -1;
68     fd_set rd_set;
69     struct timeval wait_time;
70     //fp = fdopen(*fd,"r";
71     //if(NULL == fp)
72     //{
73     //  perror("fdopen error!";
74     //  exit(1);
75     //}
76     //setvbuf(fp,buff,_IONBF,12;//set buff
77     //memset(buff,'\0',FORMAT_INFO);
78     wait_time.tv_sec = 0;
79     wait_time.tv_usec = 20000;
80 #if 1
81     sel_fd = *fd;
82     //FD_ZERO(&rd_set);
83     //FD_SET(sel_fd,&rd_set);
84     for(;index < 128;index++)
85     {
86         FD_ZERO(&rd_set); FD_SET(sel_fd,&rd_set);
88         if( 0 < select(sel_fd+1,&rd_set,NULL,NULL,&wait_time))
89         {
90             if(FD_ISSET(sel_fd,&rd_set))
91             {
92                 //printf("=== are you see me?=========\n";
93                 read_ret = read(sel_fd,&buff[index],1);
94                 if( 1 == read_ret)
95                 {
96                     printf("buff[index] :%c\n",buff[index]);
97                     if(('\n' == buff[index]) || (NULL != strstr(buff,"Creating journal"))
98                     {
99                         index = 0;
100                         printf("length of buff:%d, buff:%s",strlen(buff),buff);
101                         return buff;
102                     }
103                 }
104                 else
105                 {
106                     printf("read_ret :%d\n",read_ret);
107                     //printf("~~~~~~should not see me~~~~~~\n";
108                     //index = 0;
109                     break;
110                 }
111                         //printf("length of buff:%d, buff:%s",strlen(buff),buff);
112             }
113         }
114      }
115 #endif
116 //      fclose(fp);
117 //      return buff;
118 }
                           代碼中用了select來(lái)判斷有沒(méi)有內(nèi)容可讀,但是很奇怪的 是沒(méi)有內(nèi)容可讀的 時(shí)候select一直都是正常返回的 if(FD_ISSET(sel_fd,&rd_set))也能檢測(cè)到可讀,但是用read的話就連一個(gè)字符都讀不到,很郁悶。大俠幫看看,其中fd是管道的描述符




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2