- if ((string == NULL) || (!first))
- {
- size = size * 2 + 2;
- char *t = string;
- string = realloc(string, size);
- if (string == NULL)
- {
- if (t != NULL)
- free(t);
- return NULL;
- }
- }
-
- int ret;
- ret = vsnprintf(string, size, fmt, ap);
- /* NB! The result of the vsnprintf() might be an *EMPTY* string! */
- if ((ret >= 0) && ((ret + 1) < size))
- {
- return string;
- }
- /* there was just enough or not enough space, allocate more. */
- first = 0;
+ extern int gdb_actual_connections;
+
+ if (gdb_actual_connections)
+ LOG_WARNING("keep_alive() was not invoked in the "
+ "1000ms timelimit. GDB alive packet not "
+ "sent! (%lld). Workaround: increase "
+ "\"set remotetimeout\" in GDB",
+ current_time-last_time);
+ else
+ LOG_DEBUG("keep_alive() was not invoked in the "
+ "1000ms timelimit (%lld). This may cause "
+ "trouble with GDB connections.",
+ current_time-last_time);
+ }
+ if (current_time-last_time > 500)
+ {
+ /* this will keep the GDB connection alive */
+ LOG_USER_N("%s", "");
+
+ /* DANGER!!!! do not add code to invoke e.g. target event processing,
+ * jim timer processing, etc. it can cause infinite recursion +
+ * jim event callbacks need to happen at a well defined time,
+ * not anywhere keep_alive() is invoked.
+ *
+ * These functions should be invoked at a well defined spot in server.c
+ */
+
+ last_time = current_time;
+ }
+}
+
+/* reset keep alive timer without sending message */
+void kept_alive()
+{
+ 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(uint64_t ms)
+{
+ uint64_t napTime = 10;
+ for (uint64_t i = 0; i < ms; i += napTime)
+ {
+ uint64_t sleep_a_bit = ms - i;
+ if (sleep_a_bit > napTime)
+ sleep_a_bit = napTime;
+
+ usleep(sleep_a_bit * 1000);
+ keep_alive();
+ }
+}
+
+void busy_sleep(uint64_t ms)
+{
+ uint64_t then = timeval_ms();
+ while (timeval_ms() - then < ms)
+ {
+ /* busy wait */