summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2018-01-11 11:05:30 -0800
committerCedric BAIL <cedric@osg.samsung.com>2018-01-11 11:13:17 -0800
commit1f784b8c6c0fe1520453c35e086d5c0957124d53 (patch)
treea1a2f730e87a6abb4f02ed49f2663596ef210118
parent0e91525d25564a33153084462f15101a6a878ea3 (diff)
ecore: remove use of efl_main_loop_get from efl_net_socket_ssl_dialer_example.
-rw-r--r--src/examples/ecore/efl_net_socket_ssl_dialer_example.c106
1 files changed, 70 insertions, 36 deletions
diff --git a/src/examples/ecore/efl_net_socket_ssl_dialer_example.c b/src/examples/ecore/efl_net_socket_ssl_dialer_example.c
index 0aab135ec2..fd228458e0 100644
--- a/src/examples/ecore/efl_net_socket_ssl_dialer_example.c
+++ b/src/examples/ecore/efl_net_socket_ssl_dialer_example.c
@@ -1,15 +1,11 @@
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#include <ctype.h> 4#include <ctype.h>
8 5
9static int retval = EXIT_SUCCESS;
10static Eina_List *pending_send = NULL; 6static Eina_List *pending_send = NULL;
11static size_t pending_send_offset = 0; 7static size_t pending_send_offset = 0;
12static Eo *ssl_ctx; 8static Eo *ssl_ctx = NULL;
13 9
14static void 10static void
15_ssl_ready(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED) 11_ssl_ready(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
@@ -22,7 +18,7 @@ _ssl_error(void *data EINA_UNUSED, const Efl_Event *event)
22{ 18{
23 const Eina_Error *perr = event->info; 19 const Eina_Error *perr = event->info;
24 fprintf(stderr, "INFO: SSL error: %d '%s'\n", *perr, eina_error_msg_get(*perr)); 20 fprintf(stderr, "INFO: SSL error: %d '%s'\n", *perr, eina_error_msg_get(*perr));
25 retval = EXIT_FAILURE; 21 efl_loop_quit(efl_loop_get(event->object), eina_value_int_init(EXIT_FAILURE));
26} 22}
27 23
28static void 24static void
@@ -51,8 +47,7 @@ _ssl_can_read(void *data EINA_UNUSED, const Efl_Event *event)
51 { 47 {
52 if (err == EAGAIN) return; 48 if (err == EAGAIN) return;
53 fprintf(stderr, "ERROR: could not read: %s\n", eina_error_msg_get(err)); 49 fprintf(stderr, "ERROR: could not read: %s\n", eina_error_msg_get(err));
54 retval = EXIT_FAILURE; 50 efl_loop_quit(efl_loop_get(event->object), eina_value_int_init(EXIT_FAILURE));
55 ecore_main_loop_quit();
56 return; 51 return;
57 } 52 }
58 53
@@ -65,7 +60,7 @@ static void
65_ssl_eos(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED) 60_ssl_eos(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
66{ 61{
67 fprintf(stderr, "INFO: SSL eos\n"); 62 fprintf(stderr, "INFO: SSL eos\n");
68 ecore_main_loop_quit(); 63 efl_loop_quit(efl_loop_get(event->object), EINA_VALUE_EMPTY);
69} 64}
70 65
71static void 66static void
@@ -97,8 +92,7 @@ _ssl_can_write(void *data EINA_UNUSED, const Efl_Event *event)
97 { 92 {
98 if (err == EAGAIN) return; 93 if (err == EAGAIN) return;
99 fprintf(stderr, "ERROR: could not write: %s\n", eina_error_msg_get(err)); 94 fprintf(stderr, "ERROR: could not write: %s\n", eina_error_msg_get(err));
100 retval = EXIT_FAILURE; 95 efl_loop_quit(efl_loop_get(event->object), eina_value_int_init(EXIT_FAILURE));
101 ecore_main_loop_quit();
102 return; 96 return;
103 } 97 }
104 98
@@ -149,8 +143,7 @@ _connected(void *data EINA_UNUSED, const Efl_Event *event)
149 if (!ssl) 143 if (!ssl)
150 { 144 {
151 fprintf(stderr, "ERROR: failed to wrap dialer=%p in SSL\n", event->object); 145 fprintf(stderr, "ERROR: failed to wrap dialer=%p in SSL\n", event->object);
152 retval = EXIT_FAILURE; 146 efl_loop_quit(efl_loop_get(event->object), eina_value_int_init(EXIT_FAILURE));
153 ecore_main_loop_quit();
154 return; 147 return;
155 } 148 }
156 149
@@ -179,7 +172,7 @@ _error(void *data EINA_UNUSED, const Efl_Event *event)
179{ 172{
180 const Eina_Error *perr = event->info; 173 const Eina_Error *perr = event->info;
181 fprintf(stderr, "INFO: error: %d '%s'\n", *perr, eina_error_msg_get(*perr)); 174 fprintf(stderr, "INFO: error: %d '%s'\n", *perr, eina_error_msg_get(*perr));
182 retval = EXIT_FAILURE; 175 efl_loop_quit(efl_loop_get(event->object), eina_value_int_init(EXIT_FAILURE));
183} 176}
184 177
185EFL_CALLBACKS_ARRAY_DEFINE(dialer_cbs, 178EFL_CALLBACKS_ARRAY_DEFINE(dialer_cbs,
@@ -283,8 +276,60 @@ static const Ecore_Getopt options = {
283 } 276 }
284}; 277};
285 278
286int 279static Eo *dialer = NULL;
287main(int argc, char **argv) 280
281#ifndef USE_DEFAULT_CONTEXT
282static Eina_List *certificates = NULL;
283static Eina_List *private_keys = NULL;
284static Eina_List *crls = NULL;
285static Eina_List *cas = NULL;
286#endif
287
288EAPI_MAIN void
289efl_pause(void *data EINA_UNUSED,
290 const Efl_Event *ev EINA_UNUSED)
291{
292}
293
294EAPI_MAIN void
295efl_resume(void *data EINA_UNUSED,
296 const Efl_Event *ev EINA_UNUSED)
297{
298}
299
300EAPI_MAIN void
301efl_terminate(void *data EINA_UNUSED,
302 const Efl_Event *ev EINA_UNUSED)
303{
304 if (dialer || ssl_ctx)
305 {
306#ifndef USE_DEFAULT_CONTEXT
307 char *str;
308#endif
309
310 efl_io_closer_close(dialer); /* just del won't do as ssl has an extra ref */
311 efl_del(dialer);
312 dialer = NULL;
313
314 efl_del(ssl_ctx);
315 ssl_ctx = NULL;
316
317 EINA_LIST_FREE(pending_send, str) free(str);
318
319#ifndef USE_DEFAULT_CONTEXT
320 EINA_LIST_FREE(certificates, str) free(str);
321 EINA_LIST_FREE(private_keys, str) free(str);
322 EINA_LIST_FREE(crls, str) free(str);
323 EINA_LIST_FREE(cas, str) free(str);
324#endif
325 }
326
327 fprintf(stderr, "INFO: main loop finished.\n");
328}
329
330EAPI_MAIN void
331efl_main(void *data EINA_UNUSED,
332 const Efl_Event *ev)
288{ 333{
289 char *address = NULL; 334 char *address = NULL;
290 char *line_delimiter_str = NULL; 335 char *line_delimiter_str = NULL;
@@ -294,10 +339,6 @@ main(int argc, char **argv)
294 Eina_Iterator *it; 339 Eina_Iterator *it;
295 char *verify_mode_choice = "required"; 340 char *verify_mode_choice = "required";
296 char *cipher_choice = "auto"; 341 char *cipher_choice = "auto";
297 Eina_List *certificates = NULL;
298 Eina_List *private_keys = NULL;
299 Eina_List *crls = NULL;
300 Eina_List *cas = NULL;
301 Eina_Bool default_paths_load = EINA_TRUE; 342 Eina_Bool default_paths_load = EINA_TRUE;
302 Efl_Net_Ssl_Verify_Mode verify_mode = EFL_NET_SSL_VERIFY_MODE_OPTIONAL; 343 Efl_Net_Ssl_Verify_Mode verify_mode = EFL_NET_SSL_VERIFY_MODE_OPTIONAL;
303 Efl_Net_Ssl_Cipher cipher = EFL_NET_SSL_CIPHER_AUTO; 344 Efl_Net_Ssl_Cipher cipher = EFL_NET_SSL_CIPHER_AUTO;
@@ -336,29 +377,27 @@ main(int argc, char **argv)
336 ECORE_GETOPT_VALUE_NONE /* sentinel */ 377 ECORE_GETOPT_VALUE_NONE /* sentinel */
337 }; 378 };
338 int args; 379 int args;
339 Eo *dialer, *loop; 380 Eo *loop;
340 Eina_Error err; 381 Eina_Error err;
341 382
342 ecore_init(); 383 ecore_init();
343 ecore_con_init(); 384 ecore_con_init();
344 385
345 args = ecore_getopt_parse(&options, values, argc, argv); 386 args = ecore_getopt_parse(&options, values, 0, NULL);
346 if (args < 0) 387 if (args < 0)
347 { 388 {
348 fputs("ERROR: Could not parse command line options.\n", stderr); 389 fputs("ERROR: Could not parse command line options.\n", stderr);
349 retval = EXIT_FAILURE;
350 goto end; 390 goto end;
351 } 391 }
352 392
353 if (quit_option) goto end; 393 if (quit_option) goto end;
354 394
355 loop = efl_main_loop_get(); 395 loop = ev->object;
356 396
357 args = ecore_getopt_parse_positional(&options, values, argc, argv, args); 397 args = ecore_getopt_parse_positional(&options, values, 0, NULL, args);
358 if (args < 0) 398 if (args < 0)
359 { 399 {
360 fputs("ERROR: Could not parse positional arguments.\n", stderr); 400 fputs("ERROR: Could not parse positional arguments.\n", stderr);
361 retval = EXIT_FAILURE;
362 goto end; 401 goto end;
363 } 402 }
364 403
@@ -435,7 +474,6 @@ main(int argc, char **argv)
435 if (!ssl_ctx) 474 if (!ssl_ctx)
436 { 475 {
437 fprintf(stderr, "ERROR: could not create the SSL context!\n"); 476 fprintf(stderr, "ERROR: could not create the SSL context!\n");
438 retval = EXIT_FAILURE;
439 goto no_ssl_ctx; 477 goto no_ssl_ctx;
440 } 478 }
441 479
@@ -481,13 +519,10 @@ main(int argc, char **argv)
481 { 519 {
482 fprintf(stderr, "ERROR: could not dial '%s': %s", 520 fprintf(stderr, "ERROR: could not dial '%s': %s",
483 address, eina_error_msg_get(err)); 521 address, eina_error_msg_get(err));
484 retval = EXIT_FAILURE;
485 goto no_mainloop; 522 goto no_mainloop;
486 } 523 }
487 524
488 ecore_main_loop_begin(); 525 return ;
489
490 fprintf(stderr, "INFO: main loop finished.\n");
491 526
492 no_mainloop: 527 no_mainloop:
493 efl_io_closer_close(dialer); /* just del won't do as ssl has an extra ref */ 528 efl_io_closer_close(dialer); /* just del won't do as ssl has an extra ref */
@@ -505,8 +540,7 @@ main(int argc, char **argv)
505 EINA_LIST_FREE(cas, str) free(str); 540 EINA_LIST_FREE(cas, str) free(str);
506#endif 541#endif
507 542
508 ecore_con_shutdown(); 543 efl_loop_quit(ev->object, eina_value_int_init(EXIT_FAILURE));
509 ecore_shutdown();
510
511 return retval;
512} 544}
545
546EFL_MAIN_EX();