diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-01-13 21:33:47 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-01-13 21:33:47 +0000 |
commit | 8f2925beae5b4791ff1c0a592d10ad69f249bc7d (patch) | |
tree | 7bcbc4b3822cc5d64c59d5ef82b9d36bb5f0ac38 /src | |
parent | 45c741946d63f1734d9853896546a18d550abf96 (diff) | |
download | gnunet-8f2925beae5b4791ff1c0a592d10ad69f249bc7d.tar.gz gnunet-8f2925beae5b4791ff1c0a592d10ad69f249bc7d.zip |
added shutdown call in testcase
Diffstat (limited to 'src')
-rw-r--r-- | src/stream/test_stream_local.c | 63 |
1 files changed, 47 insertions, 16 deletions
diff --git a/src/stream/test_stream_local.c b/src/stream/test_stream_local.c index 9410d7df3..985d25e36 100644 --- a/src/stream/test_stream_local.c +++ b/src/stream/test_stream_local.c | |||
@@ -25,6 +25,7 @@ | |||
25 | */ | 25 | */ |
26 | 26 | ||
27 | #include <string.h> | 27 | #include <string.h> |
28 | #include <sys/socket.h> /* For SHUT_RD, SHUT_WR */ | ||
28 | 29 | ||
29 | #include "platform.h" | 30 | #include "platform.h" |
30 | #include "gnunet_util_lib.h" | 31 | #include "gnunet_util_lib.h" |
@@ -46,8 +47,8 @@ static GNUNET_STREAM_IOHandle *peer1_IOHandle; | |||
46 | static GNUNET_STREAM_IOHandle *peer2_IOHandle; | 47 | static GNUNET_STREAM_IOHandle *peer2_IOHandle; |
47 | 48 | ||
48 | static char *data = "ABCD"; | 49 | static char *data = "ABCD"; |
49 | static unsigned int *data_pointer; | 50 | static unsigned int data_pointer; |
50 | static unsigned int *read_pointer; | 51 | static unsigned int read_pointer; |
51 | static int result | 52 | static int result |
52 | 53 | ||
53 | static int test1_success_counter; | 54 | static int test1_success_counter; |
@@ -59,6 +60,8 @@ static int test1_success_counter; | |||
59 | static void | 60 | static void |
60 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 61 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
61 | { | 62 | { |
63 | GNUNET_STREAM_close (peer1_socket); | ||
64 | GNUNET_STREAM_close (peer2_socket); | ||
62 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: shutdown\n"); | 65 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: shutdown\n"); |
63 | if (0 != abort_task) | 66 | if (0 != abort_task) |
64 | { | 67 | { |
@@ -108,12 +111,22 @@ void write_completion (void *cls, | |||
108 | enum GNUNET_STREAM_Status status, | 111 | enum GNUNET_STREAM_Status status, |
109 | size_t size) | 112 | size_t size) |
110 | { | 113 | { |
114 | |||
115 | if (3 == test1_success_counter) /* Called for peer2's write operation */ | ||
116 | { | ||
117 | /* peer1 has shutdown reading */ | ||
118 | GNUNET_assert (GNUNET_STREAM_SHUTDOWN == status); | ||
119 | GNUNET_assert (0 == size); | ||
120 | test1_success_counter ++; | ||
121 | |||
122 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
123 | } | ||
111 | GNUNET_assert (GNUNET_STREAM_OK == status); | 124 | GNUNET_assert (GNUNET_STREAM_OK == status); |
112 | if (data_pointer + size != strlen(data)) /* Have more data to send */ | 125 | if (data_pointer + size != strlen(data)) /* Have more data to send */ |
113 | { | 126 | { |
114 | data_pointer += size; | 127 | data_pointer += size; |
115 | peer1_IOHandle = GNUNET_STREAM_write (peer1_socket, | 128 | peer1_IOHandle = GNUNET_STREAM_write (peer1_socket, |
116 | (void *) data_pointer, | 129 | (void *) data, |
117 | strlen(data) - data_pointer, | 130 | strlen(data) - data_pointer, |
118 | GNUNET_TIME_relative_multiply | 131 | GNUNET_TIME_relative_multiply |
119 | (GNUNET_TIME_UNIT_SECONDS, 5), | 132 | (GNUNET_TIME_UNIT_SECONDS, 5), |
@@ -122,12 +135,8 @@ void write_completion (void *cls, | |||
122 | GNUNET_assert (NULL != peer1_IOHandle); | 135 | GNUNET_assert (NULL != peer1_IOHandle); |
123 | } | 136 | } |
124 | else{ /* Close peer1 socket */ | 137 | else{ /* Close peer1 socket */ |
125 | GNUNET_STREAM_close (peer1_socket); | ||
126 | test1_success_counter++; | 138 | test1_success_counter++; |
127 | if (2 == test1_success_counter) | 139 | GNUNET_STREAM_shutdown (peer1_socket, SHUT_RDWR); |
128 | { | ||
129 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
130 | } | ||
131 | } | 140 | } |
132 | } | 141 | } |
133 | 142 | ||
@@ -173,6 +182,25 @@ input_processor (void *cls, | |||
173 | const void *input_data, | 182 | const void *input_data, |
174 | size_t size) | 183 | size_t size) |
175 | { | 184 | { |
185 | |||
186 | if (2 == test1_success_counter) | ||
187 | { | ||
188 | GNUNET_assert (GNUNET_STREAM_SHUTDOWN == status); | ||
189 | GNUNET_assert (0 == size); | ||
190 | test1_success_counter ++; | ||
191 | /* Now this should result in STREAM_SHUTDOWN */ | ||
192 | peer2_IOHandle = GNUNET_STREAM_write (peer2_socket, | ||
193 | (void *) data, | ||
194 | strlen(data), | ||
195 | GNUNET_TIME_relative_multiply | ||
196 | (GNUNET_TIME_UNIT_SECONDS, 5), | ||
197 | &write_completion, | ||
198 | (void *) peer2_socket); | ||
199 | |||
200 | return 0; | ||
201 | } | ||
202 | |||
203 | GNUNET_assert (GNUNET_STERAM_OK == status); | ||
176 | GNUNET_assert (size < strlen (data)); | 204 | GNUNET_assert (size < strlen (data)); |
177 | GNUNET_assert (strncmp ((const char *) data, | 205 | GNUNET_assert (strncmp ((const char *) data, |
178 | (const char *) input_data, | 206 | (const char *) input_data, |
@@ -181,20 +209,23 @@ input_processor (void *cls, | |||
181 | 209 | ||
182 | if (read_pointer < strlen (data)) | 210 | if (read_pointer < strlen (data)) |
183 | { | 211 | { |
184 | peer2_IOHandle = GNUNET_STREAM_read ((struct GNUNET_STREAM_Socket) cls, | 212 | peer2_IOHandle = GNUNET_STREAM_read ((struct GNUNET_STREAM_Socket *) cls, |
185 | GNUNET_TIME_relative_multiply | 213 | GNUNET_TIME_relative_multiply |
186 | (GNUNET_TIME_UNIT_SECONDS, 5), | 214 | (GNUNET_TIME_UNIT_SECONDS, 5), |
187 | &input_processor, | 215 | &input_processor, |
188 | NULL); | 216 | NULL); |
189 | GNUNET_assert (NULL != peer2_IOHandle); | 217 | GNUNET_assert (NULL != peer2_IOHandle); |
190 | } | 218 | } |
191 | else { /* Close peer2 socket */ | 219 | else { |
192 | GNUNET_STREAM_close (peer2_socket); | ||
193 | test1_success_counter ++; | 220 | test1_success_counter ++; |
194 | if (2 == test1_success_counter) | 221 | /* This time should the read status should be STERAM_SHUTDOWN */ |
195 | { | 222 | peer2_IOHandle = GNUNET_STREAM_read ((struct GNUNET_STREAM_Socket *) cls, |
196 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 223 | GNUNET_TIME_relative_multiply |
197 | } | 224 | (GNUNET_TIME_UNIT_SECONDS, 5), |
225 | &input_processor, | ||
226 | NULL); | ||
227 | |||
228 | |||
198 | } | 229 | } |
199 | 230 | ||
200 | return size; | 231 | return size; |
@@ -211,7 +242,7 @@ stream_read (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
211 | GNUNET_assert (NULL != cls); | 242 | GNUNET_assert (NULL != cls); |
212 | read_pointer = 0; | 243 | read_pointer = 0; |
213 | GNUNET_STREAM_listen_close (peer2_listen_socket); /* Close listen socket */ | 244 | GNUNET_STREAM_listen_close (peer2_listen_socket); /* Close listen socket */ |
214 | peer2_IOHandle = GNUNET_STREAM_read ((struct GNUNET_STREAM_Socket) cls, | 245 | peer2_IOHandle = GNUNET_STREAM_read ((struct GNUNET_STREAM_Socket *) cls, |
215 | GNUNET_TIME_relative_multiply | 246 | GNUNET_TIME_relative_multiply |
216 | (GNUNET_TIME_UNIT_SECONDS, 5), | 247 | (GNUNET_TIME_UNIT_SECONDS, 5), |
217 | &input_processor, | 248 | &input_processor, |