Reputation: 141
I am trying to do a non blocking read but the function never returns. Can someone suggest something? Here is my code to set nonblocking fd.
from_ap = open(FFS_GBEMU_OUT, O_RDWR|O_NONBLOCK);
if (from_ap < 0)
return from_ap;
I have also tried this with similar results
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");
Here is where I call my read function:
rsize = read(from_ap, cport_rbuf, ES1_MSG_SIZE);
if (rsize < 0) {
printf("error %zd receiving from AP\n", rsize);
return NULL;
}
I have also tried this with similar results:
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);
}
The last message received is "there was something to read" and code does not progress further. What I am doing wrong? This is not a multithreaded program so no one can change flags but I have anyways confirmed them with printing back the flags before reading.
Upvotes: 1
Views: 585
Reputation: 9210
O_NONBLOCK has no effect on regular file paths (and you are using open()
so I assume that's what you're doing).
Upvotes: 0