diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/util/test_service.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/util/test_service.c')
-rw-r--r-- | src/util/test_service.c | 196 |
1 files changed, 98 insertions, 98 deletions
diff --git a/src/util/test_service.c b/src/util/test_service.c index dc8bc59c1..c0b02872f 100644 --- a/src/util/test_service.c +++ b/src/util/test_service.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file util/test_service.c | 21 | * @file util/test_service.c |
22 | * @brief tests for service.c | 22 | * @brief tests for service.c |
@@ -43,20 +43,20 @@ static struct GNUNET_SCHEDULER_Task *tt; | |||
43 | 43 | ||
44 | 44 | ||
45 | static void | 45 | static void |
46 | handle_recv (void *cls, | 46 | handle_recv(void *cls, |
47 | const struct GNUNET_MessageHeader *message) | 47 | const struct GNUNET_MessageHeader *message) |
48 | { | 48 | { |
49 | struct GNUNET_SERVICE_Client *client = cls; | 49 | struct GNUNET_SERVICE_Client *client = cls; |
50 | 50 | ||
51 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 51 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
52 | "Received client message...\n"); | 52 | "Received client message...\n"); |
53 | GNUNET_SERVICE_client_continue (client); | 53 | GNUNET_SERVICE_client_continue(client); |
54 | global_ret = 2; | 54 | global_ret = 2; |
55 | if (NULL != mq) | 55 | if (NULL != mq) |
56 | { | 56 | { |
57 | GNUNET_MQ_destroy (mq); | 57 | GNUNET_MQ_destroy(mq); |
58 | mq = NULL; | 58 | mq = NULL; |
59 | } | 59 | } |
60 | } | 60 | } |
61 | 61 | ||
62 | 62 | ||
@@ -69,9 +69,9 @@ handle_recv (void *cls, | |||
69 | * @return @a c so we have the client handle in the future | 69 | * @return @a c so we have the client handle in the future |
70 | */ | 70 | */ |
71 | static void * | 71 | static void * |
72 | connect_cb (void *cls, | 72 | connect_cb(void *cls, |
73 | struct GNUNET_SERVICE_Client *c, | 73 | struct GNUNET_SERVICE_Client *c, |
74 | struct GNUNET_MQ_Handle *mq) | 74 | struct GNUNET_MQ_Handle *mq) |
75 | { | 75 | { |
76 | /* FIXME: in the future, do something with mq | 76 | /* FIXME: in the future, do something with mq |
77 | to test sending messages to the client! */ | 77 | to test sending messages to the client! */ |
@@ -85,37 +85,37 @@ connect_cb (void *cls, | |||
85 | * @param cls our service name | 85 | * @param cls our service name |
86 | * @param c disconnecting client | 86 | * @param c disconnecting client |
87 | * @param internal_cls must match @a c | 87 | * @param internal_cls must match @a c |
88 | */ | 88 | */ |
89 | static void | 89 | static void |
90 | disconnect_cb (void *cls, | 90 | disconnect_cb(void *cls, |
91 | struct GNUNET_SERVICE_Client *c, | 91 | struct GNUNET_SERVICE_Client *c, |
92 | void *internal_cls) | 92 | void *internal_cls) |
93 | { | 93 | { |
94 | GNUNET_assert (c == internal_cls); | 94 | GNUNET_assert(c == internal_cls); |
95 | if (2 == global_ret) | 95 | if (2 == global_ret) |
96 | { | ||
97 | GNUNET_SCHEDULER_shutdown (); | ||
98 | global_ret = 0; | ||
99 | if (NULL != tt) | ||
100 | { | 96 | { |
101 | GNUNET_SCHEDULER_cancel (tt); | 97 | GNUNET_SCHEDULER_shutdown(); |
102 | tt = NULL; | 98 | global_ret = 0; |
99 | if (NULL != tt) | ||
100 | { | ||
101 | GNUNET_SCHEDULER_cancel(tt); | ||
102 | tt = NULL; | ||
103 | } | ||
103 | } | 104 | } |
104 | } | ||
105 | } | 105 | } |
106 | 106 | ||
107 | 107 | ||
108 | static void | 108 | static void |
109 | timeout_task (void *cls) | 109 | timeout_task(void *cls) |
110 | { | 110 | { |
111 | tt = NULL; | 111 | tt = NULL; |
112 | if (NULL != mq) | 112 | if (NULL != mq) |
113 | { | 113 | { |
114 | GNUNET_MQ_destroy (mq); | 114 | GNUNET_MQ_destroy(mq); |
115 | mq = NULL; | 115 | mq = NULL; |
116 | } | 116 | } |
117 | global_ret = 33; | 117 | global_ret = 33; |
118 | GNUNET_SCHEDULER_shutdown (); | 118 | GNUNET_SCHEDULER_shutdown(); |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
@@ -128,28 +128,28 @@ timeout_task (void *cls) | |||
128 | * @param sh handle to the service | 128 | * @param sh handle to the service |
129 | */ | 129 | */ |
130 | static void | 130 | static void |
131 | service_init (void *cls, | 131 | service_init(void *cls, |
132 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 132 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
133 | struct GNUNET_SERVICE_Handle *sh) | 133 | struct GNUNET_SERVICE_Handle *sh) |
134 | { | 134 | { |
135 | const char *service_name = cls; | 135 | const char *service_name = cls; |
136 | struct GNUNET_MQ_Envelope *env; | 136 | struct GNUNET_MQ_Envelope *env; |
137 | struct GNUNET_MessageHeader *msg; | 137 | struct GNUNET_MessageHeader *msg; |
138 | 138 | ||
139 | GNUNET_assert (NULL == tt); | 139 | GNUNET_assert(NULL == tt); |
140 | tt = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 140 | tt = GNUNET_SCHEDULER_add_delayed(TIMEOUT, |
141 | &timeout_task, | 141 | &timeout_task, |
142 | NULL); | 142 | NULL); |
143 | mq = GNUNET_CLIENT_connect (cfg, | 143 | mq = GNUNET_CLIENT_connect(cfg, |
144 | service_name, | 144 | service_name, |
145 | NULL, | 145 | NULL, |
146 | NULL, | 146 | NULL, |
147 | NULL); | 147 | NULL); |
148 | GNUNET_assert (NULL != mq); | 148 | GNUNET_assert(NULL != mq); |
149 | env = GNUNET_MQ_msg (msg, | 149 | env = GNUNET_MQ_msg(msg, |
150 | MY_TYPE); | 150 | MY_TYPE); |
151 | GNUNET_MQ_send (mq, | 151 | GNUNET_MQ_send(mq, |
152 | env); | 152 | env); |
153 | } | 153 | } |
154 | 154 | ||
155 | 155 | ||
@@ -160,78 +160,78 @@ service_init (void *cls, | |||
160 | * @param sname name of the service to run | 160 | * @param sname name of the service to run |
161 | */ | 161 | */ |
162 | static int | 162 | static int |
163 | check (const char *sname) | 163 | check(const char *sname) |
164 | { | 164 | { |
165 | struct GNUNET_MQ_MessageHandler myhandlers[] = { | 165 | struct GNUNET_MQ_MessageHandler myhandlers[] = { |
166 | GNUNET_MQ_hd_fixed_size (recv, | 166 | GNUNET_MQ_hd_fixed_size(recv, |
167 | MY_TYPE, | 167 | MY_TYPE, |
168 | struct GNUNET_MessageHeader, | 168 | struct GNUNET_MessageHeader, |
169 | NULL), | 169 | NULL), |
170 | GNUNET_MQ_handler_end () | 170 | GNUNET_MQ_handler_end() |
171 | }; | 171 | }; |
172 | char *const argv[] = { | 172 | char *const argv[] = { |
173 | (char *) sname, | 173 | (char *)sname, |
174 | "-c", | 174 | "-c", |
175 | "test_service_data.conf", | 175 | "test_service_data.conf", |
176 | NULL | 176 | NULL |
177 | }; | 177 | }; |
178 | 178 | ||
179 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 179 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
180 | "Starting `%s' service\n", | 180 | "Starting `%s' service\n", |
181 | sname); | 181 | sname); |
182 | global_ret = 1; | 182 | global_ret = 1; |
183 | GNUNET_assert (0 == | 183 | GNUNET_assert(0 == |
184 | GNUNET_SERVICE_run_ (3, | 184 | GNUNET_SERVICE_run_(3, |
185 | argv, | 185 | argv, |
186 | sname, | 186 | sname, |
187 | GNUNET_SERVICE_OPTION_NONE, | 187 | GNUNET_SERVICE_OPTION_NONE, |
188 | &service_init, | 188 | &service_init, |
189 | &connect_cb, | 189 | &connect_cb, |
190 | &disconnect_cb, | 190 | &disconnect_cb, |
191 | (void *) sname, | 191 | (void *)sname, |
192 | myhandlers)); | 192 | myhandlers)); |
193 | return global_ret; | 193 | return global_ret; |
194 | } | 194 | } |
195 | 195 | ||
196 | 196 | ||
197 | int | 197 | int |
198 | main (int argc, | 198 | main(int argc, |
199 | char *argv[]) | 199 | char *argv[]) |
200 | { | 200 | { |
201 | int ret = 0; | 201 | int ret = 0; |
202 | struct GNUNET_NETWORK_Handle *s = NULL; | 202 | struct GNUNET_NETWORK_Handle *s = NULL; |
203 | 203 | ||
204 | GNUNET_log_setup ("test-service", | 204 | GNUNET_log_setup("test-service", |
205 | "WARNING", | 205 | "WARNING", |
206 | NULL); | 206 | NULL); |
207 | ret += check ("test_service"); | 207 | ret += check("test_service"); |
208 | ret += check ("test_service"); | 208 | ret += check("test_service"); |
209 | #ifndef MINGW | 209 | #ifndef MINGW |
210 | s = GNUNET_NETWORK_socket_create (PF_INET6, | 210 | s = GNUNET_NETWORK_socket_create(PF_INET6, |
211 | SOCK_STREAM, | 211 | SOCK_STREAM, |
212 | 0); | 212 | 0); |
213 | #endif | 213 | #endif |
214 | if (NULL == s) | 214 | if (NULL == s) |
215 | { | ||
216 | if ( (errno == ENOBUFS) || | ||
217 | (errno == ENOMEM) || | ||
218 | (errno == ENFILE) || | ||
219 | (errno == EACCES) ) | ||
220 | { | 215 | { |
221 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 216 | if ((errno == ENOBUFS) || |
222 | "socket"); | 217 | (errno == ENOMEM) || |
223 | return 1; | 218 | (errno == ENFILE) || |
219 | (errno == EACCES)) | ||
220 | { | ||
221 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, | ||
222 | "socket"); | ||
223 | return 1; | ||
224 | } | ||
225 | fprintf(stderr, | ||
226 | "IPv6 support seems to not be available (%s), not testing it!\n", | ||
227 | strerror(errno)); | ||
224 | } | 228 | } |
225 | fprintf (stderr, | ||
226 | "IPv6 support seems to not be available (%s), not testing it!\n", | ||
227 | strerror (errno)); | ||
228 | } | ||
229 | else | 229 | else |
230 | { | 230 | { |
231 | GNUNET_break (GNUNET_OK == | 231 | GNUNET_break(GNUNET_OK == |
232 | GNUNET_NETWORK_socket_close (s)); | 232 | GNUNET_NETWORK_socket_close(s)); |
233 | ret += check ("test_service6"); | 233 | ret += check("test_service6"); |
234 | } | 234 | } |
235 | return ret; | 235 | return ret; |
236 | } | 236 | } |
237 | 237 | ||