1 /* use TCP acks to measure lag. Call this after sending critcal data
2 and it will return the number of milliseconds it took for all the
3 data to be acknowledged by the clients TCP stack
5 this is very CPU intensive, for a real application you would need
6 to do this in a timer or at least yield between ioctl() calls
8 -1 is returned on error
10 int measure_lag(int fd)
12 struct timeval tv1, tv2;
16 #define TIOCOUTQ 0x5411
19 if (gettimeofday(&tv1, NULL) != 0) {
23 while (ioctl(fd, TIOCOUTQ, &outq) == 0 && outq != 0) ;
25 if (gettimeofday(&tv2, NULL) != 0) {
29 return (tv2.tv_sec - tv1.tv_sec) * 1000 +
30 (tv2.tv_usec - tv1.tv_usec) / 1000;