GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h)
{
if (h->client != NULL)
- GNUNET_CLIENT_disconnect (h->client);
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
GNUNET_CONFIGURATION_destroy (h->cfg);
GNUNET_free (h);
}
? "START"
: "STOP",
(const char*) &sc[1]);
- GNUNET_CLIENT_disconnect (sc->h->client);
+ GNUNET_CLIENT_disconnect (sc->h->client, GNUNET_NO);
sc->h->client = GNUNET_CLIENT_connect (sc->h->sched,
"arm",
sc->h->cfg);
reconnect (struct GNUNET_CORE_Handle *h)
{
if (h->client_notifications != NULL)
- GNUNET_CLIENT_disconnect (h->client_notifications);
+ GNUNET_CLIENT_disconnect (h->client_notifications, GNUNET_NO);
h->currently_down = GNUNET_YES;
h->client_notifications = GNUNET_CLIENT_connect (h->sched, "core", h->cfg);
if (h->client_notifications == NULL)
if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (handle->sched, handle->reconnect_task);
if (handle->client_notifications != NULL)
- GNUNET_CLIENT_disconnect (handle->client_notifications);
+ GNUNET_CLIENT_disconnect (handle->client_notifications, GNUNET_NO);
GNUNET_free_non_null (handle->solicit_buffer);
GNUNET_free (handle);
}
if (irc->info != NULL)
irc->info (irc->info_cls,
NULL, zbw, zbw, 0, 0);
- GNUNET_CLIENT_disconnect (irc->client);
+ GNUNET_CLIENT_disconnect (irc->client, GNUNET_NO);
GNUNET_free (irc);
return;
}
if (irc->info != NULL)
irc->info (irc->info_cls,
NULL, zbw, zbw, 0, 0);
- GNUNET_CLIENT_disconnect (irc->client);
+ GNUNET_CLIENT_disconnect (irc->client, GNUNET_NO);
GNUNET_free (irc);
return;
}
cim->bw_out,
ntohl (cim->reserved_amount),
GNUNET_ntohll (cim->preference));
- GNUNET_CLIENT_disconnect (irc->client);
+ GNUNET_CLIENT_disconnect (irc->client, GNUNET_NO);
GNUNET_free (irc);
}
void
GNUNET_CORE_peer_change_preference_cancel (struct GNUNET_CORE_InformationRequestContext *irc)
{
- GNUNET_CLIENT_disconnect (irc->client);
+ GNUNET_CLIENT_disconnect (irc->client, GNUNET_NO);
GNUNET_free (irc);
}
prh->cont,
prh->cont_cls,
GNUNET_SCHEDULER_REASON_TIMEOUT);
- GNUNET_CLIENT_disconnect (prh->client);
+ GNUNET_CLIENT_disconnect (prh->client, GNUNET_NO);
GNUNET_free (prh);
return 0;
}
prh->cont,
prh->cont_cls,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- GNUNET_CLIENT_disconnect (prh->client);
+ GNUNET_CLIENT_disconnect (prh->client, GNUNET_YES);
GNUNET_free (prh);
return sizeof (msg);
}
void
GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle *req)
{
- GNUNET_CLIENT_disconnect (req->client);
+ GNUNET_CLIENT_disconnect (req->client, GNUNET_NO);
GNUNET_free (req);
}
GNUNET_break (0);
}
if (h->client != NULL)
- GNUNET_CLIENT_disconnect (h->client);
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
GNUNET_ARM_stop_services (h->cfg, h->sched, "datastore", NULL);
GNUNET_free (h);
}
if (msg == NULL)
{
h->response_proc = NULL;
- GNUNET_CLIENT_disconnect (h->client);
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
h->client = GNUNET_CLIENT_connect (h->sched, "datastore", h->cfg);
cont (h->response_proc_cls,
GNUNET_SYSERR,
{
GNUNET_break (0);
h->response_proc = NULL;
- GNUNET_CLIENT_disconnect (h->client);
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
h->client = GNUNET_CLIENT_connect (h->sched, "datastore", h->cfg);
cont (h->response_proc_cls,
GNUNET_SYSERR,
if (msg == NULL)
{
h->response_proc = NULL;
- GNUNET_CLIENT_disconnect (h->client);
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
h->client = GNUNET_CLIENT_connect (h->sched, "datastore", h->cfg);
cont (h->response_proc_cls,
NULL, 0, NULL, 0, 0, 0,
(ntohs(msg->type) != GNUNET_MESSAGE_TYPE_DATASTORE_DATA) )
{
GNUNET_break (0);
- GNUNET_CLIENT_disconnect (h->client);
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
h->client = GNUNET_CLIENT_connect (h->sched, "datastore", h->cfg);
h->response_proc = NULL;
cont (h->response_proc_cls,
if (ntohs(msg->size) != msize + sizeof(struct DataMessage))
{
GNUNET_break (0);
- GNUNET_CLIENT_disconnect (h->client);
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
h->client = GNUNET_CLIENT_connect (h->sched, "datastore", h->cfg);
h->response_proc = NULL;
cont (h->response_proc_cls,
}
cont = h->response_proc;
h->response_proc = NULL;
- GNUNET_CLIENT_disconnect (h->client);
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
h->client = GNUNET_CLIENT_connect (h->sched, "datastore", h->cfg);
cont (h->response_proc_cls,
NULL, 0, NULL, 0, 0, 0,
* Handle for pending get request.
*/
struct GNUNET_STATISTICS_GetHandle *stat_get;
+
+ /**
+ * Pending task with scheduler for running the next request.
+ */
+ GNUNET_SCHEDULER_TaskIdentifier next_task;
/**
* How much data are we currently storing
struct GNUNET_TIME_Absolute expiration;
const GNUNET_HashCode *key;
const void *data;
-
-
+
plugin = nc->plugin;
+ plugin->next_task = GNUNET_SCHEDULER_NO_TASK;
if ( (GNUNET_YES == nc->end_it) ||
(GNUNET_OK != (nc->prep(nc->prep_cls,
nc))) )
if (GNUNET_YES == end_it)
nc->end_it = GNUNET_YES;
- GNUNET_SCHEDULER_add_continuation (nc->plugin->env->sched,
- &sqlite_next_request_cont,
- nc,
- GNUNET_SCHEDULER_REASON_PREREQ_DONE);
+ nc->plugin->next_task = GNUNET_SCHEDULER_add_now (nc->plugin->env->sched,
+ &sqlite_next_request_cont,
+ nc);
}
GNUNET_STATISTICS_get_cancel (plugin->stat_get);
plugin->stat_get = NULL;
}
+ if (plugin->next_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (plugin->env->sched,
+ plugin->next_task);
+ plugin->next_task = GNUNET_SCHEDULER_NO_TASK;
+ }
fn = NULL;
if (plugin->drop_on_shutdown)
fn = GNUNET_strdup (plugin->fn);
}
if (handle->client != NULL) /* Finally, disconnect from the service */
{
- GNUNET_CLIENT_disconnect (handle->client);
+ GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
handle->client = NULL;
}
{
// FIXME: serialize state!? (or is it always serialized???)
// FIXME: terminate receive-loop with client
- GNUNET_CLIENT_disconnect (h->client);
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
GNUNET_free (h->client_name);
GNUNET_free (h);
}
GNUNET_CLIENT_notify_transmit_ready_cancel (dc->th);
dc->th = NULL;
}
- GNUNET_CLIENT_disconnect (dc->client);
+ GNUNET_CLIENT_disconnect (dc->client, GNUNET_NO);
dc->client = NULL;
return GNUNET_NO;
}
GNUNET_CLIENT_notify_transmit_ready_cancel (dc->th);
dc->th = NULL;
}
- GNUNET_CLIENT_disconnect (dc->client);
+ GNUNET_CLIENT_disconnect (dc->client, GNUNET_NO);
dc->client = NULL;
GNUNET_free (sm);
return GNUNET_NO;
GNUNET_CONTAINER_multihashmap_iterate (dc->active,
&retry_entry,
dc);
- GNUNET_CLIENT_disconnect (dc->client);
+ GNUNET_CLIENT_disconnect (dc->client, GNUNET_NO);
dc->client = NULL;
}
dc->task
GNUNET_CONTAINER_meta_data_destroy (dc->meta);
GNUNET_FS_uri_destroy (dc->uri);
GNUNET_free (dc->filename);
- GNUNET_CLIENT_disconnect (dc->client);
+ GNUNET_CLIENT_disconnect (dc->client, GNUNET_NO);
GNUNET_free (dc);
return NULL;
}
dc->th = NULL;
}
if (NULL != dc->client)
- GNUNET_CLIENT_disconnect (dc->client);
+ GNUNET_CLIENT_disconnect (dc->client, GNUNET_NO);
GNUNET_CONTAINER_multihashmap_iterate (dc->active,
&free_entry,
NULL);
gic->cont,
gic->cont_cls,
GNUNET_SCHEDULER_REASON_TIMEOUT);
- GNUNET_CLIENT_disconnect (gic->client);
+ GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
GNUNET_free (gic);
return;
}
gic->cont,
gic->cont_cls,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- GNUNET_CLIENT_disconnect (gic->client);
+ GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
GNUNET_free (gic);
return;
}
gic->cont,
gic->cont_cls,
GNUNET_SCHEDULER_REASON_TIMEOUT);
- GNUNET_CLIENT_disconnect (gic->client);
+ GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
GNUNET_free (gic);
return;
}
gic->cont,
gic->cont_cls,
GNUNET_SCHEDULER_REASON_PREREQ_DONE);
- GNUNET_CLIENT_disconnect (gic->client);
+ GNUNET_CLIENT_disconnect (gic->client, GNUNET_NO);
GNUNET_free (gic);
return;
}
const char *emsg;
uint16_t msize;
- GNUNET_CLIENT_disconnect (sc->client);
+ GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
sc->client = NULL;
p = sc->fi_pos;
if (msg == NULL)
{
if (NULL != sc->client)
{
- GNUNET_CLIENT_disconnect (sc->client);
+ GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
sc->client = NULL;
}
sc->task
sc->task);
sc->task = GNUNET_SCHEDULER_NO_TASK;
if (NULL != sc->client)
- GNUNET_CLIENT_disconnect (sc->client);
+ GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
sc->client = NULL;
// FIXME: make persistent!
// FIXME: should this freeze all active probes?
GNUNET_SCHEDULER_cancel (sc->h->sched,
sc->task);
if (NULL != sc->client)
- GNUNET_CLIENT_disconnect (sc->client);
+ GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO);
GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
for (i=0;i<sc->uri->data.ksk.keywordCount;i++)
GNUNET_CONTAINER_multihashmap_destroy (sc->requests[i].results);
{
struct GNUNET_FS_UnindexContext *uc = cls;
- GNUNET_CLIENT_disconnect (uc->client);
+ GNUNET_CLIENT_disconnect (uc->client, GNUNET_NO);
uc->client = NULL;
if (uc->state != UNINDEX_STATE_FS_NOTIFY)
{
int do_ignore);
+
/**
* Destroy connection with the service. This will automatically
* cancel any pending "receive" request (however, the handler will
* *NOT* be called, not even with a NULL message). Any pending
* transmission request will also be cancelled UNLESS the callback for
* the transmission request has already been called, in which case the
- * transmission is guaranteed to complete before the socket is fully
- * destroyed (unless, of course, there is an error with the server
- * in which case the message may still be lost).
+ * transmission 'finish_pending_write' argument determines whether or
+ * not the write is guaranteed to complete before the socket is fully
+ * destroyed (unless, of course, there is an error with the server in
+ * which case the message may still be lost).
*
* @param sock handle to the service connection
+ * @param finish_pending_write should a transmission already passed to the
+ * handle be completed?
*/
-void GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock);
+void GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock,
+ int finish_pending_write);
/**
* Type of a function to call when we receive a message
*sock, void **addr,\r
size_t * addrlen);\r
\r
+\r
/**\r
- * Close the socket and free associated resources. Pending\r
- * transmissions are simply dropped. A pending receive call will be\r
- * called with an error code of "EPIPE".\r
+ * Close the socket and free associated resources. Pending\r
+ * transmissions may be completed or dropped depending on the\r
+ * arguments. If a receive call is pending and should \r
+ * NOT be completed, 'GNUNET_CONNECTION_receive_cancel'\r
+ * should be called explicitly first.\r
*\r
* @param sock socket to destroy\r
+ * @param finish_pending_write should pending writes be completed or aborted?\r
+ * (this applies to transmissions where the data has already been\r
+ * read from the application; all other transmissions should be\r
+ * aborted using 'GNUNET_CONNECTION_notify_transmit_ready_cancel').\r
*/\r
-void GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle\r
- *sock);\r
+void\r
+GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock,\r
+ int finish_pending_write);\r
\r
\r
/**\r
ntohs (msg->type), "peerinfo");
#endif
GNUNET_free (msg);
- GNUNET_CLIENT_disconnect (cc->client);
+ GNUNET_CLIENT_disconnect (cc->client, GNUNET_NO);
GNUNET_free (cc);
return 0;
}
GNUNET_assert (size >= msize);
memcpy (buf, msg, msize);
GNUNET_free (msg);
- GNUNET_CLIENT_disconnect (cc->client);
+ GNUNET_CLIENT_disconnect (cc->client, GNUNET_YES);
GNUNET_free (cc);
return msize;
}
_("Failed to receive response from `%s' service.\n"),
"peerinfo");
ic->callback (ic->callback_cls, NULL, NULL, 1);
- GNUNET_CLIENT_disconnect (ic->client);
+ GNUNET_CLIENT_disconnect (ic->client, GNUNET_NO);
GNUNET_free (ic);
return;
}
"Received end of list of peers from peerinfo database\n");
#endif
ic->callback (ic->callback_cls, NULL, NULL, 0);
- GNUNET_CLIENT_disconnect (ic->client);
+ GNUNET_CLIENT_disconnect (ic->client, GNUNET_NO);
GNUNET_free (ic);
return;
}
{
GNUNET_break (0);
ic->callback (ic->callback_cls, NULL, NULL, 2);
- GNUNET_CLIENT_disconnect (ic->client);
+ GNUNET_CLIENT_disconnect (ic->client, GNUNET_NO);
GNUNET_free (ic);
return;
}
{
GNUNET_break (0);
ic->callback (ic->callback_cls, NULL, NULL, 2);
- GNUNET_CLIENT_disconnect (ic->client);
+ GNUNET_CLIENT_disconnect (ic->client, GNUNET_NO);
GNUNET_free (ic);
return;
}
ihc))
{
GNUNET_break (0);
- GNUNET_CLIENT_disconnect (ihc->client);
+ GNUNET_CLIENT_disconnect (ihc->client, GNUNET_NO);
GNUNET_free (ihc);
return NULL;
}
void
GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic)
{
- GNUNET_CLIENT_disconnect (ic->client);
+ GNUNET_CLIENT_disconnect (ic->client, GNUNET_NO);
GNUNET_free (ic);
}
if (msg == NULL)
{
- GNUNET_CLIENT_disconnect (nc->client);
+ GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO);
nc->client = GNUNET_CLIENT_connect (nc->sched, "peerinfo", nc->cfg);
request_notifications (nc);
return;
(ntohs (msg->type) != GNUNET_MESSAGE_TYPE_PEERINFO_INFO))
{
GNUNET_break (0);
- GNUNET_CLIENT_disconnect (nc->client);
+ GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO);
nc->client = GNUNET_CLIENT_connect (nc->sched, "peerinfo", nc->cfg);
request_notifications (nc);
return;
if (ms != sizeof (struct InfoMessage) + GNUNET_HELLO_size (hello))
{
GNUNET_break (0);
- GNUNET_CLIENT_disconnect (nc->client);
+ GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO);
nc->client = GNUNET_CLIENT_connect (nc->sched, "peerinfo", nc->cfg);
request_notifications (nc);
return;
nc->init = NULL;
if (buf == NULL)
{
- GNUNET_CLIENT_disconnect (nc->client);
+ GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO);
nc->client = GNUNET_CLIENT_connect (nc->sched, "peerinfo", nc->cfg);
request_notifications (nc);
return 0;
GNUNET_CLIENT_notify_transmit_ready_cancel (nc->init);
nc->init = NULL;
}
- GNUNET_CLIENT_disconnect (nc->client);
+ GNUNET_CLIENT_disconnect (nc->client, GNUNET_NO);
GNUNET_free (nc);
}
{
if (NULL != h->client)
{
- GNUNET_CLIENT_disconnect (h->client);
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
h->client = NULL;
}
#if DEBUG_STATISTICS
}
if (NULL != h->client)
{
- GNUNET_CLIENT_disconnect (h->client);
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
h->client = NULL;
}
finish (h, GNUNET_SYSERR);
}
if (h->client != NULL)
{
- GNUNET_CLIENT_disconnect (h->client);
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_YES);
h->client = NULL;
}
GNUNET_free (h->subsystem);
"Disconnecting from transport service for good.\n");
#endif
handle->client = NULL;
- GNUNET_CLIENT_disconnect (client);
+ GNUNET_CLIENT_disconnect (client, GNUNET_NO);
}
GNUNET_free (handle);
}
GNUNET_CLIENT_notify_transmit_ready_cancel (h->network_handle);
h->network_handle = NULL;
}
- GNUNET_CLIENT_disconnect (h->client);
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
h->client = NULL;
schedule_reconnect (h);
return;
{
/* timeout */
alucb->cb (alucb->cls, NULL);
- GNUNET_CLIENT_disconnect (alucb->client);
+ GNUNET_CLIENT_disconnect (alucb->client. GNUNET_NO);
GNUNET_free (alucb);
return;
}
/* invalid reply */
GNUNET_break_op (0);
alucb->cb (alucb->cls, NULL);
- GNUNET_CLIENT_disconnect (alucb->client);
+ GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
GNUNET_free (alucb);
return;
}
if (address == NULL)
{
/* done! */
- GNUNET_CLIENT_disconnect (alucb->client);
+ GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
GNUNET_free (alucb);
}
}
static void
retry_get_notifications (struct GNUNET_TRANSPORT_BlacklistNotification *bn)
{
- GNUNET_CLIENT_disconnect (bn->client);
+ GNUNET_CLIENT_disconnect (bn->client, GNUNET_NO);
bn->client = GNUNET_CLIENT_connect (bn->sched, "transport", bn->cfg);
request_notifications (bn);
}
{
if (bn->th != NULL)
GNUNET_CLIENT_notify_transmit_ready_cancel (bn->th);
- GNUNET_CLIENT_disconnect (bn->client);
+ GNUNET_CLIENT_disconnect (bn->client, GNUNET_NO);
GNUNET_free (bn);
}
* *NOT* be called, not even with a NULL message). Any pending
* transmission request will also be cancelled UNLESS the callback for
* the transmission request has already been called, in which case the
- * transmission is guaranteed to complete before the socket is fully
- * destroyed (unless, of course, there is an error with the server
- * in which case the message may still be lost).
+ * transmission 'finish_pending_write' argument determines whether or
+ * not the write is guaranteed to complete before the socket is fully
+ * destroyed (unless, of course, there is an error with the server in
+ * which case the message may still be lost).
*
+ * @param finish_pending_write should a transmission already passed to the
+ * handle be completed?
* @param sock handle to the service connection
*/
void
-GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock)
+GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock,
+ int finish_pending_write)
{
GNUNET_assert (sock->sock != NULL);
if (sock->in_receive == GNUNET_YES)
GNUNET_CONNECTION_receive_cancel (sock->sock);
sock->in_receive = GNUNET_NO;
}
- GNUNET_CONNECTION_destroy (sock->sock);
+ GNUNET_CONNECTION_destroy (sock->sock, finish_pending_write);
sock->sock = NULL;
if (sock->tag != NULL)
{
struct GNUNET_MessageHeader *msg;
struct GNUNET_CLIENT_Connection *sock = cls;
- GNUNET_CLIENT_disconnect (sock);
+ GNUNET_CLIENT_disconnect (sock, GNUNET_YES);
if (size < sizeof (struct GNUNET_MessageHeader))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
{
service_test_error (conn->sched, conn->test_cb, conn->test_cb_cls);
}
- GNUNET_CLIENT_disconnect (conn);
+ GNUNET_CLIENT_disconnect (conn, GNUNET_NO);
}
_("Failure to transmit request to service `%s'\n"),
service);
service_test_error (sched, task, task_cls);
- GNUNET_CLIENT_disconnect (conn);
+ GNUNET_CLIENT_disconnect (conn, GNUNET_NO);
return;
}
}
return 0;
}
/* auto-retry */
- GNUNET_CONNECTION_destroy (th->sock->sock);
+ GNUNET_CONNECTION_destroy (th->sock->sock, GNUNET_NO);
th->sock->sock = do_connect (th->sock->sched,
th->sock->service_name, th->sock->cfg);
GNUNET_assert (NULL != th->sock->sock);
GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile)
{
FILE *altlog;
+ int dirwarn;
GNUNET_free_non_null (component);
GNUNET_asprintf (&component,
min_level = get_type (loglevel);
if (logfile == NULL)
return GNUNET_OK;
- if (GNUNET_OK !=
- GNUNET_DISK_directory_create_for_file (logfile))
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Failed to create or access directory for log file `%s'"),
- logfile);
+ dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (logfile));
altlog = FOPEN (logfile, "a");
if (altlog == NULL)
{
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", logfile);
+ if (dirwarn)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Failed to create or access directory for log file `%s'\n"),
+ logfile);
return GNUNET_SYSERR;
}
if (GNUNET_stderr != NULL)
/**
* Close the socket and free associated resources. Pending
- * transmissions are simply dropped. A pending receive call will be
- * called with an error code of "EPIPE".
+ * 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.
*
* @param sock socket to destroy
+ * @param finish_pending_write should pending writes be completed or aborted?
+ * (this applies to transmissions where the data has already been
+ * read from the application; all other transmissions should be
+ * aborted using 'GNUNET_CONNECTION_notify_transmit_ready_cancel').
*/
void
-GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock)
+GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock,
+ int finish_pending_write)
{
if ((sock->write_buffer_off == 0) && (sock->dns_active != NULL))
{
GNUNET_RESOLVER_request_cancel (sock->dns_active);
sock->dns_active = NULL;
}
+ if (GNUNET_NO == finish_pending_write)
+ {
+ if (sock->write_task != GNUNET_SCHEDULER_NO_TASK)
+ {
+ GNUNET_SCHEDULER_cancel (sock->sched,
+ sock->write_task);
+ sock->write_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+ }
GNUNET_assert (sock->sched != NULL);
GNUNET_SCHEDULER_add_now (sock->sched,
&destroy_continuation, 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);
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ {
+ if (sock->ignore_shutdown == GNUNET_YES)
+ goto SCHEDULE_WRITE; /* ignore shutdown, go again immediately */
+#if DEBUG_CONNECTION
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmit to `%s' fails, shutdown happened (%p).\n",
+ GNUNET_a2s (sock->addr, sock->addrlen), sock);
+#endif
+ notify = sock->nth.notify_ready;
+ sock->nth.notify_ready = NULL;
+ notify (sock->nth.notify_ready_cls, 0, NULL);
+ return;
+ }
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
{
#if DEBUG_CONNECTION
_("Timeout trying to resolve hostname `%s'.\n"),
rh->hostname);
rh->addr_callback (rh->cls, NULL, 0);
- GNUNET_CLIENT_disconnect (rh->client);
+ GNUNET_CLIENT_disconnect (rh->client, GNUNET_NO);
GNUNET_free (rh);
return;
}
{
GNUNET_break (0);
rh->addr_callback (rh->cls, NULL, 0);
- GNUNET_CLIENT_disconnect (rh->client);
+ GNUNET_CLIENT_disconnect (rh->client, GNUNET_NO);
GNUNET_free (rh);
return;
}
rh->hostname);
#endif
rh->addr_callback (rh->cls, NULL, 0);
- GNUNET_CLIENT_disconnect (rh->client);
+ GNUNET_CLIENT_disconnect (rh->client, GNUNET_NO);
GNUNET_free (rh);
return;
}
{
GNUNET_break (0);
rh->addr_callback (rh->cls, NULL, 0);
- GNUNET_CLIENT_disconnect (rh->client);
+ GNUNET_CLIENT_disconnect (rh->client, GNUNET_NO);
GNUNET_free (rh);
return;
}
&handle_address_response, rh))
{
GNUNET_free (rh);
- GNUNET_CLIENT_disconnect (client);
+ GNUNET_CLIENT_disconnect (client, GNUNET_NO);
return NULL;
}
return rh;
_("Timeout trying to resolve IP address `%s'.\n"),
GNUNET_a2s ((const void*) &rh[1], rh->salen));
rh->name_callback (rh->cls, NULL);
- GNUNET_CLIENT_disconnect (rh->client);
+ GNUNET_CLIENT_disconnect (rh->client, GNUNET_NO);
GNUNET_free (rh);
return;
}
GNUNET_a2s ((const void*) &rh[1], rh->salen));
#endif
rh->name_callback (rh->cls, NULL);
- GNUNET_CLIENT_disconnect (rh->client);
+ GNUNET_CLIENT_disconnect (rh->client, GNUNET_NO);
GNUNET_free (rh);
return;
}
{
GNUNET_break (0);
rh->name_callback (rh->cls, NULL);
- GNUNET_CLIENT_disconnect (rh->client);
+ GNUNET_CLIENT_disconnect (rh->client, GNUNET_NO);
GNUNET_free (rh);
return;
}
GNUNET_YES,
&handle_hostname_response, rh))
{
- GNUNET_CLIENT_disconnect (client);
+ GNUNET_CLIENT_disconnect (client, GNUNET_NO);
GNUNET_free (rh);
return NULL;
}
GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *h)
{
if (h->client != NULL)
- GNUNET_CLIENT_disconnect (h->client);
+ GNUNET_CLIENT_disconnect (h->client, GNUNET_NO);
if (h->task != GNUNET_SCHEDULER_NO_TASK)
GNUNET_SCHEDULER_cancel (h->sched, h->task);
GNUNET_free (h);
static void
sock_destroy (void *cls)
{
- GNUNET_CONNECTION_destroy (cls);
+ GNUNET_CONNECTION_destroy (cls, GNUNET_NO);
}
msg.size = htons (sizeof (struct GNUNET_MessageHeader));
GNUNET_assert (0 ==
memcmp (got, &msg, sizeof (struct GNUNET_MessageHeader)));
- GNUNET_CLIENT_disconnect (client);
+ GNUNET_CLIENT_disconnect (client, GNUNET_YES);
client = NULL;
GNUNET_SERVER_destroy (server);
server = NULL;
"Receive closes accepted socket\n");
#endif
*ok = 0;
- GNUNET_CONNECTION_destroy (asock);
+ GNUNET_CONNECTION_destroy (asock, GNUNET_YES);
}
}
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test destroys listen socket\n");
#endif
- GNUNET_CONNECTION_destroy (lsock);
+ GNUNET_CONNECTION_destroy (lsock, GNUNET_YES);
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Test asks to receive on accepted socket\n");
#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test destroys client socket\n");
#endif
- GNUNET_CONNECTION_destroy (csock);
+ GNUNET_CONNECTION_destroy (csock, GNUNET_YES);
return 12;
}
else
{
*ok = 0;
- GNUNET_CONNECTION_destroy (asock);
+ GNUNET_CONNECTION_destroy (asock, GNUNET_YES);
}
}
expect.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
GNUNET_assert (0 == memcmp (&expect, v4, alen));
GNUNET_free (addr);
- GNUNET_CONNECTION_destroy (lsock);
+ GNUNET_CONNECTION_destroy (lsock, GNUNET_YES);
GNUNET_CONNECTION_receive (asock,
1024,
GNUNET_TIME_relative_multiply
12,
GNUNET_TIME_UNIT_SECONDS,
&make_hello, NULL));
- GNUNET_CONNECTION_destroy (csock);
+ GNUNET_CONNECTION_destroy (csock, GNUNET_YES);
GNUNET_SCHEDULER_add_read_net (tc->sched,
GNUNET_TIME_UNIT_FOREVER_REL,
ls, &run_accept, cls);
NULL, NULL, ls, 1024);
GNUNET_assert (asock != NULL);
GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock));
- GNUNET_CONNECTION_destroy (lsock);
+ GNUNET_CONNECTION_destroy (lsock, GNUNET_YES);
GNUNET_CONNECTION_receive (asock,
1024,
GNUNET_TIME_relative_multiply
{
int *ok = cls;
GNUNET_CONNECTION_receive_cancel (asock);
- GNUNET_CONNECTION_destroy (csock);
- GNUNET_CONNECTION_destroy (asock);
+ GNUNET_CONNECTION_destroy (csock, GNUNET_YES);
+ GNUNET_CONNECTION_destroy (asock, GNUNET_YES);
*ok = 0;
}
#endif
GNUNET_assert (buf == NULL);
*ok = 0;
- GNUNET_CONNECTION_destroy (lsock);
- GNUNET_CONNECTION_destroy (csock);
+ GNUNET_CONNECTION_destroy (lsock, GNUNET_YES);
+ GNUNET_CONNECTION_destroy (csock, GNUNET_YES);
return 0;
}
#if VERBOSE
GNUNET_TIME_UNIT_MINUTES,
¬_run, cls);
GNUNET_CONNECTION_notify_transmit_ready_cancel (th);
- GNUNET_CONNECTION_destroy (csock);
+ GNUNET_CONNECTION_destroy (csock, GNUNET_YES);
*ok = 0;
}
GNUNET_assert (msg == NULL);
GNUNET_assert (ok == 7);
ok = 0;
- GNUNET_CLIENT_disconnect (client);
+ GNUNET_CLIENT_disconnect (client, GNUNET_YES);
client = NULL;
GNUNET_SERVER_destroy (server);
server = NULL;
break;
case 4:
ok++;
- GNUNET_CLIENT_disconnect (client);
+ GNUNET_CLIENT_disconnect (client, GNUNET_YES);
GNUNET_SERVER_receive_done (argclient, GNUNET_OK);
break;
default: