My C program uses TCP socket for communication.
I am using an iterative server and select()
to listen for monitoring multiple file descriptors; one TCP socket file descriptor for each client.
Is there a method, using which I can figure out when did a file descriptor become ready?
The application is for a linux platform.
The application is like:
I have a set of file descriptors {fd1, fd2, ... fdN}
while (True)
S <-- select (fd1, fd2, ... fdN) // Set S contains the ready fds
S = {fd1, fd2, fd3}.
/* Say only the file descriptors fd1, fd2 and fd3 are ready.
* I want to process in FIFO order.
* Hence, I need timestamp at which a file descriptor became ready.*/
process (S) /* It may take 2-3 minutes. Which is not negligible.
* Say t units for generalization.*/
Note that in the since it takes t units to process the file descriptors, the maximum difference between the ready time of two file descriptors in the set S can be t units.
Hence, the time at which a file descriptor became ready becomes important.
And I want to know how to obtain the timestamp at which a file descriptor became ready.
The timestamp at which a file descriptor becomes ready is the modification time of the file descriptor. Or in other words, the time at which the file represented by the file descriptor was last modified.
The modification time of a file (represented by a file descriptor) can be obtained using the fstat() method. Read http://pubs.opengroup.org/onlinepubs/009695399/functions/fstat.html for details.