Obsolete
/
libipc-old
Archived
3
0
Fork 0

timer works as expected

pollfd
Karchnu 2020-07-04 10:11:19 +02:00
parent 3b1aaf36c2
commit f89ab91917
1 changed files with 6 additions and 3 deletions

View File

@ -482,13 +482,16 @@ struct ipc_error ipc_events_loop (struct ipc_ctx *ctx, struct ipc_event *event,
gettimeofday(&tv_2, NULL); gettimeofday(&tv_2, NULL);
int new_timer = *timer - ((tv_2.tv_sec - tv_1.tv_sec) * 1000000 + (tv_2.tv_usec - tv_1.tv_usec)) / 1000; int nb_sec_ms = (tv_2.tv_sec - tv_1.tv_sec) * 1000;
int nb_usec_ms = (tv_2.tv_usec - tv_1.tv_usec) / 1000;
int time_elapsed_ms = (nb_sec_ms + nb_usec_ms);
// Handle memory fuckery, 'cause low level programming is fun. // Handle memory fuckery, 'cause low level programming is fun.
if (new_timer >= *timer || new_timer < 0) { if (time_elapsed_ms >= *timer) {
*timer = 0; *timer = 0;
} }
else { else {
*timer = new_timer; *timer -= time_elapsed_ms;
} }
// Timeout. // Timeout.