diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-06-27 14:11:11 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-06-27 14:11:11 +0000 |
commit | a74c37dde046da0c3c0765f47b0fb01ece6a1cc1 (patch) | |
tree | 8b5f6fcd91228c5f36c771c30b425b38a107054c /src/testbed | |
parent | 02a21c4dcaae82d610630036d3ea4921723504f9 (diff) | |
download | gnunet-a74c37dde046da0c3c0765f47b0fb01ece6a1cc1.tar.gz gnunet-a74c37dde046da0c3c0765f47b0fb01ece6a1cc1.zip |
-simplify barriers logic, make sure cb is called on all errors
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/testbed_api_barriers.c | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/src/testbed/testbed_api_barriers.c b/src/testbed/testbed_api_barriers.c index 527a86554..3ec4a905e 100644 --- a/src/testbed/testbed_api_barriers.c +++ b/src/testbed/testbed_api_barriers.c | |||
@@ -82,25 +82,6 @@ struct GNUNET_TESTBED_BarrierWaitHandle | |||
82 | }; | 82 | }; |
83 | 83 | ||
84 | 84 | ||
85 | /** | ||
86 | * Function to destroy barrier wait handle | ||
87 | * | ||
88 | * @param h the handle to destroy | ||
89 | */ | ||
90 | static void | ||
91 | destroy_handle (struct GNUNET_TESTBED_BarrierWaitHandle *h) | ||
92 | { | ||
93 | GNUNET_free (h->name); | ||
94 | if (NULL != h->tx) | ||
95 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->tx); | ||
96 | if (NULL != h->conn) | ||
97 | GNUNET_CLIENT_disconnect (h->conn); | ||
98 | if (NULL != h->msg) | ||
99 | GNUNET_free (h->msg); | ||
100 | GNUNET_CONFIGURATION_destroy (h->cfg); | ||
101 | GNUNET_free (h); | ||
102 | } | ||
103 | |||
104 | 85 | ||
105 | /** | 86 | /** |
106 | * Type of a function to call when we receive a message | 87 | * Type of a function to call when we receive a message |
@@ -139,8 +120,8 @@ receive_handler (void *cls, | |||
139 | case GNUNET_TESTBED_BARRIERSTATUS_ERROR: | 120 | case GNUNET_TESTBED_BARRIERSTATUS_ERROR: |
140 | goto fail; | 121 | goto fail; |
141 | case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: | 122 | case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: |
142 | GNUNET_break (0); /* FIXME */ | 123 | GNUNET_break (0); |
143 | goto destroy; | 124 | goto fail; |
144 | case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: | 125 | case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: |
145 | h->cb (h->cls, h->name, GNUNET_OK); | 126 | h->cb (h->cls, h->name, GNUNET_OK); |
146 | goto destroy; | 127 | goto destroy; |
@@ -152,7 +133,7 @@ receive_handler (void *cls, | |||
152 | h->cb (h->cls, h->name, GNUNET_SYSERR); | 133 | h->cb (h->cls, h->name, GNUNET_SYSERR); |
153 | 134 | ||
154 | destroy: | 135 | destroy: |
155 | destroy_handle (h); | 136 | GNUNET_TESTBED_barrier_wait_cancel (h); |
156 | } | 137 | } |
157 | 138 | ||
158 | 139 | ||
@@ -176,7 +157,8 @@ transmit_notify (void *cls, size_t size, void *buf) | |||
176 | h->tx = NULL; | 157 | h->tx = NULL; |
177 | if ((0 == size) || (NULL == buf)) | 158 | if ((0 == size) || (NULL == buf)) |
178 | { | 159 | { |
179 | destroy_handle (h); | 160 | h->cb (h->cls, h->name, GNUNET_SYSERR); |
161 | GNUNET_TESTBED_barrier_wait_cancel (h); | ||
180 | return 0; | 162 | return 0; |
181 | } | 163 | } |
182 | msize = htons (h->msg->size); | 164 | msize = htons (h->msg->size); |
@@ -238,7 +220,7 @@ GNUNET_TESTBED_barrier_wait (const char *name, | |||
238 | { | 220 | { |
239 | LOG (GNUNET_ERROR_TYPE_ERROR, | 221 | LOG (GNUNET_ERROR_TYPE_ERROR, |
240 | "Unable to connect to local testbed-barrier service\n"); | 222 | "Unable to connect to local testbed-barrier service\n"); |
241 | destroy_handle (h); | 223 | GNUNET_TESTBED_barrier_wait_cancel (h); |
242 | return NULL; | 224 | return NULL; |
243 | } | 225 | } |
244 | name_len = strlen (name); | 226 | name_len = strlen (name); |
@@ -266,7 +248,15 @@ GNUNET_TESTBED_barrier_wait (const char *name, | |||
266 | void | 248 | void |
267 | GNUNET_TESTBED_barrier_wait_cancel (struct GNUNET_TESTBED_BarrierWaitHandle *h) | 249 | GNUNET_TESTBED_barrier_wait_cancel (struct GNUNET_TESTBED_BarrierWaitHandle *h) |
268 | { | 250 | { |
269 | destroy_handle (h); | 251 | GNUNET_free (h->name); |
252 | if (NULL != h->tx) | ||
253 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->tx); | ||
254 | if (NULL != h->conn) | ||
255 | GNUNET_CLIENT_disconnect (h->conn); | ||
256 | if (NULL != h->msg) | ||
257 | GNUNET_free (h->msg); | ||
258 | GNUNET_CONFIGURATION_destroy (h->cfg); | ||
259 | GNUNET_free (h); | ||
270 | } | 260 | } |
271 | 261 | ||
272 | /* end of testbed_api_barriers.c */ | 262 | /* end of testbed_api_barriers.c */ |