diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-11-19 14:17:51 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-11-19 14:17:51 +0000 |
commit | b0694ccdef528a727e17b29e2528d1e1018abe1f (patch) | |
tree | 66e6b959dd53526a9b41aed1d35723e38a7249e1 /src/stream | |
parent | 35b25e9f0758fa3d4a2ce3f0ab828ab898ed549d (diff) | |
download | gnunet-b0694ccdef528a727e17b29e2528d1e1018abe1f.tar.gz gnunet-b0694ccdef528a727e17b29e2528d1e1018abe1f.zip |
- warn upon unclean socket close
Diffstat (limited to 'src/stream')
-rw-r--r-- | src/stream/stream_api.c | 2 | ||||
-rw-r--r-- | src/stream/test_stream_2peers.c | 1 | ||||
-rw-r--r-- | src/stream/test_stream_local.c | 46 |
3 files changed, 40 insertions, 9 deletions
diff --git a/src/stream/stream_api.c b/src/stream/stream_api.c index b55ae46f0..fd2f86e51 100644 --- a/src/stream/stream_api.c +++ b/src/stream/stream_api.c | |||
@@ -3214,6 +3214,8 @@ GNUNET_STREAM_close (struct GNUNET_STREAM_Socket *socket) | |||
3214 | GNUNET_STREAM_io_write_cancel (socket->write_handle); | 3214 | GNUNET_STREAM_io_write_cancel (socket->write_handle); |
3215 | //socket->write_handle = NULL; | 3215 | //socket->write_handle = NULL; |
3216 | } | 3216 | } |
3217 | GNUNET_break (GNUNET_YES == socket->receive_closed); | ||
3218 | GNUNET_break (GNUNET_YES == socket->transmit_closed); | ||
3217 | /* Terminate the ack'ing task if they are still present */ | 3219 | /* Terminate the ack'ing task if they are still present */ |
3218 | if (socket->ack_task_id != GNUNET_SCHEDULER_NO_TASK) | 3220 | if (socket->ack_task_id != GNUNET_SCHEDULER_NO_TASK) |
3219 | { | 3221 | { |
diff --git a/src/stream/test_stream_2peers.c b/src/stream/test_stream_2peers.c index c517cc2b1..d059d0521 100644 --- a/src/stream/test_stream_2peers.c +++ b/src/stream/test_stream_2peers.c | |||
@@ -264,7 +264,6 @@ shutdown_completion (void *cls, | |||
264 | } | 264 | } |
265 | 265 | ||
266 | 266 | ||
267 | |||
268 | /** | 267 | /** |
269 | * Shutdown sockets gracefully | 268 | * Shutdown sockets gracefully |
270 | */ | 269 | */ |
diff --git a/src/stream/test_stream_local.c b/src/stream/test_stream_local.c index 3286ade5f..cb59de999 100644 --- a/src/stream/test_stream_local.c +++ b/src/stream/test_stream_local.c | |||
@@ -60,6 +60,11 @@ struct PeerData | |||
60 | struct GNUNET_STREAM_IOReadHandle *io_read_handle; | 60 | struct GNUNET_STREAM_IOReadHandle *io_read_handle; |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * Peer's shutdown handle | ||
64 | */ | ||
65 | struct GNUNET_STREAM_ShutdownHandle *shutdown_handle; | ||
66 | |||
67 | /** | ||
63 | * Bytes the peer has written | 68 | * Bytes the peer has written |
64 | */ | 69 | */ |
65 | unsigned int bytes_wrote; | 70 | unsigned int bytes_wrote; |
@@ -166,19 +171,16 @@ stream_write_task (void *cls, | |||
166 | * Shutdown nicely | 171 | * Shutdown nicely |
167 | */ | 172 | */ |
168 | static void | 173 | static void |
169 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 174 | do_close (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
170 | { | 175 | { |
176 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) | ||
177 | GNUNET_SCHEDULER_cancel (abort_task); | ||
171 | if (NULL != peer1.socket) | 178 | if (NULL != peer1.socket) |
172 | GNUNET_STREAM_close (peer1.socket); | 179 | GNUNET_STREAM_close (peer1.socket); |
173 | if (NULL != peer2.socket) | 180 | if (NULL != peer2.socket) |
174 | GNUNET_STREAM_close (peer2.socket); | 181 | GNUNET_STREAM_close (peer2.socket); |
175 | if (NULL != peer2_listen_socket) | 182 | if (NULL != peer2_listen_socket) |
176 | GNUNET_STREAM_listen_close (peer2_listen_socket); | 183 | GNUNET_STREAM_listen_close (peer2_listen_socket); |
177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: shutdown\n"); | ||
178 | if (0 != abort_task) | ||
179 | { | ||
180 | GNUNET_SCHEDULER_cancel (abort_task); | ||
181 | } | ||
182 | } | 184 | } |
183 | 185 | ||
184 | 186 | ||
@@ -190,8 +192,36 @@ do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
190 | { | 192 | { |
191 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: ABORT\n"); | 193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: ABORT\n"); |
192 | result = GNUNET_SYSERR; | 194 | result = GNUNET_SYSERR; |
193 | abort_task = 0; | 195 | abort_task = GNUNET_SCHEDULER_NO_TASK; |
194 | do_shutdown (cls, tc); | 196 | do_close (cls, tc); |
197 | } | ||
198 | |||
199 | |||
200 | /** | ||
201 | * Completion callback for shutdown | ||
202 | * | ||
203 | * @param cls the closure from GNUNET_STREAM_shutdown call | ||
204 | * @param operation the operation that was shutdown (SHUT_RD, SHUT_WR, | ||
205 | * SHUT_RDWR) | ||
206 | */ | ||
207 | static void | ||
208 | shutdown_completion (void *cls, | ||
209 | int operation) | ||
210 | { | ||
211 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "STREAM shutdown successful\n"); | ||
212 | GNUNET_SCHEDULER_add_now (&do_close, cls); | ||
213 | } | ||
214 | |||
215 | |||
216 | /** | ||
217 | * Shutdown sockets gracefully | ||
218 | */ | ||
219 | static void | ||
220 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
221 | { | ||
222 | result = GNUNET_OK; | ||
223 | peer1.shutdown_handle = GNUNET_STREAM_shutdown (peer1.socket, SHUT_RDWR, | ||
224 | &shutdown_completion, cls); | ||
195 | } | 225 | } |
196 | 226 | ||
197 | 227 | ||