How do I compare two timestamps in C?

前端 未结 4 849
感情败类
感情败类 2020-12-29 10:03

I\'m writing a socket program that maintains FIFO queues for two input sockets. When deciding which queue to service, the program pulls the most recent time-stamp from each

4条回答
  •  清歌不尽
    2020-12-29 10:36

    For viewing timevals I just whipped this up. It returns a timeval as a string that you can print or send to a text file:

    char *tv2str(struct timeval *intv) {
      static char ans[200];
      snprintf(ans,200,"%u.%u",(unsigned int)intv->tv_sec, \
        (unsigned int) intv->tv_usec);
      return ans;
    }
    

    Use like:

    printf("nowtv: %s\n",tv2str(&nowtv));
    

    nowtv: 1568407554.646623

    Timercmp() didn't seem to work right so I wanted a way to check up on it by actually looking at some values.

提交回复
热议问题