本文介绍了如何获得由select()监视的文件描述符准备就绪的时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的C程序使用 TCP套接字进行通信.

My C program uses TCP socket for communication.

我正在使用迭代服务器和select()来监听监视多个文件描述符;每个客户端一个TCP套接字文件描述符.

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?

该应用程序适用于linux平台.

The application is for a linux platform.

应用程序类似于:

我有一组文件描述符{fd1,fd2,... fdN}

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.*/

请注意,由于需要花费 t 个单位来处理文件描述符,因此集合 S中的两个文件描述符的 ready time 之间的最大差值可以是 t 个单位.

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.

我想知道如何获取文件描述符准备就绪的时间戳.

推荐答案

文件描述符准备就绪的时间戳是文件描述符的修改时间.换句话说,文件描述符所代表的文件的最后修改时间.

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.

可以使用fstat()方法获得文件的修改时间(由文件描述符表示).阅读 http://pubs.opengroup.org/onlinepubs/009695399/functions/fstat. html 了解详情.

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.

这篇关于如何获得由select()监视的文件描述符准备就绪的时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 21:08