This code is not intended to be taken literally! struct event { struct event * next; /* happy doubly-linked list */ struct event * prev; struct timeval when; /* time when the event should fire */ void (*f)(void *); /* callback to invoke at that time */ void *a; /* parameter to hand the callback */ }; struct event *eventlist; struct timeval now, event_time, timeout; gettimeofday ( &now, NULL ); event_time.tv_sec = now.tv_sec + 25 event_time.tv_usec = now.tv_usec boolean timeval_is_less_than( struct timeval *a, struct timeval *b) { blah blah blah. } for(ptr = eventlist; ptr != NULL && [[[ptr-> when < event_time]]]; ptr =ptr-> next); for(ptr = eventlist; ptr != NULL && timeval_is_less_than(&ptr-> when, &event_time); ptr =ptr-> next); if(ptr) { new_event->next = ptr new_event->prev = ptr->prev ptr->prev->next = new_event /* if not null!!! */ ptr->prev = new_event } else { new_event->prev = last; last=new_event; } select_timeout.tv_sec = eventlist -> when.tv_sec - now.tv_sec select_timeout.tv_usec = eventlist -> when.tv_usec - now.tv_usec /* then cleanup the carry */ number_of_ready_filedescriptors = select(........, &select_timeout); /* wait for input on any socket */ FD_SET FD_ISSET gettimeofday(&now, NULL); if ( timeval_is_less_than(&eventlist->when, &now) ) { eventlist->f(eventlist->a); eventlist=eventlist->next; free! }