aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-01-13 22:14:11 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-01-13 22:14:11 +0000
commit3c61c59e70103d21f9b3f645108f51f7a34b77fc (patch)
treedcf7c0fb5cb46ae97ce20aa8832519745ccb620b /src
parentfb1390dfeb7e98a404207988f13341522f3692b6 (diff)
downloadgnunet-3c61c59e70103d21f9b3f645108f51f7a34b77fc.tar.gz
gnunet-3c61c59e70103d21f9b3f645108f51f7a34b77fc.zip
added half-closed shutdown test
Diffstat (limited to 'src')
-rw-r--r--src/stream/test_stream_local.c52
1 files changed, 40 insertions, 12 deletions
diff --git a/src/stream/test_stream_local.c b/src/stream/test_stream_local.c
index 985d25e36..32e3bf2e4 100644
--- a/src/stream/test_stream_local.c
+++ b/src/stream/test_stream_local.c
@@ -49,9 +49,14 @@ static GNUNET_STREAM_IOHandle *peer2_IOHandle;
49static char *data = "ABCD"; 49static char *data = "ABCD";
50static unsigned int data_pointer; 50static unsigned int data_pointer;
51static unsigned int read_pointer; 51static unsigned int read_pointer;
52static int result 52static int result;
53 53
54static int test1_success_counter; 54static int peer1_write_pass;
55static int peer2_read_pass;
56static int peer1_half_closed_write_pass;
57static int peer2_half_closed_read_pass;
58static int peer1_write_shutdown_pass;
59static int peer1_read_shutdown_pass;
55 60
56 61
57/** 62/**
@@ -112,12 +117,12 @@ void write_completion (void *cls,
112 size_t size) 117 size_t size)
113{ 118{
114 119
115 if (3 == test1_success_counter) /* Called for peer2's write operation */ 120 if (peer1_write_shutdown_pass) /* Called for peer2's write operation */
116 { 121 {
117 /* peer1 has shutdown reading */ 122 /* peer1 has shutdown reading */
118 GNUNET_assert (GNUNET_STREAM_SHUTDOWN == status); 123 GNUNET_assert (GNUNET_STREAM_SHUTDOWN == status);
119 GNUNET_assert (0 == size); 124 GNUNET_assert (0 == size);
120 test1_success_counter ++; 125 peer1_read_shutdown_pass = 1;
121 126
122 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 127 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
123 } 128 }
@@ -134,9 +139,28 @@ void write_completion (void *cls,
134 NULL); 139 NULL);
135 GNUNET_assert (NULL != peer1_IOHandle); 140 GNUNET_assert (NULL != peer1_IOHandle);
136 } 141 }
137 else{ /* Close peer1 socket */ 142 else{
138 test1_success_counter++; 143 peer1_write_pass = 1;
139 GNUNET_STREAM_shutdown (peer1_socket, SHUT_RDWR); 144 /* If we are here and peer2_read_pass == 1 => we have send the data twice */
145 if (peer2_read_pass) peer1_half_closed_write_pass = 1;
146
147 if (! peer1_half_closed_write_pass)
148 {
149 GNUNET_STREAM_shutdown (peer1_socket, SHUT_RD);
150 /* Half closed write */
151 data_pointer = 0;
152 peer1_IOHandle = GNUNET_STREAM_write (peer1_socket,
153 (void *) data,
154 strlen(data),
155 GNUNET_TIME_relative_multiply
156 (GNUNET_TIME_UNIT_SECONDS, 5),
157 &write_completion,
158 NULL);
159 }
160 else
161 {
162 GNUNET_STREAM_shutdown (peer1_socket, SHUT_WR);
163 }
140 } 164 }
141} 165}
142 166
@@ -183,11 +207,11 @@ input_processor (void *cls,
183 size_t size) 207 size_t size)
184{ 208{
185 209
186 if (2 == test1_success_counter) 210 if (peer2_half_closed_read_pass)
187 { 211 {
188 GNUNET_assert (GNUNET_STREAM_SHUTDOWN == status); 212 GNUNET_assert (GNUNET_STREAM_SHUTDOWN == status);
189 GNUNET_assert (0 == size); 213 GNUNET_assert (0 == size);
190 test1_success_counter ++; 214 peer1_write_shutdown_pass = 1;
191 /* Now this should result in STREAM_SHUTDOWN */ 215 /* Now this should result in STREAM_SHUTDOWN */
192 peer2_IOHandle = GNUNET_STREAM_write (peer2_socket, 216 peer2_IOHandle = GNUNET_STREAM_write (peer2_socket,
193 (void *) data, 217 (void *) data,
@@ -217,8 +241,12 @@ input_processor (void *cls,
217 GNUNET_assert (NULL != peer2_IOHandle); 241 GNUNET_assert (NULL != peer2_IOHandle);
218 } 242 }
219 else { 243 else {
220 test1_success_counter ++; 244 /* If we are here and peer2_read_pass => we have finished reading twice */
221 /* This time should the read status should be STERAM_SHUTDOWN */ 245 if (peer1_write_pass && peer2_read_pass) peer2_half_closed_read_pass = 1;
246 if (peer1_write_pass) peer2_read_pass = 1;
247
248 /* Half closed read */
249 read_pointer = 0;
222 peer2_IOHandle = GNUNET_STREAM_read ((struct GNUNET_STREAM_Socket *) cls, 250 peer2_IOHandle = GNUNET_STREAM_read ((struct GNUNET_STREAM_Socket *) cls,
223 GNUNET_TIME_relative_multiply 251 GNUNET_TIME_relative_multiply
224 (GNUNET_TIME_UNIT_SECONDS, 5), 252 (GNUNET_TIME_UNIT_SECONDS, 5),
@@ -283,7 +311,7 @@ static void
283test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 311test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
284{ 312{
285 test_task = GNUNET_SCHEDULER_NO_TASK; 313 test_task = GNUNET_SCHEDULER_NO_TASK;
286 test1_success_counter = 0; 314
287 /* Connect to stream library */ 315 /* Connect to stream library */
288 peer1_socket = GNUNET_STREAM_open (NULL, /* Null for local peer? */ 316 peer1_socket = GNUNET_STREAM_open (NULL, /* Null for local peer? */
289 10, /* App port */ 317 10, /* App port */