very hostile.....thanks for the help?
Printable View
I would suggest you look at using open() and read(), as opposed to the standard fopen/fread approach. You'll have a lot more scope for controlling what is going on, with what is after all rather system specific to begin with.
You also need to put the stream in non-blocking mode. Salem's point is that this is impossible in the first place with fread.
Passing O_NONBLOCK in mode to open() sounds like an option.
As already mentioned - http://www.rt.com/man/fcntl.2.html
tried with the open()/read() and the open with O_NONBLOCK but no luck.
wondering if adding O_NDELAY would help.
You could start another thread to monitor the disks or something? Very OS specific, but so is your problem.
tried with fcntl(), I got passed the read() but then hang on the close(fd).
I'm sure I missed something here. Can someone have a look?
Not that familiar with fcntl()
Code:
int fd_flags = 0;
fd = open(fullpath, O_RDONLY|O_NONBLOCK|O_NDELAY);
if (!fd) {
fprintf(stderr, "ERROR: Can't open device %s
\n",
fullpath);
return 0;
}
fd_flags = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, fd_flags | O_NONBLOCK);
ret = read(fd, buffer, sizeof(buffer));
close(fd);