From 4071d1862fdcd9389e990784d0ea1fb9c4651f0f Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 19 Apr 2012 11:22:20 +0000 Subject: [PATCH] -rename fest in connection.c --- src/include/gnunet_connection_lib.h | 85 ++- src/util/client.c | 22 +- src/util/connection.c | 795 ++++++++++++++-------------- src/util/server.c | 6 +- 4 files changed, 454 insertions(+), 454 deletions(-) diff --git a/src/include/gnunet_connection_lib.h b/src/include/gnunet_connection_lib.h index 7f74de59e..5c9ead95e 100644 --- a/src/include/gnunet_connection_lib.h +++ b/src/include/gnunet_connection_lib.h @@ -109,10 +109,10 @@ typedef void (*GNUNET_CONNECTION_Receiver) (void *cls, const void *buf, * that the underlying socket or fd should never really be closed. * Used for indicating process death. * - * @param sock the connection to set persistent + * @param connection the connection to set persistent */ void -GNUNET_CONNECTION_persist_ (struct GNUNET_CONNECTION_Handle *sock); +GNUNET_CONNECTION_persist_ (struct GNUNET_CONNECTION_Handle *connection); /** * Disable the "CORK" feature for communication with the given socket, @@ -122,17 +122,17 @@ GNUNET_CONNECTION_persist_ (struct GNUNET_CONNECTION_Handle *sock); * Used to make sure that the last messages sent through the connection * reach the other side before the process is terminated. * - * @param sock the connection to make flushing and blocking + * @param connection the connection to make flushing and blocking * @return GNUNET_OK on success */ int -GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *sock); +GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *connection); /** - * Create a socket handle by boxing an existing OS socket. The OS + * Create a connection handle by boxing an existing OS socket. The OS * socket should henceforth be no longer used directly. - * GNUNET_socket_destroy will close it. + * GNUNET_CONNECTION_destroy will close it. * * @param osSocket existing socket to box * @return the boxed socket handle @@ -142,13 +142,13 @@ GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle *osSocket); /** - * Create a socket handle by accepting on a listen socket. This + * Create a connection handle by accepting on a listen socket. This * function may block if the listen socket has no connection ready. * * @param access function to use to check if access is allowed * @param access_cls closure for access * @param lsock listen socket - * @return the socket handle, NULL on error (for example, access refused) + * @return the connection handle, NULL on error (for example, access refused) */ struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access, @@ -157,14 +157,14 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access, /** - * Create a socket handle by (asynchronously) connecting to a host. + * Create a connection handle by (asynchronously) connecting to a host. * This function returns immediately, even if the connection has not * yet been established. This function only creates TCP connections. * * @param cfg configuration to use * @param hostname name of the host to connect to * @param port port to connect to - * @return the socket handle + * @return the connection handle */ struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle @@ -173,13 +173,13 @@ GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle /** - * Create a socket handle by connecting to a UNIX domain service. + * Create a connection handle by connecting to a UNIX domain service. * This function returns immediately, even if the connection has not * yet been established. This function only creates UNIX connections. * * @param cfg configuration to use * @param unixpath path to connect to) - * @return the socket handle, NULL on systems without UNIX support + * @return the connection handle, NULL on systems without UNIX support */ struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct @@ -190,14 +190,14 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct /** - * Create a socket handle by (asynchronously) connecting to a host. + * Create a connection handle by (asynchronously) connecting to a host. * This function returns immediately, even if the connection has not * yet been established. This function only creates TCP connections. * * @param af_family address family to use * @param serv_addr server address * @param addrlen length of server address - * @return the socket handle + * @return the connection handle */ struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_sockaddr (int af_family, @@ -205,79 +205,78 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family, socklen_t addrlen); /** - * Check if socket is valid (no fatal errors have happened so far). - * Note that a socket that is still trying to connect is considered + * Check if connection is valid (no fatal errors have happened so far). + * Note that a connection that is still trying to connect is considered * valid. * - * @param sock socket to check + * @param connection handle to check * @return GNUNET_YES if valid, GNUNET_NO otherwise */ int -GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock); +GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection); /** * Obtain the network address of the other party. * - * @param sock the client to get the address for + * @param connection the client to get the address for * @param addr where to store the address * @param addrlen where to store the length of the address * @return GNUNET_OK on success */ int -GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *sock, +GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *connection, void **addr, size_t * addrlen); /** - * Close the socket and free associated resources. Pending - * transmissions may be completed or dropped depending on the - * arguments. If a receive call is pending and should - * NOT be completed, 'GNUNET_CONNECTION_receive_cancel' - * should be called explicitly first. + * Close the connection and free associated resources. A pending + * request for transmission is automatically cancelled (we might + * want to change this in the future). We require that there + * are no active pending requests for reading from the connection. * - * @param sock socket to destroy + * @param connection connection to destroy */ void -GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock); +GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection); /** - * Receive data from the given socket. Note that this function will + * Receive data from the given connection. Note that this function will * call "receiver" asynchronously using the scheduler. It will * "immediately" return. Note that there MUST only be one active - * receive call per socket at any given point in time (so do not + * receive call per connection at any given point in time (so do not * call receive again until the receiver callback has been invoked). * - * @param sock socket handle + * @param connection connection handle * @param max maximum number of bytes to read * @param timeout maximum amount of time to wait * @param receiver function to call with received data * @param receiver_cls closure for receiver */ void -GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock, size_t max, +GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection, size_t max, struct GNUNET_TIME_Relative timeout, GNUNET_CONNECTION_Receiver receiver, void *receiver_cls); /** - * Cancel receive job on the given socket. Note that the + * Cancel receive job on the given connection. Note that the * receiver callback must not have been called yet in order * for the cancellation to be valid. * - * @param sock socket handle + * @param connection connection handle * @return closure of the original receiver callback closure */ void * -GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *sock); +GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *connection); /** - * Function called to notify a client about the socket + * Function called to notify a client about the connection * begin ready to queue more data. "buf" will be - * NULL and "size" zero if the socket was closed for + * NULL and "size" zero if the connection was closed for * writing in the meantime. * * @param cls closure @@ -296,17 +295,17 @@ typedef size_t (*GNUNET_CONNECTION_TransmitReadyNotify) (void *cls, size_t size, struct GNUNET_CONNECTION_TransmitHandle; /** - * Ask the socket to call us once the specified number of bytes + * Ask the connection to call us once the specified number of bytes * are free in the transmission buffer. May call the notify * method immediately if enough space is available. Note that * this function will abort if "size" is greater than * GNUNET_SERVER_MAX_MESSAGE_SIZE. * * Note that "notify" will be called either when enough - * buffer space is available OR when the socket is destroyed. + * buffer space is available OR when the connection is destroyed. * The size parameter given to notify is guaranteed to be * larger or equal to size if the buffer is ready, or zero - * if the socket was destroyed (or at least closed for + * if the connection was destroyed (or at least closed for * writing). Finally, any time before 'notify' is called, a * client may call "notify_transmit_ready_cancel" to cancel * the transmission request. @@ -315,7 +314,7 @@ struct GNUNET_CONNECTION_TransmitHandle; * time. Notify will be run with the same scheduler priority * as that of the caller. * - * @param sock socket + * @param connection connection * @param size number of bytes to send * @param timeout after how long should we give up (and call * notify with buf NULL and size 0)? @@ -325,7 +324,7 @@ struct GNUNET_CONNECTION_TransmitHandle; * NULL if we are already going to notify someone else (busy) */ struct GNUNET_CONNECTION_TransmitHandle * -GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *sock, +GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connection, size_t size, struct GNUNET_TIME_Relative timeout, GNUNET_CONNECTION_TransmitReadyNotify @@ -347,11 +346,11 @@ GNUNET_CONNECTION_notify_transmit_ready_cancel (struct /** * Configure this connection to ignore shutdown signals. * - * @param sock socket handle + * @param connection connection handle * @param do_ignore GNUNET_YES to ignore, GNUNET_NO to restore default */ void -GNUNET_CONNECTION_ignore_shutdown (struct GNUNET_CONNECTION_Handle *sock, +GNUNET_CONNECTION_ignore_shutdown (struct GNUNET_CONNECTION_Handle *connection, int do_ignore); diff --git a/src/util/client.c b/src/util/client.c index f6bc27381..aa80d6b72 100644 --- a/src/util/client.c +++ b/src/util/client.c @@ -943,11 +943,12 @@ static size_t client_notify (void *cls, size_t size, void *buf) { struct GNUNET_CLIENT_TransmitHandle *th = cls; + struct GNUNET_CLIENT_Connection *sock = th->sock; size_t ret; struct GNUNET_TIME_Relative delay; th->th = NULL; - th->sock->th = NULL; + sock->th = NULL; if (buf == NULL) { delay = GNUNET_TIME_absolute_get_remaining (th->timeout); @@ -967,19 +968,24 @@ client_notify (void *cls, size_t size, void *buf) /* auto-retry */ LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect to `%s', automatically trying again.\n", - th->sock->service_name); - GNUNET_CONNECTION_destroy (th->sock->sock); - th->sock->sock = NULL; - delay = GNUNET_TIME_relative_min (delay, th->sock->back_off); - th->sock->back_off = + sock->service_name); + if (sock->in_receive == GNUNET_YES) + { + GNUNET_CONNECTION_receive_cancel (sock->sock); + sock->in_receive = GNUNET_NO; + } + GNUNET_CONNECTION_destroy (sock->sock); + sock->sock = NULL; + delay = GNUNET_TIME_relative_min (delay, sock->back_off); + sock->back_off = GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply - (th->sock->back_off, 2), + (sock->back_off, 2), GNUNET_TIME_UNIT_SECONDS); LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmission failed %u times, trying again in %llums.\n", MAX_ATTEMPTS - th->attempts_left, (unsigned long long) delay.rel_value); - th->sock->th = th; + sock->th = th; th->reconnect_task = GNUNET_SCHEDULER_add_delayed (delay, &client_delayed_retry, th); return 0; diff --git a/src/util/connection.c b/src/util/connection.c index 2953d9ca7..8d0042b7b 100644 --- a/src/util/connection.c +++ b/src/util/connection.c @@ -89,9 +89,9 @@ struct GNUNET_CONNECTION_TransmitHandle void *notify_ready_cls; /** - * Our socket handle. + * Our connection handle. */ - struct GNUNET_CONNECTION_Handle *sh; + struct GNUNET_CONNECTION_Handle *connection; /** * Timeout for receiving (in absolute time). @@ -142,7 +142,7 @@ struct AddressProbe /** * Connection for which we are probing. */ - struct GNUNET_CONNECTION_Handle *h; + struct GNUNET_CONNECTION_Handle *connection; /** * Lenth of addr. @@ -150,14 +150,14 @@ struct AddressProbe socklen_t addrlen; /** - * Task waiting for the socket to finish connecting. + * Task waiting for the connection to finish connecting. */ GNUNET_SCHEDULER_TaskIdentifier task; }; /** - * @brief handle for a network socket + * @brief handle for a network connection */ struct GNUNET_CONNECTION_Handle { @@ -185,7 +185,7 @@ struct GNUNET_CONNECTION_Handle struct sockaddr *addr; /** - * Pointer to the hostname if socket was + * Pointer to the hostname if connection was * created using DNS lookup, otherwise NULL. */ char *hostname; @@ -273,7 +273,7 @@ struct GNUNET_CONNECTION_Handle size_t max; /** - * Ignore GNUNET_SCHEDULER_REASON_SHUTDOWN for this socket. + * Ignore GNUNET_SCHEDULER_REASON_SHUTDOWN for this connection. */ int ignore_shutdown; @@ -297,69 +297,69 @@ struct GNUNET_CONNECTION_Handle * that the underlying socket or fd should never really be closed. * Used for indicating process death. * - * @param sock the connection to set persistent + * @param connection the connection to set persistent */ void -GNUNET_CONNECTION_persist_ (struct GNUNET_CONNECTION_Handle *sock) +GNUNET_CONNECTION_persist_ (struct GNUNET_CONNECTION_Handle *connection) { - sock->persist = GNUNET_YES; + connection->persist = GNUNET_YES; } /** - * Disable the "CORK" feature for communication with the given socket, + * Disable the "CORK" feature for communication with the given connection, * forcing the OS to immediately flush the buffer on transmission * instead of potentially buffering multiple messages. Essentially * reduces the OS send buffers to zero. * Used to make sure that the last messages sent through the connection * reach the other side before the process is terminated. * - * @param sock the connection to make flushing and blocking + * @param connection the connection to make flushing and blocking * @return GNUNET_OK on success */ int -GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *sock) +GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *connection) { - return GNUNET_NETWORK_socket_disable_corking (sock->sock); + return GNUNET_NETWORK_socket_disable_corking (connection->sock); } /** - * Create a socket handle by boxing an existing OS socket. The OS + * Create a connection handle by boxing an existing OS socket. The OS * socket should henceforth be no longer used directly. - * GNUNET_socket_destroy will close it. + * GNUNET_connection_destroy will close it. * * @param osSocket existing socket to box - * @return the boxed socket handle + * @return the boxed connection handle */ struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle *osSocket) { - struct GNUNET_CONNECTION_Handle *ret; + struct GNUNET_CONNECTION_Handle *connection; - ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle)); - ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE; - ret->write_buffer = GNUNET_malloc (ret->write_buffer_size); - ret->sock = osSocket; - return ret; + connection = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle)); + connection->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE; + connection->write_buffer = GNUNET_malloc (connection->write_buffer_size); + connection->sock = osSocket; + return connection; } /** - * Create a socket handle by accepting on a listen socket. This + * Create a connection handle by accepting on a listen socket. This * function may block if the listen socket has no connection ready. * * @param access function to use to check if access is allowed * @param access_cls closure for access * @param lsock listen socket - * @return the socket handle, NULL on error + * @return the connection handle, NULL on error */ struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access, void *access_cls, struct GNUNET_NETWORK_Handle *lsock) { - struct GNUNET_CONNECTION_Handle *ret; + struct GNUNET_CONNECTION_Handle *connection; char addr[128]; socklen_t addrlen; struct GNUNET_NETWORK_Handle *sock; @@ -466,36 +466,36 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access, GNUNET_free (uaddr); return NULL; } - ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle)); - ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE; - ret->write_buffer = GNUNET_malloc (ret->write_buffer_size); - ret->addr = uaddr; - ret->addrlen = addrlen; - ret->sock = sock; + connection = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle)); + connection->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE; + connection->write_buffer = GNUNET_malloc (connection->write_buffer_size); + connection->addr = uaddr; + connection->addrlen = addrlen; + connection->sock = sock; LOG (GNUNET_ERROR_TYPE_INFO, _("Accepting connection from `%s': %p\n"), - GNUNET_a2s (uaddr, addrlen), ret); - return ret; + GNUNET_a2s (uaddr, addrlen), connection); + return connection; } /** * Obtain the network address of the other party. * - * @param sock the client to get the address for + * @param connection the client to get the address for * @param addr where to store the address * @param addrlen where to store the length of the address * @return GNUNET_OK on success */ int -GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *sock, +GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *connection, void **addr, size_t * addrlen) { - if ((sock->addr == NULL) || (sock->addrlen == 0)) + if ((connection->addr == NULL) || (connection->addrlen == 0)) return GNUNET_NO; - *addr = GNUNET_malloc (sock->addrlen); - memcpy (*addr, sock->addr, sock->addrlen); - *addrlen = sock->addrlen; + *addr = GNUNET_malloc (connection->addrlen); + memcpy (*addr, connection->addr, connection->addrlen); + *addrlen = connection->addrlen; return GNUNET_OK; } @@ -524,82 +524,82 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); static void destroy_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - struct GNUNET_CONNECTION_Handle *sock = cls; + struct GNUNET_CONNECTION_Handle *connection = cls; GNUNET_CONNECTION_TransmitReadyNotify notify; struct AddressProbe *pos; - sock->destroy_task = GNUNET_SCHEDULER_NO_TASK; - GNUNET_assert (sock->dns_active == NULL); - if (0 != (sock->ccs & COCO_TRANSMIT_READY)) + connection->destroy_task = GNUNET_SCHEDULER_NO_TASK; + GNUNET_assert (connection->dns_active == NULL); + if (0 != (connection->ccs & COCO_TRANSMIT_READY)) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroy waits for CCS-TR to be done (%p)\n", - sock); - sock->ccs |= COCO_DESTROY_CONTINUATION; + connection); + connection->ccs |= COCO_DESTROY_CONTINUATION; return; } - if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) + if (connection->write_task != GNUNET_SCHEDULER_NO_TASK) { LOG (GNUNET_ERROR_TYPE_DEBUG, - "Destroy waits for write_task to be done (%p)\n", sock); - GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); - sock->destroy_task = - GNUNET_SCHEDULER_add_after (sock->write_task, &destroy_continuation, - sock); + "Destroy waits for write_task to be done (%p)\n", connection); + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == connection->destroy_task); + connection->destroy_task = + GNUNET_SCHEDULER_add_after (connection->write_task, &destroy_continuation, + connection); return; } - if (0 != (sock->ccs & COCO_RECEIVE_AGAIN)) + if (0 != (connection->ccs & COCO_RECEIVE_AGAIN)) { - sock->ccs |= COCO_DESTROY_CONTINUATION; + connection->ccs |= COCO_DESTROY_CONTINUATION; return; } - if (sock->sock != NULL) + if (connection->sock != NULL) { - LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down socket (%p)\n", sock); - if (sock->persist != GNUNET_YES) + LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down connection (%p)\n", connection); + if (connection->persist != GNUNET_YES) { - if ((GNUNET_YES != GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR)) + if ((GNUNET_YES != GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR)) && (errno != ENOTCONN) && (errno != ECONNRESET)) LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "shutdown"); } } - if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) + if (connection->read_task != GNUNET_SCHEDULER_NO_TASK) { - GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); - sock->destroy_task = - GNUNET_SCHEDULER_add_after (sock->read_task, &destroy_continuation, - sock); + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == connection->destroy_task); + connection->destroy_task = + GNUNET_SCHEDULER_add_after (connection->read_task, &destroy_continuation, + connection); return; } - LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroy actually runs (%p)!\n", sock); - while (NULL != (pos = sock->ap_head)) + LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroy actually runs (%p)!\n", connection); + while (NULL != (pos = connection->ap_head)) { GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); GNUNET_SCHEDULER_cancel (pos->task); - GNUNET_CONTAINER_DLL_remove (sock->ap_head, sock->ap_tail, pos); + GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos); GNUNET_free (pos); } - GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK); - GNUNET_assert (sock->ccs == COCO_NONE); - if (NULL != (notify = sock->nth.notify_ready)) + GNUNET_assert (connection->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK); + GNUNET_assert (connection->ccs == COCO_NONE); + if (NULL != (notify = connection->nth.notify_ready)) { - sock->nth.notify_ready = NULL; - notify (sock->nth.notify_ready_cls, 0, NULL); + connection->nth.notify_ready = NULL; + notify (connection->nth.notify_ready_cls, 0, NULL); } - if (sock->sock != NULL) + if (connection->sock != NULL) { - if (sock->persist != GNUNET_YES) - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); + if (connection->persist != GNUNET_YES) + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock)); else - GNUNET_free (sock->sock); /* at least no memory leak (we deliberately + GNUNET_free (connection->sock); /* at least no memory leak (we deliberately * leak the socket in this special case) ... */ } - GNUNET_free_non_null (sock->addr); - GNUNET_free_non_null (sock->hostname); - GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); - LOG (GNUNET_ERROR_TYPE_DEBUG, "Freeing memory of connection %p.\n", sock); - GNUNET_free (sock->write_buffer); - GNUNET_free (sock); + GNUNET_free_non_null (connection->addr); + GNUNET_free_non_null (connection->hostname); + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == connection->destroy_task); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Freeing memory of connection %p.\n", connection); + GNUNET_free (connection->write_buffer); + GNUNET_free (connection); } @@ -668,44 +668,44 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h) /** * We've succeeded in establishing a connection. * - * @param h the connection we tried to establish + * @param connection the connection we tried to establish */ static void -connect_success_continuation (struct GNUNET_CONNECTION_Handle *h) +connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Connection to `%s' succeeded! (%p)\n", - GNUNET_a2s (h->addr, h->addrlen), h); + GNUNET_a2s (connection->addr, connection->addrlen), connection); /* trigger jobs that waited for the connection */ - if (0 != (h->ccs & COCO_RECEIVE_AGAIN)) + if (0 != (connection->ccs & COCO_RECEIVE_AGAIN)) { LOG (GNUNET_ERROR_TYPE_DEBUG, - "connect_success_continuation runs receive_again (%p)\n", h); - h->ccs -= COCO_RECEIVE_AGAIN; - h->read_task = GNUNET_SCHEDULER_add_now (&receive_again, h); + "connect_success_continuation runs receive_again (%p)\n", connection); + connection->ccs -= COCO_RECEIVE_AGAIN; + connection->read_task = GNUNET_SCHEDULER_add_now (&receive_again, connection); } - if (0 != (h->ccs & COCO_TRANSMIT_READY)) + if (0 != (connection->ccs & COCO_TRANSMIT_READY)) { LOG (GNUNET_ERROR_TYPE_DEBUG, "connect_success_continuation runs transmit_ready, cancels timeout_task (%p)\n", - h); - GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); - GNUNET_SCHEDULER_cancel (h->nth.timeout_task); - h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; - h->ccs -= COCO_TRANSMIT_READY; - GNUNET_assert (h->write_task == GNUNET_SCHEDULER_NO_TASK); - GNUNET_assert (h->nth.notify_ready != NULL); - h->write_task = + connection); + GNUNET_assert (connection->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); + GNUNET_SCHEDULER_cancel (connection->nth.timeout_task); + connection->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; + connection->ccs -= COCO_TRANSMIT_READY; + GNUNET_assert (connection->write_task == GNUNET_SCHEDULER_NO_TASK); + GNUNET_assert (connection->nth.notify_ready != NULL); + connection->write_task = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining - (h->nth.transmit_timeout), h->sock, - &transmit_ready, h); + (connection->nth.transmit_timeout), connection->sock, + &transmit_ready, connection); } - if (0 != (h->ccs & COCO_DESTROY_CONTINUATION)) + if (0 != (connection->ccs & COCO_DESTROY_CONTINUATION)) { LOG (GNUNET_ERROR_TYPE_DEBUG, - "connect_success_continuation runs destroy_continuation (%p)\n", h); - h->ccs -= COCO_DESTROY_CONTINUATION; - GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->destroy_task); - h->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, h); + "connect_success_continuation runs destroy_continuation (%p)\n", connection); + connection->ccs -= COCO_DESTROY_CONTINUATION; + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == connection->destroy_task); + connection->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, connection); } } @@ -722,13 +722,13 @@ connect_probe_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct AddressProbe *ap = cls; - struct GNUNET_CONNECTION_Handle *h = ap->h; + struct GNUNET_CONNECTION_Handle *connection = ap->connection; struct AddressProbe *pos; int error; socklen_t len; GNUNET_assert (ap->sock != NULL); - GNUNET_CONTAINER_DLL_remove (h->ap_head, h->ap_tail, ap); + GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, ap); len = sizeof (error); errno = 0; error = 0; @@ -739,31 +739,31 @@ connect_probe_continuation (void *cls, { GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); GNUNET_free (ap); - if ((NULL == h->ap_head) && (h->dns_active == GNUNET_NO)) - connect_fail_continuation (h); + if ((NULL == connection->ap_head) && (connection->dns_active == GNUNET_NO)) + connect_fail_continuation (connection); return; } - GNUNET_assert (h->sock == NULL); - h->sock = ap->sock; - GNUNET_assert (h->addr == NULL); - h->addr = GNUNET_malloc (ap->addrlen); - memcpy (h->addr, ap->addr, ap->addrlen); - h->addrlen = ap->addrlen; + GNUNET_assert (connection->sock == NULL); + connection->sock = ap->sock; + GNUNET_assert (connection->addr == NULL); + connection->addr = GNUNET_malloc (ap->addrlen); + memcpy (connection->addr, ap->addr, ap->addrlen); + connection->addrlen = ap->addrlen; GNUNET_free (ap); /* cancel all other attempts */ - while (NULL != (pos = h->ap_head)) + while (NULL != (pos = connection->ap_head)) { GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); GNUNET_SCHEDULER_cancel (pos->task); - GNUNET_CONTAINER_DLL_remove (h->ap_head, h->ap_tail, pos); + GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos); GNUNET_free (pos); } - connect_success_continuation (h); + connect_success_continuation (connection); } /** - * Try to establish a socket connection given the specified address. + * Try to establish a connection given the specified address. * This function is called by the resolver once we have a DNS reply. * * @param cls our "struct GNUNET_CONNECTION_Handle *" @@ -774,37 +774,37 @@ static void try_connect_using_address (void *cls, const struct sockaddr *addr, socklen_t addrlen) { - struct GNUNET_CONNECTION_Handle *h = cls; + struct GNUNET_CONNECTION_Handle *connection = cls; struct AddressProbe *ap; struct GNUNET_TIME_Relative delay; if (addr == NULL) { - h->dns_active = NULL; - if ((NULL == h->ap_head) && (NULL == h->sock)) - connect_fail_continuation (h); + connection->dns_active = NULL; + if ((NULL == connection->ap_head) && (NULL == connection->sock)) + connect_fail_continuation (connection); return; } - if (h->sock != NULL) + if (connection->sock != NULL) return; /* already connected */ - GNUNET_assert (h->addr == NULL); + GNUNET_assert (connection->addr == NULL); /* try to connect */ LOG (GNUNET_ERROR_TYPE_DEBUG, - "Trying to connect using address `%s:%u/%s:%u'\n", h->hostname, h->port, - GNUNET_a2s (addr, addrlen), h->port); + "Trying to connect using address `%s:%u/%s:%u'\n", connection->hostname, connection->port, + GNUNET_a2s (addr, addrlen), connection->port); ap = GNUNET_malloc (sizeof (struct AddressProbe) + addrlen); ap->addr = (const struct sockaddr *) &ap[1]; memcpy (&ap[1], addr, addrlen); ap->addrlen = addrlen; - ap->h = h; + ap->connection = connection; switch (ap->addr->sa_family) { case AF_INET: - ((struct sockaddr_in *) ap->addr)->sin_port = htons (h->port); + ((struct sockaddr_in *) ap->addr)->sin_port = htons (connection->port); break; case AF_INET6: - ((struct sockaddr_in6 *) ap->addr)->sin6_port = htons (h->port); + ((struct sockaddr_in6 *) ap->addr)->sin6_port = htons (connection->port); break; default: GNUNET_break (0); @@ -818,7 +818,7 @@ try_connect_using_address (void *cls, const struct sockaddr *addr, return; /* not supported by OS */ } LOG (GNUNET_ERROR_TYPE_INFO, _("Trying to connect to `%s' (%p)\n"), - GNUNET_a2s (ap->addr, ap->addrlen), h); + GNUNET_a2s (ap->addr, ap->addrlen), connection); if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (ap->sock, ap->addr, ap->addrlen)) && (errno != EINPROGRESS)) @@ -827,24 +827,24 @@ try_connect_using_address (void *cls, const struct sockaddr *addr, LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect"); #if 0 LOG (GNUNET_ERROR_TYPE_INFO, _("Failed to connect to `%s' (%p)\n"), - GNUNET_a2s (ap->addr, ap->addrlen), h); + GNUNET_a2s (ap->addr, ap->addrlen), connection); #endif GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); GNUNET_free (ap); return; } - GNUNET_CONTAINER_DLL_insert (h->ap_head, h->ap_tail, ap); + GNUNET_CONTAINER_DLL_insert (connection->ap_head, connection->ap_tail, ap); delay = GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT; - if (h->nth.notify_ready != NULL) + if (connection->nth.notify_ready != NULL) delay = GNUNET_TIME_relative_min (delay, - GNUNET_TIME_absolute_get_remaining (h-> + GNUNET_TIME_absolute_get_remaining (connection-> nth.transmit_timeout)); - if (h->receiver != NULL) + if (connection->receiver != NULL) delay = GNUNET_TIME_relative_min (delay, GNUNET_TIME_absolute_get_remaining - (h->receive_timeout)); + (connection->receive_timeout)); ap->task = GNUNET_SCHEDULER_add_write_net (delay, ap->sock, &connect_probe_continuation, ap); @@ -852,45 +852,45 @@ try_connect_using_address (void *cls, const struct sockaddr *addr, /** - * Create a socket handle by (asynchronously) connecting to a host. + * Create a connection handle by (asynchronously) connecting to a host. * This function returns immediately, even if the connection has not * yet been established. This function only creates TCP connections. * * @param cfg configuration to use * @param hostname name of the host to connect to * @param port port to connect to - * @return the socket handle + * @return the connection handle */ struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *hostname, uint16_t port) { - struct GNUNET_CONNECTION_Handle *ret; + struct GNUNET_CONNECTION_Handle *connection; GNUNET_assert (0 < strlen (hostname)); /* sanity check */ - ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle)); - ret->cfg = cfg; - ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE; - ret->write_buffer = GNUNET_malloc (ret->write_buffer_size); - ret->port = port; - ret->hostname = GNUNET_strdup (hostname); - ret->dns_active = - GNUNET_RESOLVER_ip_get (ret->hostname, AF_UNSPEC, + connection = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle)); + connection->cfg = cfg; + connection->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE; + connection->write_buffer = GNUNET_malloc (connection->write_buffer_size); + connection->port = port; + connection->hostname = GNUNET_strdup (hostname); + connection->dns_active = + GNUNET_RESOLVER_ip_get (connection->hostname, AF_UNSPEC, GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT, - &try_connect_using_address, ret); - return ret; + &try_connect_using_address, connection); + return connection; } /** - * Create a socket handle by connecting to a UNIX domain service. + * Create a connection handle by connecting to a UNIX domain service. * This function returns immediately, even if the connection has not * yet been established. This function only creates UNIX connections. * * @param cfg configuration to use * @param unixpath path to connect to - * @return the socket handle, NULL on systems without UNIX support + * @return the connection handle, NULL on systems without UNIX support */ struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct @@ -898,7 +898,7 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct *cfg, const char *unixpath) { #ifdef AF_UNIX - struct GNUNET_CONNECTION_Handle *ret; + struct GNUNET_CONNECTION_Handle *connection; struct sockaddr_un *un; size_t slen; @@ -917,32 +917,32 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct #if LINUX un->sun_path[0] = '\0'; #endif - ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle)); - ret->cfg = cfg; - ret->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE; - ret->write_buffer = GNUNET_malloc (ret->write_buffer_size); - ret->port = 0; - ret->hostname = NULL; - ret->addr = (struct sockaddr *) un; - ret->addrlen = slen; - ret->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); - if (NULL == ret->sock) + connection = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle)); + connection->cfg = cfg; + connection->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE; + connection->write_buffer = GNUNET_malloc (connection->write_buffer_size); + connection->port = 0; + connection->hostname = NULL; + connection->addr = (struct sockaddr *) un; + connection->addrlen = slen; + connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); + if (NULL == connection->sock) { - GNUNET_free (ret->addr); - GNUNET_free (ret->write_buffer); - GNUNET_free (ret); + GNUNET_free (connection->addr); + GNUNET_free (connection->write_buffer); + GNUNET_free (connection); return NULL; } if (GNUNET_OK != - GNUNET_NETWORK_socket_connect (ret->sock, ret->addr, ret->addrlen)) + GNUNET_NETWORK_socket_connect (connection->sock, connection->addr, connection->addrlen)) { /* Just return; we expect everything to work eventually so don't fail HARD */ - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret->sock)); - ret->sock = NULL; - return ret; + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock)); + connection->sock = NULL; + return connection; } - connect_success_continuation (ret); - return ret; + connect_success_continuation (connection); + return connection; #else return NULL; #endif @@ -950,14 +950,14 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct /** - * Create a socket handle by (asynchronously) connecting to a host. + * Create a connection handle by (asynchronously) connecting to a host. * This function returns immediately, even if the connection has not * yet been established. This function only creates TCP connections. * * @param af_family address family to use * @param serv_addr server address * @param addrlen length of server address - * @return the socket handle + * @return the connection handle */ struct GNUNET_CONNECTION_Handle * GNUNET_CONNECTION_create_from_sockaddr (int af_family, @@ -965,7 +965,7 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family, socklen_t addrlen) { struct GNUNET_NETWORK_Handle *s; - struct GNUNET_CONNECTION_Handle *ret; + struct GNUNET_CONNECTION_Handle *connection; s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0); @@ -984,22 +984,22 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family, GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); return NULL; } - ret = GNUNET_CONNECTION_create_from_existing (s); - ret->addr = GNUNET_malloc (addrlen); - memcpy (ret->addr, serv_addr, addrlen); - ret->addrlen = addrlen; + connection = GNUNET_CONNECTION_create_from_existing (s); + connection->addr = GNUNET_malloc (addrlen); + memcpy (connection->addr, serv_addr, addrlen); + connection->addrlen = addrlen; LOG (GNUNET_ERROR_TYPE_INFO, _("Trying to connect to `%s' (%p)\n"), - GNUNET_a2s (serv_addr, addrlen), ret); - return ret; + GNUNET_a2s (serv_addr, addrlen), connection); + return connection; } /** - * Check if socket is valid (no fatal errors have happened so far). - * Note that a socket that is still trying to connect is considered + * Check if connection is valid (no fatal errors have happened so far). + * Note that a connection that is still trying to connect is considered * valid. * - * @param sock socket to check + * @param sock connection to check * @return GNUNET_YES if valid, GNUNET_NO otherwise */ int @@ -1012,35 +1012,32 @@ GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock) /** - * Close the socket and free associated resources. Pending - * transmissions may be completed or dropped depending on the - * arguments. If a receive call is pending and should - * NOT be completed, 'GNUNET_CONNECTION_receive_cancel' - * should be called explicitly first. + * Close the connection and free associated resources. A pending + * request for transmission is automatically cancelled (we might + * want to change this in the future). We require that there + * are no active pending requests for reading from the connection. * - * @param sock socket to destroy + * @param connection connection to destroy */ void -GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock) +GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection) { - int finish_pending_write = GNUNET_NO; - if (GNUNET_NO == finish_pending_write) + GNUNET_assert (NULL == connection->receiver); + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == connection->read_task); + if (connection->write_task != GNUNET_SCHEDULER_NO_TASK) { - if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) - { - GNUNET_SCHEDULER_cancel (sock->write_task); - sock->write_task = GNUNET_SCHEDULER_NO_TASK; - sock->write_buffer_off = 0; - } - sock->nth.notify_ready = NULL; + GNUNET_SCHEDULER_cancel (connection->write_task); + connection->write_task = GNUNET_SCHEDULER_NO_TASK; + connection->write_buffer_off = 0; } - if ((sock->write_buffer_off == 0) && (sock->dns_active != NULL)) + connection->nth.notify_ready = NULL; + if (connection->dns_active != NULL) { - GNUNET_RESOLVER_request_cancel (sock->dns_active); - sock->dns_active = NULL; + GNUNET_RESOLVER_request_cancel (connection->dns_active); + connection->dns_active = NULL; } - GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->destroy_task); - sock->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, sock); + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == connection->destroy_task); + connection->destroy_task = GNUNET_SCHEDULER_add_now (&destroy_continuation, connection); } @@ -1081,64 +1078,64 @@ signal_error (struct GNUNET_CONNECTION_Handle *sh, int errcode) static void receive_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - struct GNUNET_CONNECTION_Handle *sh = cls; + struct GNUNET_CONNECTION_Handle *connection = cls; struct GNUNET_TIME_Absolute now; - char buffer[sh->max]; + char buffer[connection->max]; ssize_t ret; GNUNET_CONNECTION_Receiver receiver; - sh->read_task = GNUNET_SCHEDULER_NO_TASK; - if ((GNUNET_YES == sh->ignore_shutdown) && + connection->read_task = GNUNET_SCHEDULER_NO_TASK; + if ((GNUNET_YES == connection->ignore_shutdown) && (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))) { /* ignore shutdown request, go again immediately */ LOG (GNUNET_ERROR_TYPE_DEBUG, "Ignoring shutdown signal per configuration\n"); - sh->read_task = + connection->read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining - (sh->receive_timeout), sh->sock, - &receive_ready, sh); + (connection->receive_timeout), connection->sock, + &receive_ready, connection); return; } now = GNUNET_TIME_absolute_get (); - if ((now.abs_value > sh->receive_timeout.abs_value) || + if ((now.abs_value > connection->receive_timeout.abs_value) || (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) || (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))) { if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) LOG (GNUNET_ERROR_TYPE_DEBUG, "Receive from `%s' encounters error: time out by %llums... (%p)\n", - GNUNET_a2s (sh->addr, sh->addrlen), - GNUNET_TIME_absolute_get_duration (sh->receive_timeout).rel_value, - sh); - signal_timeout (sh); + GNUNET_a2s (connection->addr, connection->addrlen), + GNUNET_TIME_absolute_get_duration (connection->receive_timeout).rel_value, + connection); + signal_timeout (connection); return; } - if (sh->sock == NULL) + if (connection->sock == NULL) { /* connect failed for good */ LOG (GNUNET_ERROR_TYPE_DEBUG, - "Receive encounters error, socket closed... (%p)\n", sh); - signal_error (sh, ECONNREFUSED); + "Receive encounters error, connection closed... (%p)\n", connection); + signal_error (connection, ECONNREFUSED); return; } - GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, sh->sock)); + GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, connection->sock)); RETRY: - ret = GNUNET_NETWORK_socket_recv (sh->sock, buffer, sh->max); + ret = GNUNET_NETWORK_socket_recv (connection->sock, buffer, connection->max); if (ret == -1) { if (errno == EINTR) goto RETRY; LOG (GNUNET_ERROR_TYPE_DEBUG, "Error receiving: %s\n", STRERROR (errno)); - signal_error (sh, errno); + signal_error (connection, errno); return; } 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); - GNUNET_assert (NULL != (receiver = sh->receiver)); - sh->receiver = NULL; - receiver (sh->receiver_cls, buffer, ret, sh->addr, sh->addrlen, 0); + 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); } @@ -1155,117 +1152,117 @@ RETRY: static void receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - struct GNUNET_CONNECTION_Handle *sh = cls; + struct GNUNET_CONNECTION_Handle *connection = cls; struct GNUNET_TIME_Absolute now; - sh->read_task = GNUNET_SCHEDULER_NO_TASK; - if (sh->sock == NULL) + connection->read_task = GNUNET_SCHEDULER_NO_TASK; + if (connection->sock == NULL) { /* not connected and no longer trying */ LOG (GNUNET_ERROR_TYPE_DEBUG, - "Receive encounters error, socket closed (%p)...\n", sh); - signal_error (sh, ECONNREFUSED); + "Receive encounters error, connection closed (%p)...\n", connection); + signal_error (connection, ECONNREFUSED); return; } now = GNUNET_TIME_absolute_get (); - if ((now.abs_value > sh->receive_timeout.abs_value) || + if ((now.abs_value > connection->receive_timeout.abs_value) || (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))) { LOG (GNUNET_ERROR_TYPE_DEBUG, - "Receive encounters error: time out (%p)...\n", sh); - signal_timeout (sh); + "Receive encounters error: time out (%p)...\n", connection); + signal_timeout (connection); return; } - GNUNET_assert (sh->sock != NULL); + GNUNET_assert (connection->sock != NULL); /* connect succeeded, wait for data! */ - sh->read_task = + connection->read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining - (sh->receive_timeout), sh->sock, - &receive_ready, sh); + (connection->receive_timeout), connection->sock, + &receive_ready, connection); } /** - * Receive data from the given socket. Note that this function will + * Receive data from the given connection. Note that this function will * call "receiver" asynchronously using the scheduler. It will * "immediately" return. Note that there MUST only be one active - * receive call per socket at any given point in time (so do not + * receive call per connection at any given point in time (so do not * call receive again until the receiver callback has been invoked). * - * @param sock socket handle + * @param connection connection handle * @param max maximum number of bytes to read * @param timeout maximum amount of time to wait (use -1 for "forever") * @param receiver function to call with received data * @param receiver_cls closure for receiver */ void -GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock, size_t max, +GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection, size_t max, struct GNUNET_TIME_Relative timeout, GNUNET_CONNECTION_Receiver receiver, void *receiver_cls) { struct GNUNET_SCHEDULER_TaskContext tc; - GNUNET_assert ((sock->read_task == GNUNET_SCHEDULER_NO_TASK) && - (0 == (sock->ccs & COCO_RECEIVE_AGAIN)) && - (sock->receiver == NULL)); - sock->receiver = receiver; - sock->receiver_cls = receiver_cls; - sock->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout); - sock->max = max; - if (sock->sock != NULL) + GNUNET_assert ((connection->read_task == GNUNET_SCHEDULER_NO_TASK) && + (0 == (connection->ccs & COCO_RECEIVE_AGAIN)) && + (connection->receiver == NULL)); + connection->receiver = receiver; + connection->receiver_cls = receiver_cls; + connection->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout); + connection->max = max; + if (connection->sock != NULL) { memset (&tc, 0, sizeof (tc)); tc.reason = GNUNET_SCHEDULER_REASON_PREREQ_DONE; - receive_again (sock, &tc); + receive_again (connection, &tc); return; } - if ((sock->dns_active == NULL) && (sock->ap_head == NULL)) + if ((connection->dns_active == NULL) && (connection->ap_head == NULL)) { receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT); return; } - sock->ccs += COCO_RECEIVE_AGAIN; + connection->ccs += COCO_RECEIVE_AGAIN; } /** * Configure this connection to ignore shutdown signals. * - * @param sock socket handle + * @param connection connection handle * @param do_ignore GNUNET_YES to ignore, GNUNET_NO to restore default */ void -GNUNET_CONNECTION_ignore_shutdown (struct GNUNET_CONNECTION_Handle *sock, +GNUNET_CONNECTION_ignore_shutdown (struct GNUNET_CONNECTION_Handle *connection, int do_ignore) { - sock->ignore_shutdown = do_ignore; + connection->ignore_shutdown = do_ignore; } /** - * Cancel receive job on the given socket. Note that the + * Cancel receive job on the given connection. Note that the * receiver callback must not have been called yet in order * for the cancellation to be valid. * - * @param sock socket handle + * @param connection connection handle * @return closure of the original receiver callback closure */ void * -GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *sock) +GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *connection) { - if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) + if (connection->read_task != GNUNET_SCHEDULER_NO_TASK) { - GNUNET_assert (sock == GNUNET_SCHEDULER_cancel (sock->read_task)); - sock->read_task = GNUNET_SCHEDULER_NO_TASK; + GNUNET_assert (connection == GNUNET_SCHEDULER_cancel (connection->read_task)); + connection->read_task = GNUNET_SCHEDULER_NO_TASK; } else { - GNUNET_assert (0 != (sock->ccs & COCO_RECEIVE_AGAIN)); - sock->ccs -= COCO_RECEIVE_AGAIN; + GNUNET_assert (0 != (connection->ccs & COCO_RECEIVE_AGAIN)); + connection->ccs -= COCO_RECEIVE_AGAIN; } - sock->receiver = NULL; - return sock->receiver_cls; + connection->receiver = NULL; + return connection->receiver_cls; } @@ -1273,41 +1270,41 @@ GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *sock) * Try to call the transmit notify method (check if we do * have enough space available first)! * - * @param sock socket for which we should do this processing + * @param connection connection for which we should do this processing * @return GNUNET_YES if we were able to call notify */ static int -process_notify (struct GNUNET_CONNECTION_Handle *sock) +process_notify (struct GNUNET_CONNECTION_Handle *connection) { size_t used; size_t avail; size_t size; GNUNET_CONNECTION_TransmitReadyNotify notify; - GNUNET_assert (sock->write_task == GNUNET_SCHEDULER_NO_TASK); - if (NULL == (notify = sock->nth.notify_ready)) + GNUNET_assert (connection->write_task == GNUNET_SCHEDULER_NO_TASK); + if (NULL == (notify = connection->nth.notify_ready)) return GNUNET_NO; - used = sock->write_buffer_off - sock->write_buffer_pos; - avail = sock->write_buffer_size - used; - size = sock->nth.notify_size; + used = connection->write_buffer_off - connection->write_buffer_pos; + avail = connection->write_buffer_size - used; + size = connection->nth.notify_size; if (size > avail) return GNUNET_NO; - sock->nth.notify_ready = NULL; - if (sock->write_buffer_size - sock->write_buffer_off < size) + connection->nth.notify_ready = NULL; + if (connection->write_buffer_size - connection->write_buffer_off < size) { /* need to compact */ - memmove (sock->write_buffer, &sock->write_buffer[sock->write_buffer_pos], + memmove (connection->write_buffer, &connection->write_buffer[connection->write_buffer_pos], used); - sock->write_buffer_off -= sock->write_buffer_pos; - sock->write_buffer_pos = 0; + connection->write_buffer_off -= connection->write_buffer_pos; + connection->write_buffer_pos = 0; } - avail = sock->write_buffer_size - sock->write_buffer_off; + avail = connection->write_buffer_size - connection->write_buffer_off; GNUNET_assert (avail >= size); size = - notify (sock->nth.notify_ready_cls, avail, - &sock->write_buffer[sock->write_buffer_off]); + notify (connection->nth.notify_ready_cls, avail, + &connection->write_buffer[connection->write_buffer_off]); GNUNET_assert (size <= avail); - sock->write_buffer_off += size; + connection->write_buffer_off += size; return GNUNET_YES; } @@ -1326,19 +1323,19 @@ process_notify (struct GNUNET_CONNECTION_Handle *sock) static void transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - struct GNUNET_CONNECTION_Handle *sock = cls; + struct GNUNET_CONNECTION_Handle *connection = cls; GNUNET_CONNECTION_TransmitReadyNotify notify; - sock->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; + connection->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmit to `%s:%u/%s' fails, time out reached (%p).\n", - sock->hostname, - sock->port, GNUNET_a2s (sock->addr, sock->addrlen), sock); - GNUNET_assert (0 != (sock->ccs & COCO_TRANSMIT_READY)); - sock->ccs -= COCO_TRANSMIT_READY; /* remove request */ - notify = sock->nth.notify_ready; - sock->nth.notify_ready = NULL; - notify (sock->nth.notify_ready_cls, 0, NULL); + connection->hostname, + connection->port, GNUNET_a2s (connection->addr, connection->addrlen), connection); + GNUNET_assert (0 != (connection->ccs & COCO_TRANSMIT_READY)); + connection->ccs -= COCO_TRANSMIT_READY; /* remove request */ + notify = connection->nth.notify_ready; + connection->nth.notify_ready = NULL; + notify (connection->nth.notify_ready_cls, 0, NULL); } @@ -1354,48 +1351,48 @@ transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) static void connect_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - struct GNUNET_CONNECTION_Handle *sock = cls; + struct GNUNET_CONNECTION_Handle *connection = cls; GNUNET_CONNECTION_TransmitReadyNotify notify; LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmission request of size %u fails (%s/%u), connection failed (%p).\n", - sock->nth.notify_size, sock->hostname, sock->port, sock); - 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); + connection->nth.notify_size, connection->hostname, connection->port, connection); + connection->write_task = GNUNET_SCHEDULER_NO_TASK; + notify = connection->nth.notify_ready; + connection->nth.notify_ready = NULL; + notify (connection->nth.notify_ready_cls, 0, NULL); } /** * FIXME * - * @param sock FIXME + * @param connection FIXME */ static void -transmit_error (struct GNUNET_CONNECTION_Handle *sock) +transmit_error (struct GNUNET_CONNECTION_Handle *connection) { GNUNET_CONNECTION_TransmitReadyNotify notify; - if (NULL != sock->sock) + if (NULL != connection->sock) { - GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR); - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); - sock->sock = NULL; - GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->write_task); + GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock)); + connection->sock = NULL; + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == connection->write_task); } - if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) + if (connection->read_task != GNUNET_SCHEDULER_NO_TASK) { - GNUNET_SCHEDULER_cancel (sock->read_task); - sock->read_task = GNUNET_SCHEDULER_NO_TASK; - signal_timeout (sock); + GNUNET_SCHEDULER_cancel (connection->read_task); + connection->read_task = GNUNET_SCHEDULER_NO_TASK; + signal_timeout (connection); return; } - if (sock->nth.notify_ready == NULL) + if (connection->nth.notify_ready == NULL) return; /* nobody to tell about it */ - notify = sock->nth.notify_ready; - sock->nth.notify_ready = NULL; - notify (sock->nth.notify_ready_cls, 0, NULL); + notify = connection->nth.notify_ready; + connection->nth.notify_ready = NULL; + notify (connection->nth.notify_ready_cls, 0, NULL); } @@ -1410,27 +1407,27 @@ transmit_error (struct GNUNET_CONNECTION_Handle *sock) static void transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - struct GNUNET_CONNECTION_Handle *sock = cls; + struct GNUNET_CONNECTION_Handle *connection = cls; GNUNET_CONNECTION_TransmitReadyNotify notify; ssize_t ret; size_t have; - LOG (GNUNET_ERROR_TYPE_DEBUG, "transmit_ready running (%p).\n", sock); - GNUNET_assert (sock->write_task != GNUNET_SCHEDULER_NO_TASK); - sock->write_task = GNUNET_SCHEDULER_NO_TASK; - GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK); + LOG (GNUNET_ERROR_TYPE_DEBUG, "transmit_ready running (%p).\n", connection); + GNUNET_assert (connection->write_task != GNUNET_SCHEDULER_NO_TASK); + connection->write_task = GNUNET_SCHEDULER_NO_TASK; + GNUNET_assert (connection->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK); if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) { - if ((sock->ignore_shutdown == GNUNET_YES) && (NULL != sock->sock)) + if ((connection->ignore_shutdown == GNUNET_YES) && (NULL != connection->sock)) goto SCHEDULE_WRITE; /* ignore shutdown, go again immediately */ LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmit to `%s' fails, shutdown happened (%p).\n", - GNUNET_a2s (sock->addr, sock->addrlen), sock); - notify = sock->nth.notify_ready; + GNUNET_a2s (connection->addr, connection->addrlen), connection); + notify = connection->nth.notify_ready; if (NULL != notify) { - sock->nth.notify_ready = NULL; - notify (sock->nth.notify_ready_cls, 0, NULL); + connection->nth.notify_ready = NULL; + notify (connection->nth.notify_ready_cls, 0, NULL); } return; } @@ -1438,14 +1435,14 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmit to `%s' fails, time out reached (%p).\n", - GNUNET_a2s (sock->addr, sock->addrlen), sock); - notify = sock->nth.notify_ready; + GNUNET_a2s (connection->addr, connection->addrlen), connection); + notify = connection->nth.notify_ready; GNUNET_assert (NULL != notify); - sock->nth.notify_ready = NULL; - notify (sock->nth.notify_ready_cls, 0, NULL); + connection->nth.notify_ready = NULL; + notify (connection->nth.notify_ready_cls, 0, NULL); return; } - GNUNET_assert (NULL != sock->sock); + GNUNET_assert (NULL != connection->sock); if (tc->write_ready == NULL) { /* special circumstances (in particular, @@ -1453,86 +1450,86 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) * but no "fatal" error either. Hence retry. */ goto SCHEDULE_WRITE; } - if (!GNUNET_NETWORK_fdset_isset (tc->write_ready, sock->sock)) + if (!GNUNET_NETWORK_fdset_isset (tc->write_ready, connection->sock)) { LOG (GNUNET_ERROR_TYPE_INFO, _ ("Could not satisfy pending transmission request, socket closed or connect failed (%p).\n"), - sock); - GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->write_task); - transmit_error (sock); + connection); + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == connection->write_task); + transmit_error (connection); return; /* connect failed for good, we're finished */ } - GNUNET_assert (sock->write_buffer_off >= sock->write_buffer_pos); - if ((sock->nth.notify_ready != NULL) && - (sock->write_buffer_size < sock->nth.notify_size)) + GNUNET_assert (connection->write_buffer_off >= connection->write_buffer_pos); + if ((connection->nth.notify_ready != NULL) && + (connection->write_buffer_size < connection->nth.notify_size)) { - sock->write_buffer = - GNUNET_realloc (sock->write_buffer, sock->nth.notify_size); - sock->write_buffer_size = sock->nth.notify_size; + connection->write_buffer = + GNUNET_realloc (connection->write_buffer, connection->nth.notify_size); + connection->write_buffer_size = connection->nth.notify_size; } - process_notify (sock); - have = sock->write_buffer_off - sock->write_buffer_pos; + process_notify (connection); + have = connection->write_buffer_off - connection->write_buffer_pos; if (have == 0) { /* no data ready for writing, terminate write loop */ return; } - GNUNET_assert (have <= sock->write_buffer_size); - GNUNET_assert (have + sock->write_buffer_pos <= sock->write_buffer_size); - GNUNET_assert (sock->write_buffer_pos <= sock->write_buffer_size); + GNUNET_assert (have <= connection->write_buffer_size); + GNUNET_assert (have + connection->write_buffer_pos <= connection->write_buffer_size); + GNUNET_assert (connection->write_buffer_pos <= connection->write_buffer_size); RETRY: ret = - GNUNET_NETWORK_socket_send (sock->sock, - &sock->write_buffer[sock->write_buffer_pos], - have); + GNUNET_NETWORK_socket_send (connection->sock, + &connection->write_buffer[connection->write_buffer_pos], + have); if (ret == -1) { if (errno == EINTR) goto RETRY; LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "send"); - if (GNUNET_SCHEDULER_NO_TASK != sock->write_task) + if (GNUNET_SCHEDULER_NO_TASK != connection->write_task) { - GNUNET_SCHEDULER_cancel (sock->write_task); - sock->write_task = GNUNET_SCHEDULER_NO_TASK; + GNUNET_SCHEDULER_cancel (connection->write_task); + connection->write_task = GNUNET_SCHEDULER_NO_TASK; } - transmit_error (sock); + transmit_error (connection); return; } LOG (GNUNET_ERROR_TYPE_DEBUG, "transmit_ready transmitted %u/%u bytes to `%s' (%p)\n", - (unsigned int) ret, have, GNUNET_a2s (sock->addr, sock->addrlen), sock); - sock->write_buffer_pos += ret; - if (sock->write_buffer_pos == sock->write_buffer_off) + (unsigned int) ret, have, GNUNET_a2s (connection->addr, connection->addrlen), connection); + connection->write_buffer_pos += ret; + if (connection->write_buffer_pos == connection->write_buffer_off) { /* transmitted all pending data */ - sock->write_buffer_pos = 0; - sock->write_buffer_off = 0; + connection->write_buffer_pos = 0; + connection->write_buffer_off = 0; } - if ((sock->write_buffer_off == 0) && (NULL == sock->nth.notify_ready)) + if ((connection->write_buffer_off == 0) && (NULL == connection->nth.notify_ready)) return; /* all data sent! */ /* not done writing, schedule more */ SCHEDULE_WRITE: LOG (GNUNET_ERROR_TYPE_DEBUG, - "Re-scheduling transmit_ready (more to do) (%p).\n", sock); - have = sock->write_buffer_off - sock->write_buffer_pos; - GNUNET_assert ((sock->nth.notify_ready != NULL) || (have > 0)); - if (sock->write_task == GNUNET_SCHEDULER_NO_TASK) - sock->write_task = - GNUNET_SCHEDULER_add_write_net ((sock->nth.notify_ready == + "Re-scheduling transmit_ready (more to do) (%p).\n", connection); + have = connection->write_buffer_off - connection->write_buffer_pos; + GNUNET_assert ((connection->nth.notify_ready != NULL) || (have > 0)); + if (connection->write_task == GNUNET_SCHEDULER_NO_TASK) + connection->write_task = + GNUNET_SCHEDULER_add_write_net ((connection->nth.notify_ready == NULL) ? GNUNET_TIME_UNIT_FOREVER_REL : GNUNET_TIME_absolute_get_remaining - (sock->nth.transmit_timeout), - sock->sock, &transmit_ready, sock); + (connection->nth.transmit_timeout), + connection->sock, &transmit_ready, connection); } /** - * Ask the socket to call us once the specified number of bytes + * Ask the connection to call us once the specified number of bytes * are free in the transmission buffer. May call the notify * method immediately if enough space is available. * - * @param sock socket + * @param connection connection * @param size number of bytes to send * @param timeout after how long should we give up (and call * notify with buf NULL and size 0)? @@ -1542,55 +1539,55 @@ SCHEDULE_WRITE: * NULL if we are already going to notify someone else (busy) */ struct GNUNET_CONNECTION_TransmitHandle * -GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *sock, +GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connection, size_t size, struct GNUNET_TIME_Relative timeout, GNUNET_CONNECTION_TransmitReadyNotify notify, void *notify_cls) { - if (sock->nth.notify_ready != NULL) + if (connection->nth.notify_ready != NULL) { GNUNET_assert (0); return NULL; } GNUNET_assert (notify != NULL); GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE); - 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_ready = notify; - sock->nth.notify_ready_cls = notify_cls; - sock->nth.sh = sock; - 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 == NULL)) + GNUNET_assert (connection->write_buffer_off <= connection->write_buffer_size); + GNUNET_assert (connection->write_buffer_pos <= connection->write_buffer_size); + GNUNET_assert (connection->write_buffer_pos <= connection->write_buffer_off); + connection->nth.notify_ready = notify; + connection->nth.notify_ready_cls = notify_cls; + connection->nth.connection = connection; + connection->nth.notify_size = size; + connection->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout); + GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == connection->nth.timeout_task); + if ((connection->sock == NULL) && (connection->ap_head == NULL) && + (connection->dns_active == NULL)) { - if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) - GNUNET_SCHEDULER_cancel (sock->write_task); - sock->write_task = GNUNET_SCHEDULER_add_now (&connect_error, sock); - return &sock->nth; + if (connection->write_task != GNUNET_SCHEDULER_NO_TASK) + GNUNET_SCHEDULER_cancel (connection->write_task); + connection->write_task = GNUNET_SCHEDULER_add_now (&connect_error, connection); + return &connection->nth; } - if (GNUNET_SCHEDULER_NO_TASK != sock->write_task) - return &sock->nth; - if (sock->sock != NULL) + if (GNUNET_SCHEDULER_NO_TASK != connection->write_task) + return &connection->nth; + if (connection->sock != NULL) { - LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduling transmit_ready (%p).\n", sock); - sock->write_task = + LOG (GNUNET_ERROR_TYPE_DEBUG, "Scheduling transmit_ready (%p).\n", connection); + connection->write_task = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining - (sock->nth.transmit_timeout), - sock->sock, &transmit_ready, sock); + (connection->nth.transmit_timeout), + connection->sock, &transmit_ready, connection); } else { LOG (GNUNET_ERROR_TYPE_DEBUG, - "CCS-Scheduling transmit_ready, adding timeout task (%p).\n", sock); - sock->ccs |= COCO_TRANSMIT_READY; - sock->nth.timeout_task = - GNUNET_SCHEDULER_add_delayed (timeout, &transmit_timeout, sock); + "CCS-Scheduling transmit_ready, adding timeout task (%p).\n", connection); + connection->ccs |= COCO_TRANSMIT_READY; + connection->nth.timeout_task = + GNUNET_SCHEDULER_add_delayed (timeout, &transmit_timeout, connection); } - return &sock->nth; + return &connection->nth; } @@ -1605,20 +1602,20 @@ GNUNET_CONNECTION_notify_transmit_ready_cancel (struct *th) { GNUNET_assert (th->notify_ready != NULL); - if (0 != (th->sh->ccs & COCO_TRANSMIT_READY)) + if (0 != (th->connection->ccs & COCO_TRANSMIT_READY)) { LOG (GNUNET_ERROR_TYPE_DEBUG, "notify_transmit_ready_cancel cancels timeout_task (%p)\n", th); GNUNET_SCHEDULER_cancel (th->timeout_task); th->timeout_task = GNUNET_SCHEDULER_NO_TASK; - th->sh->ccs -= COCO_TRANSMIT_READY; + th->connection->ccs -= COCO_TRANSMIT_READY; } else { - if (th->sh->write_task != GNUNET_SCHEDULER_NO_TASK) + if (th->connection->write_task != GNUNET_SCHEDULER_NO_TASK) { - GNUNET_SCHEDULER_cancel (th->sh->write_task); - th->sh->write_task = GNUNET_SCHEDULER_NO_TASK; + GNUNET_SCHEDULER_cancel (th->connection->write_task); + th->connection->write_task = GNUNET_SCHEDULER_NO_TASK; } } th->notify_ready = NULL; diff --git a/src/util/server.c b/src/util/server.c index 4b3ebb7d9..a3f63490a 100644 --- a/src/util/server.c +++ b/src/util/server.c @@ -773,10 +773,10 @@ process_mst (struct GNUNET_SERVER_Client *client, int ret) { if (ret == GNUNET_OK) { - client->receive_pending = GNUNET_YES; LOG (GNUNET_ERROR_TYPE_DEBUG, "Server re-enters receive loop, timeout: %llu.\n", client->idle_timeout.rel_value); + client->receive_pending = GNUNET_YES; GNUNET_CONNECTION_receive (client->connection, GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, client->idle_timeout, &process_incoming, @@ -966,17 +966,15 @@ GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server, client->next = server->clients; client->idle_timeout = server->idle_timeout; server->clients = client; - client->receive_pending = GNUNET_YES; client->callback = NULL; client->callback_cls = NULL; - if (server->mst_create != NULL) client->mst = server->mst_create (server->mst_cls, client); else client->mst = GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, server); - + client->receive_pending = GNUNET_YES; GNUNET_CONNECTION_receive (client->connection, GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, client->idle_timeout, &process_incoming, client); -- 2.25.1