Edit
My primary goal was to just flush a readable file descriptor after select()
notified incoming data. This goal is achieved for me now by just providing read()
with a big enough buffer as pointed out by Basile Starynkevitch. This is why I mark this answer accepted.
The question in the title is not answered yet though: how do I get the minimum number of bytes I can read from a file descriptor like this:
min_size = fd_get_chunksize(file_descriptor);
which might return 1, 4, 8 or something else.
Original Question
I have a couple of file descriptors created in different ways. E.g. with timerfd_create()
and configured it to fire once a second.
When select()
signals traffic on a certain FD I want to flush it. For the ones created with timerfd_create()
I have to read 8 bytes minimum:
if(select(fd + 1, &l_fdsRd, NULL, NULL, &l_timeOut)) {
unsigned long long data;
int count;
while((count = read (fd, &data, sizeof(data))) > 0) {
printf("%d %ld\n", count, data);
}
}
When data
is declared as char
and thus sizeof(data) is 1, count
is always 0
and my file descriptor never gets flushed.
In case I have more than one file descriptor to flush (maybe created differently) I have to know the number of bytes for every file descriptor I have to read to flush it.
Is there a way to get this amount of bytes for an existing FD?
Is there another way to flush a file descriptor I've created with timerfd_create()
? (I read Empty or "flush" a file descriptor without read()? but this gave me no answer..)
Actually I don't want to read the content but just want to make it ready for select()
again.