aboutsummaryrefslogtreecommitdiff
path: root/src/util/connection.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-03-12 13:29:05 +0000
committerChristian Grothoff <christian@grothoff.org>2010-03-12 13:29:05 +0000
commita6f43190ab793b3487da2133735e166e337000c4 (patch)
treefc2dacc6a36f3ec04cf86a14cdea9c5bdf45274f /src/util/connection.c
parent61cfd3340e67672f351ab92dab7da72dca058c79 (diff)
downloadgnunet-a6f43190ab793b3487da2133735e166e337000c4.tar.gz
gnunet-a6f43190ab793b3487da2133735e166e337000c4.zip
cancel pending write if we are just dead anyway
Diffstat (limited to 'src/util/connection.c')
-rw-r--r--src/util/connection.c36
1 files changed, 33 insertions, 3 deletions
diff --git a/src/util/connection.c b/src/util/connection.c
index b1e13a663..c572d02de 100644
--- a/src/util/connection.c
+++ b/src/util/connection.c
@@ -916,19 +916,35 @@ GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock)
916 916
917/** 917/**
918 * Close the socket and free associated resources. Pending 918 * Close the socket and free associated resources. Pending
919 * transmissions are simply dropped. A pending receive call will be 919 * transmissions may be completed or dropped depending on the
920 * called with an error code of "EPIPE". 920 * arguments. If a receive call is pending and should
921 * NOT be completed, 'GNUNET_CONNECTION_receive_cancel'
922 * should be called explicitly first.
921 * 923 *
922 * @param sock socket to destroy 924 * @param sock socket to destroy
925 * @param finish_pending_write should pending writes be completed or aborted?
926 * (this applies to transmissions where the data has already been
927 * read from the application; all other transmissions should be
928 * aborted using 'GNUNET_CONNECTION_notify_transmit_ready_cancel').
923 */ 929 */
924void 930void
925GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock) 931GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock,
932 int finish_pending_write)
926{ 933{
927 if ((sock->write_buffer_off == 0) && (sock->dns_active != NULL)) 934 if ((sock->write_buffer_off == 0) && (sock->dns_active != NULL))
928 { 935 {
929 GNUNET_RESOLVER_request_cancel (sock->dns_active); 936 GNUNET_RESOLVER_request_cancel (sock->dns_active);
930 sock->dns_active = NULL; 937 sock->dns_active = NULL;
931 } 938 }
939 if (GNUNET_NO == finish_pending_write)
940 {
941 if (sock->write_task != GNUNET_SCHEDULER_NO_TASK)
942 {
943 GNUNET_SCHEDULER_cancel (sock->sched,
944 sock->write_task);
945 sock->write_task = GNUNET_SCHEDULER_NO_TASK;
946 }
947 }
932 GNUNET_assert (sock->sched != NULL); 948 GNUNET_assert (sock->sched != NULL);
933 GNUNET_SCHEDULER_add_now (sock->sched, 949 GNUNET_SCHEDULER_add_now (sock->sched,
934 &destroy_continuation, sock); 950 &destroy_continuation, sock);
@@ -1316,6 +1332,20 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1316 GNUNET_assert (sock->write_task != GNUNET_SCHEDULER_NO_TASK); 1332 GNUNET_assert (sock->write_task != GNUNET_SCHEDULER_NO_TASK);
1317 sock->write_task = GNUNET_SCHEDULER_NO_TASK; 1333 sock->write_task = GNUNET_SCHEDULER_NO_TASK;
1318 GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK); 1334 GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK);
1335 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1336 {
1337 if (sock->ignore_shutdown == GNUNET_YES)
1338 goto SCHEDULE_WRITE; /* ignore shutdown, go again immediately */
1339#if DEBUG_CONNECTION
1340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1341 "Transmit to `%s' fails, shutdown happened (%p).\n",
1342 GNUNET_a2s (sock->addr, sock->addrlen), sock);
1343#endif
1344 notify = sock->nth.notify_ready;
1345 sock->nth.notify_ready = NULL;
1346 notify (sock->nth.notify_ready_cls, 0, NULL);
1347 return;
1348 }
1319 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) 1349 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
1320 { 1350 {
1321#if DEBUG_CONNECTION 1351#if DEBUG_CONNECTION