*/
struct GNUNET_CLIENT_TransmitHandle *th;
+ /**
+ * Task to trigger reconnect.
+ */
+ GNUNET_SCHEDULER_TaskIdentifier task;
+
};
reconnect (struct GNUNET_ATS_PerformanceHandle *ph);
+/**
+ * Re-establish the connection to the ATS service.
+ *
+ * @param cls handle to use to re-connect.
+ * @param tc scheduler context
+ */
+static void
+reconnect_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct GNUNET_ATS_PerformanceHandle *ph = cls;
+
+ ph->task = GNUNET_SCHEDULER_NO_TASK;
+ reconnect (ph);
+}
+
+
/**
* Transmit messages from the message queue to the service
* (if there are any, and if we are not already trying).
struct GNUNET_ATS_PerformanceHandle *ph = cls;
if (NULL == msg)
- {
- GNUNET_CLIENT_disconnect (ph->client, GNUNET_NO);
- ph->client = NULL;
- reconnect (ph);
- return;
- }
+ goto reconnect;
switch (ntohs (msg->type))
{
case GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION:
if (GNUNET_OK != process_pi_message (ph, msg))
- {
- GNUNET_CLIENT_disconnect (ph->client, GNUNET_NO);
- ph->client = NULL;
- reconnect (ph);
- return;
- }
+ goto reconnect;
break;
case GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT:
if (GNUNET_OK != process_rr_message (ph, msg))
- {
- GNUNET_CLIENT_disconnect (ph->client, GNUNET_NO);
- ph->client = NULL;
- reconnect (ph);
- return;
- }
+ goto reconnect;
break;
default:
GNUNET_break (0);
- GNUNET_CLIENT_disconnect (ph->client, GNUNET_NO);
- ph->client = NULL;
- reconnect (ph);
+ goto reconnect;
return;
}
GNUNET_CLIENT_receive (ph->client,
&process_ats_message, ph,
GNUNET_TIME_UNIT_FOREVER_REL);
+ return;
+ reconnect:
+ GNUNET_CLIENT_disconnect (ph->client, GNUNET_NO);
+ ph->client = NULL;
+ ph->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+ &reconnect_task, ph);
}
GNUNET_break (NULL == rc->rcb);
GNUNET_free (p);
}
+ if (GNUNET_SCHEDULER_NO_TASK != ph->task)
+ {
+ GNUNET_SCHEDULER_cancel (ph->task);
+ ph->task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_CLIENT_disconnect (ph->client, GNUNET_NO);
GNUNET_free (ph);
}