Tizen 2.1 base
[framework/uifw/ecore.git] / src / examples / ecore_server_bench.c
1 #include <stdio.h>
2 #include <Ecore.h>
3 #include <Ecore_Con.h>
4
5 /* Ecore_Con server example
6  * 2010 Mike Blumenkrantz
7  */
8
9 static Ecore_Con_Server *svr;
10 static int add;
11 static int del;
12
13 Eina_Bool
14 _add(void *data, int type, Ecore_Con_Event_Client_Add *ev)
15 {
16    ++add;
17 //   printf ("%s ", ecore_con_client_ip_get(ev->client));
18    printf("Client #%i!\n", add);
19    return ECORE_CALLBACK_RENEW;
20 }
21
22 Eina_Bool
23 _del(void *data, int type, Ecore_Con_Event_Client_Del *ev)
24 {
25    ++del;
26    printf("Disconnected #%i!\n", del);
27    if (add == del)
28      ecore_main_loop_quit();
29    return ECORE_CALLBACK_RENEW;
30 }
31
32 int
33 main(int argc, const char *argv[])
34 {
35    ecore_init();
36    ecore_con_init();
37    ecore_app_args_set(argc, argv);
38    eina_log_domain_level_set("ecore_con", EINA_LOG_LEVEL_ERR);
39    eina_log_domain_level_set("eina", EINA_LOG_LEVEL_ERR);
40
41 /* to use a PEM certificate with TLS and SSL3, uncomment the lines below */
42 //   if (!(svr = ecore_con_server_add(ECORE_CON_REMOTE_NODELAY | ECORE_CON_USE_MIXED | ECORE_CON_LOAD_CERT, "127.0.0.1", 8080, NULL)))
43
44 /* to use simple tcp with ssl/tls, use this line */
45    svr = ecore_con_server_add(ECORE_CON_REMOTE_NODELAY, "127.0.0.1", 8080, NULL);
46    if (!svr)
47      exit(1);
48
49    ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, (Ecore_Event_Handler_Cb)_add, NULL);
50    ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, (Ecore_Event_Handler_Cb)_del, NULL);
51
52 /* start server */
53    ecore_main_loop_begin();
54    if (add && del)
55      {
56         printf("Restarting server after %i connections\n", add);
57         add = del = 0;
58         ecore_con_server_del(svr);
59         ecore_app_restart();
60      }
61    return 0;
62 }
63