![](/img/trans.png)
[英]Linux named fifo non-blocking read select returns bogus read_fds
[英]Non blocking read never returns
我正在嘗試進行非阻塞讀取,但是該函數永不返回。 有人可以建議嗎? 這是我設置非阻塞fd的代碼。
from_ap = open(FFS_GBEMU_OUT, O_RDWR|O_NONBLOCK);
if (from_ap < 0)
return from_ap;
我也嘗試過類似的結果
from_ap = open(FFS_GBEMU_OUT, O_RDWR);
int status = fcntl(from_ap, F_SETFL, fcntl(from_ap, F_GETFL, 0) | O_NONBLOCK);
if (status == -1){
perror("calling fcntl");
這是我調用讀取函數的地方:
rsize = read(from_ap, cport_rbuf, ES1_MSG_SIZE);
if (rsize < 0) {
printf("error %zd receiving from AP\n", rsize);
return NULL;
}
我也嘗試過類似的結果:
fd_set readset;
struct timeval tv;
FD_ZERO(&readset);
FD_SET(from_ap, &readset);
tv.tv_sec = 0;
tv.tv_usec = 100;
result = select(from_ap+1, &readset, NULL, NULL, &tv);
if (result > 0 && FD_ISSET(from_ap, &readset)){
printf("there was something to read\n");
rsize=read(from_ap,cport_rbuf,ES1_MSG_SIZE);
}
收到的最后一條消息是“有一些東西要閱讀”,並且代碼沒有進一步進行。 我做錯了什么? 這不是一個多線程程序,因此沒有人可以更改標志,但是無論如何,我還是在閱讀之前通過打印回標志來確認它們。
設備是否支持O_NONBLOCK? 這似乎是來自GitHub的gbsim代碼。 在gbsim上閱讀,驅動程序很可能不支持非阻塞調用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.