summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2018-01-11 11:12:13 -0800
committerCedric BAIL <cedric@osg.samsung.com>2018-01-11 11:13:17 -0800
commitbe3abbd1051fc986a2075dfe97a155150dd94ab4 (patch)
treeb0533ef2a6bb4bfb18a8dafb6458ad40ed85d3eb
parent1f784b8c6c0fe1520453c35e086d5c0957124d53 (diff)
ecore: remove use of efl_main_loop_get from efl_net_socket_ssl_server_example.
-rw-r--r--src/examples/ecore/efl_net_socket_ssl_server_example.c89
1 files changed, 58 insertions, 31 deletions
diff --git a/src/examples/ecore/efl_net_socket_ssl_server_example.c b/src/examples/ecore/efl_net_socket_ssl_server_example.c
index bfd6adc412..f8503c0d38 100644
--- a/src/examples/ecore/efl_net_socket_ssl_server_example.c
+++ b/src/examples/ecore/efl_net_socket_ssl_server_example.c
@@ -1,11 +1,7 @@
1#define EFL_BETA_API_SUPPORT 1 1#include <Efl_Net.h>
2#define EFL_EO_API_SUPPORT 1
3#include <Ecore.h>
4#include <Ecore_Con.h>
5#include <Ecore_Getopt.h> 2#include <Ecore_Getopt.h>
6#include <fcntl.h> 3#include <fcntl.h>
7 4
8static int retval = EXIT_SUCCESS;
9static double timeout = 30.0; 5static double timeout = 30.0;
10static Eo *ssl_ctx = NULL; 6static Eo *ssl_ctx = NULL;
11 7
@@ -77,7 +73,7 @@ _echo_copier_error(void *data EINA_UNUSED, const Efl_Event *event)
77 return; 73 return;
78 } 74 }
79 75
80 retval = EXIT_FAILURE; 76 efl_loop_quit(efl_loop_get(event->object), eina_value_int_init(EXIT_FAILURE));
81 77
82 fprintf(stderr, "ERROR: echo copier %p failed %d '%s', close and del.\n", 78 fprintf(stderr, "ERROR: echo copier %p failed %d '%s', close and del.\n",
83 copier, *perr, eina_error_msg_get(*perr)); 79 copier, *perr, eina_error_msg_get(*perr));
@@ -113,8 +109,7 @@ _server_client_add(void *data EINA_UNUSED, const Efl_Event *event)
113 if (!ssl) 109 if (!ssl)
114 { 110 {
115 fprintf(stderr, "ERROR: failed to wrap client=%p in SSL\n", client); 111 fprintf(stderr, "ERROR: failed to wrap client=%p in SSL\n", client);
116 retval = EXIT_FAILURE; 112 efl_loop_quit(efl_loop_get(client), eina_value_int_init(EXIT_FAILURE));
117 ecore_main_loop_quit();
118 return; 113 return;
119 } 114 }
120 115
@@ -145,8 +140,7 @@ _server_error(void *data EINA_UNUSED, const Efl_Event *event)
145{ 140{
146 const Eina_Error *perr = event->info; 141 const Eina_Error *perr = event->info;
147 fprintf(stderr, "ERROR: %d '%s'\n", *perr, eina_error_msg_get(*perr)); 142 fprintf(stderr, "ERROR: %d '%s'\n", *perr, eina_error_msg_get(*perr));
148 retval = EXIT_FAILURE; 143 efl_loop_quit(efl_loop_get(event->object), eina_value_int_init(EXIT_FAILURE));
149 ecore_main_loop_quit();
150} 144}
151 145
152static void 146static void
@@ -201,16 +195,57 @@ static const Ecore_Getopt options = {
201 } 195 }
202}; 196};
203 197
204int 198static Eo *server = NULL;
205main(int argc, char **argv) 199static Eina_List *certificates = NULL;
200static Eina_List *private_keys = NULL;
201static Eina_List *crls = NULL;
202static Eina_List *cas = NULL;
203
204EAPI_MAIN void
205efl_pause(void *data EINA_UNUSED,
206 const Efl_Event *ev EINA_UNUSED)
207{
208}
209
210EAPI_MAIN void
211efl_resume(void *data EINA_UNUSED,
212 const Efl_Event *ev EINA_UNUSED)
213{
214}
215
216EAPI_MAIN void
217efl_terminate(void *data EINA_UNUSED,
218 const Efl_Event *ev EINA_UNUSED)
219{
220 /* FIXME: For the moment the main loop doesn't get
221 properly destroyed on shutdown which disallow
222 relying on parent destroying their children */
223 if (server || ssl_ctx)
224 {
225 char *str;
226
227 efl_del(server);
228 server = NULL;
229
230 efl_del(ssl_ctx);
231 ssl_ctx = NULL;
232
233 EINA_LIST_FREE(certificates, str) free(str);
234 EINA_LIST_FREE(private_keys, str) free(str);
235 EINA_LIST_FREE(crls, str) free(str);
236 EINA_LIST_FREE(cas, str) free(str);
237 }
238
239 fprintf(stderr, "INFO: main loop finished.\n");
240}
241
242EAPI_MAIN void
243efl_main(void *data EINA_UNUSED,
244 const Efl_Event *ev)
206{ 245{
207 char *address = NULL; 246 char *address = NULL;
208 char *cipher_choice = "auto"; 247 char *cipher_choice = "auto";
209 char *str; 248 char *str;
210 Eina_List *certificates = NULL;
211 Eina_List *private_keys = NULL;
212 Eina_List *crls = NULL;
213 Eina_List *cas = NULL;
214 Efl_Net_Ssl_Cipher cipher = EFL_NET_SSL_CIPHER_AUTO; 249 Efl_Net_Ssl_Cipher cipher = EFL_NET_SSL_CIPHER_AUTO;
215 Eina_Bool quit_option = EINA_FALSE; 250 Eina_Bool quit_option = EINA_FALSE;
216 Ecore_Getopt_Value values[] = { 251 Ecore_Getopt_Value values[] = {
@@ -234,27 +269,21 @@ main(int argc, char **argv)
234 }; 269 };
235 int args; 270 int args;
236 Eina_Iterator *it; 271 Eina_Iterator *it;
237 Eo *server;
238 Eina_Error err; 272 Eina_Error err;
239 273
240 ecore_init(); 274 args = ecore_getopt_parse(&options, values, 0, NULL);
241 ecore_con_init();
242
243 args = ecore_getopt_parse(&options, values, argc, argv);
244 if (args < 0) 275 if (args < 0)
245 { 276 {
246 fputs("ERROR: Could not parse command line options.\n", stderr); 277 fputs("ERROR: Could not parse command line options.\n", stderr);
247 retval = EXIT_FAILURE;
248 goto end; 278 goto end;
249 } 279 }
250 280
251 if (quit_option) goto end; 281 if (quit_option) goto end;
252 282
253 args = ecore_getopt_parse_positional(&options, values, argc, argv, args); 283 args = ecore_getopt_parse_positional(&options, values, 0, NULL, args);
254 if (args < 0) 284 if (args < 0)
255 { 285 {
256 fputs("ERROR: Could not parse positional arguments.\n", stderr); 286 fputs("ERROR: Could not parse positional arguments.\n", stderr);
257 retval = EXIT_FAILURE;
258 goto end; 287 goto end;
259 } 288 }
260 289
@@ -282,7 +311,6 @@ main(int argc, char **argv)
282 if (!ssl_ctx) 311 if (!ssl_ctx)
283 { 312 {
284 fprintf(stderr, "ERROR: could not create the SSL context!\n"); 313 fprintf(stderr, "ERROR: could not create the SSL context!\n");
285 retval = EXIT_FAILURE;
286 goto end; 314 goto end;
287 } 315 }
288 316
@@ -310,7 +338,7 @@ main(int argc, char **argv)
310 fprintf(stderr, "INFO: * %s\n", str); 338 fprintf(stderr, "INFO: * %s\n", str);
311 eina_iterator_free(it); 339 eina_iterator_free(it);
312 340
313 server = efl_add(EFL_NET_SERVER_TCP_CLASS, efl_main_loop_get(), /* it's mandatory to use a main loop provider as the server parent */ 341 server = efl_add(EFL_NET_SERVER_TCP_CLASS, ev->object, /* it's mandatory to use a main loop provider as the server parent */
314 efl_net_server_ip_ipv6_only_set(efl_added, EINA_FALSE), /* optional, but helps testing IPv4 on IPv6 servers */ 342 efl_net_server_ip_ipv6_only_set(efl_added, EINA_FALSE), /* optional, but helps testing IPv4 on IPv6 servers */
315 efl_net_server_fd_reuse_address_set(efl_added, EINA_TRUE), /* optional, but nice for testing */ 343 efl_net_server_fd_reuse_address_set(efl_added, EINA_TRUE), /* optional, but nice for testing */
316 efl_net_server_fd_reuse_port_set(efl_added, EINA_TRUE), /* optional, but nice for testing... not secure unless you know what you're doing */ 344 efl_net_server_fd_reuse_port_set(efl_added, EINA_TRUE), /* optional, but nice for testing... not secure unless you know what you're doing */
@@ -329,7 +357,7 @@ main(int argc, char **argv)
329 goto end_server; 357 goto end_server;
330 } 358 }
331 359
332 ecore_main_loop_begin(); 360 return ;
333 361
334 end_server: 362 end_server:
335 efl_del(server); 363 efl_del(server);
@@ -343,8 +371,7 @@ main(int argc, char **argv)
343 EINA_LIST_FREE(crls, str) free(str); 371 EINA_LIST_FREE(crls, str) free(str);
344 EINA_LIST_FREE(cas, str) free(str); 372 EINA_LIST_FREE(cas, str) free(str);
345 373
346 ecore_con_shutdown(); 374 efl_loop_quit(ev->object, eina_value_int_init(EXIT_FAILURE));
347 ecore_shutdown();
348
349 return retval;
350} 375}
376
377EFL_MAIN_EX();