- 论坛徽章:
- 0
|
我也对这个问题有些不解
那啥时候算是read集合被置位呢?
比如下面的代码
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include "restart.h"
int copy2files(int fromfd1, int tofd1, int fromfd2, int tofd2) {
int bytesread;
int maxfd;
int num;
fd_set readset;
int totalbytes = 0;
maxfd = fromfd1; /* find the biggest fd for select */
if (fromfd2 > maxfd)
maxfd = fromfd2;
for ( ; ; ) {
FD_ZERO(&readset);
FD_SET(fromfd1, &readset);
FD_SET(fromfd2, &readset);
if (((num = select(maxfd+1, &readset, NULL, NULL, NULL)) == -1) &&
(errno == EINTR))
continue;
if (num == -1)
return totalbytes;
if (FD_ISSET(fromfd1, &readset)) {
bytesread = readwrite(fromfd1, tofd1);
if (bytesread <= 0)
break;
totalbytes += bytesread;
}
if (FD_ISSET(fromfd2, &readset)) {
bytesread = readwrite(fromfd2, tofd2);
if (bytesread <= 0)
break;
totalbytes += bytesread;
}
}
return totalbytes;
}
|
在第一次select之前,readset中的两个fd(fromfd1和fromfd2)只是两个被open了的fd,也没执行其他操作,那select具体是在什么条件下成功返回呢?
write集合是在内核缓冲区有空闲空间的时候被成功置位返回,那read集合呢?
谢谢! |
|