fixed command timeout
[svn42.git] / door_daemon / command_queue.c
index 7ba22c7..8e6ca2c 100644 (file)
@@ -59,7 +59,6 @@ int cmd_push(cmd_t** first, int fd, cmd_id_t cmd, const char* param)
   new_cmd->sent = 0;
   new_cmd->tv_start.tv_sec = 0;
   new_cmd->tv_start.tv_usec = 0;
-  gettimeofday(&new_cmd->tv_start, NULL);
   new_cmd->next = NULL;
 
   if(!(*first)) {
@@ -72,18 +71,23 @@ int cmd_push(cmd_t** first, int fd, cmd_id_t cmd, const char* param)
   return 0;
 }
 
-// timeout between 1 and 2 seconds
-int cmd_has_expired(const cmd_t cmd)
+void cmd_sent(cmd_t* cmd)
+{
+  if(!cmd)
+    return;
+
+  cmd->sent = 1;
+  gettimeofday(&cmd->tv_start, NULL);
+}
+
+int cmd_has_expired(cmd_t cmd)
 {
   struct timeval now;
-  now.tv_sec = 2;
-  now.tv_usec = 0;
+  timerclear(&now);
   gettimeofday(&now, NULL);
-  
-  if(cmd.tv_start.tv_sec + 2 >= now.tv_sec)
-    return 1;
-  
-  return 0;
+  cmd.tv_start.tv_sec++;
+
+  return timercmp(&cmd.tv_start, &now, <);
 }
 
 void cmd_pop(cmd_t** first)