[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r19130 - gnunet/src/stream
From: |
gnunet |
Subject: |
[GNUnet-SVN] r19130 - gnunet/src/stream |
Date: |
Fri, 13 Jan 2012 23:14:11 +0100 |
Author: harsha
Date: 2012-01-13 23:14:11 +0100 (Fri, 13 Jan 2012)
New Revision: 19130
Modified:
gnunet/src/stream/test_stream_local.c
Log:
added half-closed shutdown test
Modified: gnunet/src/stream/test_stream_local.c
===================================================================
--- gnunet/src/stream/test_stream_local.c 2012-01-13 22:10:16 UTC (rev
19129)
+++ gnunet/src/stream/test_stream_local.c 2012-01-13 22:14:11 UTC (rev
19130)
@@ -49,9 +49,14 @@
static char *data = "ABCD";
static unsigned int data_pointer;
static unsigned int read_pointer;
-static int result
+static int result;
-static int test1_success_counter;
+static int peer1_write_pass;
+static int peer2_read_pass;
+static int peer1_half_closed_write_pass;
+static int peer2_half_closed_read_pass;
+static int peer1_write_shutdown_pass;
+static int peer1_read_shutdown_pass;
/**
@@ -112,12 +117,12 @@
size_t size)
{
- if (3 == test1_success_counter) /* Called for peer2's write operation */
+ if (peer1_write_shutdown_pass) /* Called for peer2's write operation */
{
/* peer1 has shutdown reading */
GNUNET_assert (GNUNET_STREAM_SHUTDOWN == status);
GNUNET_assert (0 == size);
- test1_success_counter ++;
+ peer1_read_shutdown_pass = 1;
GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
}
@@ -134,9 +139,28 @@
NULL);
GNUNET_assert (NULL != peer1_IOHandle);
}
- else{ /* Close peer1 socket */
- test1_success_counter++;
- GNUNET_STREAM_shutdown (peer1_socket, SHUT_RDWR);
+ else{
+ peer1_write_pass = 1;
+ /* If we are here and peer2_read_pass == 1 => we have send the data twice
*/
+ if (peer2_read_pass) peer1_half_closed_write_pass = 1;
+
+ if (! peer1_half_closed_write_pass)
+ {
+ GNUNET_STREAM_shutdown (peer1_socket, SHUT_RD);
+ /* Half closed write */
+ data_pointer = 0;
+ peer1_IOHandle = GNUNET_STREAM_write (peer1_socket,
+ (void *) data,
+ strlen(data),
+ GNUNET_TIME_relative_multiply
+ (GNUNET_TIME_UNIT_SECONDS, 5),
+ &write_completion,
+ NULL);
+ }
+ else
+ {
+ GNUNET_STREAM_shutdown (peer1_socket, SHUT_WR);
+ }
}
}
@@ -183,11 +207,11 @@
size_t size)
{
- if (2 == test1_success_counter)
+ if (peer2_half_closed_read_pass)
{
GNUNET_assert (GNUNET_STREAM_SHUTDOWN == status);
GNUNET_assert (0 == size);
- test1_success_counter ++;
+ peer1_write_shutdown_pass = 1;
/* Now this should result in STREAM_SHUTDOWN */
peer2_IOHandle = GNUNET_STREAM_write (peer2_socket,
(void *) data,
@@ -217,8 +241,12 @@
GNUNET_assert (NULL != peer2_IOHandle);
}
else {
- test1_success_counter ++;
- /* This time should the read status should be STERAM_SHUTDOWN */
+ /* If we are here and peer2_read_pass => we have finished reading twice */
+ if (peer1_write_pass && peer2_read_pass) peer2_half_closed_read_pass = 1;
+ if (peer1_write_pass) peer2_read_pass = 1;
+
+ /* Half closed read */
+ read_pointer = 0;
peer2_IOHandle = GNUNET_STREAM_read ((struct GNUNET_STREAM_Socket *) cls,
GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 5),
@@ -283,7 +311,7 @@
test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
test_task = GNUNET_SCHEDULER_NO_TASK;
- test1_success_counter = 0;
+
/* Connect to stream library */
peer1_socket = GNUNET_STREAM_open (NULL, /* Null for local peer? */
10, /* App port */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r19130 - gnunet/src/stream,
gnunet <=