current_time=timeval_ms();
        last_time=current_time;
 }
+
+/* if we sleep for extended periods of time, we must invoke keep_alive() intermittantly */
+void alive_sleep(int ms)
+{
+       int i;
+       for (i=0; i<ms; i+=500)
+       {
+               int sleep_a_bit=ms-i;
+               if (sleep_a_bit>500)
+               {
+                       sleep_a_bit=500;
+               }
+               keep_alive();
+               usleep(sleep_a_bit*1000);
+               keep_alive();
+       }
+}
 
 extern int set_log_output(struct command_context_s *cmd_ctx, FILE *output);
 extern void keep_alive(void);
 extern void kept_alive(void);
+extern void alive_sleep(int ms);
 
 typedef void (*log_callback_fn)(void *priv, const char *file, int line,
                const char *function, const char *string);