- ret = GNUNET_NETWORK_socket_recv (sh->sock, buffer, sh->max);
- if (ret == -1)
- {
- if (errno == EINTR)
- goto RETRY;
-#if DEBUG_CONNECTION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Error receiving: %s\n", STRERROR (errno));
-#endif
- signal_error (sh, errno);
- return;
- }
-#if DEBUG_CONNECTION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "receive_ready read %u/%u bytes from `%s' (%p)!\n",
- (unsigned int) ret,
- sh->max, GNUNET_a2s (sh->addr, sh->addrlen), sh);
-#endif
- GNUNET_assert (NULL != (receiver = sh->receiver));
- sh->receiver = NULL;
- receiver (sh->receiver_cls, buffer, ret, sh->addr, sh->addrlen, 0);
-}
-
-
-/**
- * This function is called after establishing a connection either has
- * succeeded or timed out. Note that it is possible that the attempt
- * timed out and that we're immediately retrying. If we are retrying,
- * we need to wait again (or timeout); if we succeeded, we need to
- * wait for data (or timeout).
- *
- * @param cls our connection handle
- * @param tc task context describing why we are here
- */
-static void
-receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- struct GNUNET_CONNECTION_Handle *sh = cls;
- struct GNUNET_TIME_Absolute now;
-
- sh->read_task = GNUNET_SCHEDULER_NO_TASK;
- if (sh->sock == NULL)
- {
- /* not connected and no longer trying */
-#if DEBUG_CONNECTION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receive encounters error, socket closed (%p)...\n", sh);
-#endif
- signal_error (sh, ECONNREFUSED);
- return;
- }
- now = GNUNET_TIME_absolute_get ();
- if ((now.abs_value > sh->receive_timeout.abs_value) ||
- (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)))
- {
-#if DEBUG_CONNECTION
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Receive encounters error: time out (%p)...\n", sh);
-#endif
- signal_timeout (sh);
- return;
- }
- GNUNET_assert (sh->sock != NULL);
- /* connect succeeded, wait for data! */
- sh->read_task = GNUNET_SCHEDULER_add_read_net (tc->sched,
- GNUNET_TIME_absolute_get_remaining
- (sh->receive_timeout),
- sh->sock,
- &receive_ready, sh);
+ ret = GNUNET_NETWORK_socket_recv (connection->sock,
+ buffer,
+ connection->max);
+ if (-1 == ret)
+ {
+ if (EINTR == errno)
+ goto RETRY;
+ signal_receive_error (connection, errno);
+ return;
+ }
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "receive_ready read %u/%u bytes from `%s' (%p)!\n",
+ (unsigned int) ret,
+ connection->max,
+ GNUNET_a2s (connection->addr,
+ connection->addrlen),
+ connection);
+ GNUNET_assert (NULL != (receiver = connection->receiver));
+ connection->receiver = NULL;
+ receiver (connection->receiver_cls,
+ buffer,
+ ret,
+ connection->addr,
+ connection->addrlen,
+ 0);