- fixes
authorSree Harsha Totakura <totakura@in.tum.de>
Mon, 19 Nov 2012 15:02:23 +0000 (15:02 +0000)
committerSree Harsha Totakura <totakura@in.tum.de>
Mon, 19 Nov 2012 15:02:23 +0000 (15:02 +0000)
src/stream/perf_stream_api.c
src/stream/test_stream_big.c
src/stream/test_stream_sequence_wraparound.c

index 3c1d56f84d137ff9a885f74f4eea6c620ee7a9eb..cd68310bca348b49790134c0cc4720f36076fb5b 100644 (file)
@@ -125,6 +125,11 @@ struct PeerData
    */
   struct GNUNET_PeerIdentity id;
 
+  /**
+   * Peer's shutdown handle
+   */
+  struct GNUNET_STREAM_ShutdownHandle *shutdown_handle;
+
   /**
    * Bytes the peer has written
    */
@@ -372,7 +377,7 @@ free_meter (struct ProgressMeter *meter)
  * Shutdown nicely
  */
 static void
-do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_close (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   switch (test_step)
   {
@@ -419,7 +424,34 @@ do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   if (GNUNET_SCHEDULER_NO_TASK != read_task)
     GNUNET_SCHEDULER_cancel (read_task);
   result = GNUNET_SYSERR;
-  do_shutdown (cls, tc);
+  do_close (cls, tc);
+}
+
+
+/**
+ * Completion callback for shutdown
+ *
+ * @param cls the closure from GNUNET_STREAM_shutdown call
+ * @param operation the operation that was shutdown (SHUT_RD, SHUT_WR,
+ *          SHUT_RDWR) 
+ */
+static void 
+shutdown_completion (void *cls,
+                     int operation)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "STREAM shutdown successful\n");
+  GNUNET_SCHEDULER_add_now (&do_close, cls);
+}
+
+
+/**
+ * Shutdown sockets gracefully
+ */
+static void
+do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  peer_data[0].shutdown_handle = GNUNET_STREAM_shutdown (peer_data[0].socket, SHUT_RDWR,
+                                                         &shutdown_completion, cls);
 }
 
   
index 05da826913eb8ca55798c9bf7c51de6f94def5de..d5875dd55ea4bb40ecbd22466dfeb5cd99a274b5 100644 (file)
@@ -60,6 +60,11 @@ struct PeerData
    */
   struct GNUNET_STREAM_IOReadHandle *io_read_handle;
 
+  /**
+   * Peer's shutdown handle
+   */
+  struct GNUNET_STREAM_ShutdownHandle *shutdown_handle;
+
   /**
    * Bytes the peer has written
    */
@@ -88,19 +93,16 @@ static int result;
  * Shutdown nicely
  */
 static void
-do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_close (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  if (GNUNET_SCHEDULER_NO_TASK != abort_task)
+    GNUNET_SCHEDULER_cancel (abort_task);
   if (NULL != peer1.socket)
     GNUNET_STREAM_close (peer1.socket);
   if (NULL != peer2.socket)
     GNUNET_STREAM_close (peer2.socket);
   if (NULL != peer2_listen_socket)
     GNUNET_STREAM_listen_close (peer2_listen_socket); /* Close listen socket */
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: shutdown\n");
-  if (GNUNET_SCHEDULER_NO_TASK != abort_task)
-    GNUNET_SCHEDULER_cancel (abort_task);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Wait\n");
-  GNUNET_SCHEDULER_shutdown ();
 }
 
 
@@ -115,7 +117,35 @@ do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
       GNUNET_SCHEDULER_cancel (read_task);
   result = GNUNET_SYSERR;
   abort_task = GNUNET_SCHEDULER_NO_TASK;
-  do_shutdown (cls, tc);
+  do_close (cls, tc);
+}
+
+
+/**
+ * Completion callback for shutdown
+ *
+ * @param cls the closure from GNUNET_STREAM_shutdown call
+ * @param operation the operation that was shutdown (SHUT_RD, SHUT_WR,
+ *          SHUT_RDWR) 
+ */
+static void 
+shutdown_completion (void *cls,
+                     int operation)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "STREAM shutdown successful\n");
+  GNUNET_SCHEDULER_add_now (&do_close, cls);
+}
+
+
+/**
+ * Shutdown sockets gracefully
+ */
+static void
+do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  result = GNUNET_OK;
+  peer1.shutdown_handle = GNUNET_STREAM_shutdown (peer1.socket, SHUT_RDWR,
+                                                  &shutdown_completion, cls);
 }
 
 
index f231716614dfddafff3fc101ee6dff245f147279..61e28cf7298e4282b181d6391fe1422a07011b72 100644 (file)
@@ -63,6 +63,11 @@ struct PeerData
    */
   struct GNUNET_STREAM_IOReadHandle *io_read_handle;
 
+  /**
+   * Peer's shutdown handle
+   */
+  struct GNUNET_STREAM_ShutdownHandle *shutdown_handle;
+
   /**
    * Bytes the peer has written
    */
@@ -93,19 +98,16 @@ static int result;
  * Shutdown nicely
  */
 static void
-do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_close (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  if (GNUNET_SCHEDULER_NO_TASK != abort_task)
+    GNUNET_SCHEDULER_cancel (abort_task);
   if (NULL != peer1.socket)
     GNUNET_STREAM_close (peer1.socket);
   if (NULL != peer2.socket)
     GNUNET_STREAM_close (peer2.socket);
   if (NULL != peer2_listen_socket)
     GNUNET_STREAM_listen_close (peer2_listen_socket); /* Close listen socket */
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: shutdown\n");
-  if (0 != abort_task)
-  {
-    GNUNET_SCHEDULER_cancel (abort_task);
-  }
 }
 
 
@@ -121,8 +123,36 @@ do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
       GNUNET_SCHEDULER_cancel (read_task);
     }
   result = GNUNET_SYSERR;
-  abort_task = 0;
-  do_shutdown (cls, tc);
+  abort_task = GNUNET_SCHEDULER_NO_TASK;
+  do_close (cls, tc);
+}
+
+
+/**
+ * Completion callback for shutdown
+ *
+ * @param cls the closure from GNUNET_STREAM_shutdown call
+ * @param operation the operation that was shutdown (SHUT_RD, SHUT_WR,
+ *          SHUT_RDWR) 
+ */
+static void 
+shutdown_completion (void *cls,
+                     int operation)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "STREAM shutdown successful\n");
+  GNUNET_SCHEDULER_add_now (&do_close, cls);
+}
+
+
+/**
+ * Shutdown sockets gracefully
+ */
+static void
+do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  result = GNUNET_OK;
+  peer1.shutdown_handle = GNUNET_STREAM_shutdown (peer1.socket, SHUT_RDWR,
+                                                  &shutdown_completion, cls);
 }