Hi, I have a C program that do recv/send operations from/to socket using a for(;;) loop and a select() to monitor the file descriptor. I need also this program to send a packet every 80msec to a packet, how can I implement this? Maybe I can use a fork() and the child process simply write an ack in one of the file descriptor monitored by the select() every 80msec. Is there better solutions?
+3
A:
When calling select() you can use the timeout argument to limit the selection waiting time.
struct timeval {
long tv_sec; /* seconds */
long tv_usec; /* microseconds */
};
int select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout);
It is rather easy to limit the timeout to 80msec and send the required packet.
eyalm
2009-10-11 16:23:31
That's cool, where did you learn that this ever existed?
Karl
2009-10-11 16:37:22
The problem is the select() returns several time in 80msec and I can't re utilize the timeval sturct with the remaining time for portability reason (only linux do it right)...
Federico
2009-10-11 16:40:06
@karl: man select :P
Federico
2009-10-11 16:40:54