size_t ret;
struct GNUNET_TIME_Relative delay;
+ th->th = NULL;
if (buf == NULL)
{
delay = GNUNET_TIME_absolute_get_remaining (th->timeout);
/* auto-retry */
GNUNET_CONNECTION_destroy (th->sock->sock);
th->sock->sock = NULL;
- th->th = NULL;
delay = GNUNET_TIME_relative_min (delay, GNUNET_TIME_UNIT_SECONDS);
th->task = GNUNET_SCHEDULER_add_delayed (th->sock->sched,
GNUNET_NO,
GNUNET_CLIENT_notify_transmit_ready_cancel (struct GNUNET_CLIENT_TransmitHandle *th)
{
if (th->task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (th->sock->sched,
- th->task);
+ {
+ GNUNET_break (NULL == th->th);
+ GNUNET_SCHEDULER_cancel (th->sock->sched,
+ th->task);
+ }
else
{
GNUNET_break (NULL != th->th);
}
+/**
+ * Task invoked by the scheduler when we failed to connect
+ * at the time of being asked to transmit.
+ *
+ * This task notifies the client about the error.
+ */
+static void
+connect_error (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct GNUNET_CONNECTION_Handle *sock = cls;
+ GNUNET_CONNECTION_TransmitReadyNotify notify;
+
+#if DEBUG_CONNECTION
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmission request of size %u fails, connection failed (%p).\n",
+ sock->nth.notify_size,
+ sock);
+#endif
+ sock->write_task = GNUNET_SCHEDULER_NO_TASK;
+ notify = sock->nth.notify_ready;
+ sock->nth.notify_ready = NULL;
+ notify (sock->nth.notify_ready_cls, 0, NULL);
+}
+
+
static void
transmit_error (struct GNUNET_CONNECTION_Handle *sock)
{
return NULL;
GNUNET_assert (notify != NULL);
GNUNET_assert (sock->write_buffer_size >= size);
-
- if ( (sock->sock == NULL) &&
- (sock->ap_head == NULL) &&
- (sock->dns_active != GNUNET_YES) )
- {
-#if DEBUG_CONNECTION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Transmission request of size %u fails, connection failed (%p).\n",
- size,
- sock);
-#endif
- notify (notify_cls, 0, NULL);
- return &sock->nth;
- }
GNUNET_assert (sock->write_buffer_off <= sock->write_buffer_size);
GNUNET_assert (sock->write_buffer_pos <= sock->write_buffer_size);
GNUNET_assert (sock->write_buffer_pos <= sock->write_buffer_off);
sock->nth.notify_size = size;
sock->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout);
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->nth.timeout_task);
+ if ( (sock->sock == NULL) &&
+ (sock->ap_head == NULL) &&
+ (sock->dns_active != GNUNET_YES) )
+ {
+ sock->write_task = GNUNET_SCHEDULER_add_delayed (sock->sched,
+ GNUNET_NO,
+ GNUNET_SCHEDULER_PRIORITY_KEEP,
+ GNUNET_SCHEDULER_NO_TASK,
+ GNUNET_TIME_UNIT_ZERO,
+ &connect_error,
+ sock);
+ return &sock->nth;
+ }
if (GNUNET_SCHEDULER_NO_TASK != sock->write_task)
return &sock->nth;
if (sock->sock != NULL)