aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_service.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/util/test_service.c
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/util/test_service.c')
-rw-r--r--src/util/test_service.c186
1 files changed, 93 insertions, 93 deletions
diff --git a/src/util/test_service.c b/src/util/test_service.c
index 4edc38a0d..6db8471bd 100644
--- a/src/util/test_service.c
+++ b/src/util/test_service.c
@@ -43,20 +43,20 @@ static struct GNUNET_SCHEDULER_Task *tt;
43 43
44 44
45static void 45static void
46handle_recv(void *cls, 46handle_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 */
71static void * 71static void *
72connect_cb(void *cls, 72connect_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! */
@@ -87,35 +87,35 @@ connect_cb(void *cls,
87 * @param internal_cls must match @a c 87 * @param internal_cls must match @a c
88 */ 88 */
89static void 89static void
90disconnect_cb(void *cls, 90disconnect_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)
96 { 100 {
97 GNUNET_SCHEDULER_shutdown(); 101 GNUNET_SCHEDULER_cancel (tt);
98 global_ret = 0; 102 tt = NULL;
99 if (NULL != tt)
100 {
101 GNUNET_SCHEDULER_cancel(tt);
102 tt = NULL;
103 }
104 } 103 }
104 }
105} 105}
106 106
107 107
108static void 108static void
109timeout_task(void *cls) 109timeout_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 */
130static void 130static void
131service_init(void *cls, 131service_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,77 +160,77 @@ service_init(void *cls,
160 * @param sname name of the service to run 160 * @param sname name of the service to run
161 */ 161 */
162static int 162static int
163check(const char *sname) 163check (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
197int 197int
198main(int argc, 198main (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 s = GNUNET_NETWORK_socket_create(PF_INET6, 209 s = GNUNET_NETWORK_socket_create (PF_INET6,
210 SOCK_STREAM, 210 SOCK_STREAM,
211 0); 211 0);
212 212
213 if (NULL == s) 213 if (NULL == s)
214 {
215 if ((errno == ENOBUFS) ||
216 (errno == ENOMEM) ||
217 (errno == ENFILE) ||
218 (errno == EACCES))
214 { 219 {
215 if ((errno == ENOBUFS) || 220 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
216 (errno == ENOMEM) || 221 "socket");
217 (errno == ENFILE) || 222 return 1;
218 (errno == EACCES))
219 {
220 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR,
221 "socket");
222 return 1;
223 }
224 fprintf(stderr,
225 "IPv6 support seems to not be available (%s), not testing it!\n",
226 strerror(errno));
227 } 223 }
224 fprintf (stderr,
225 "IPv6 support seems to not be available (%s), not testing it!\n",
226 strerror (errno));
227 }
228 else 228 else
229 { 229 {
230 GNUNET_break(GNUNET_OK == 230 GNUNET_break (GNUNET_OK ==
231 GNUNET_NETWORK_socket_close(s)); 231 GNUNET_NETWORK_socket_close (s));
232 ret += check("test_service6"); 232 ret += check ("test_service6");
233 } 233 }
234 return ret; 234 return ret;
235} 235}
236 236