Tizen 2.1 base
[framework/uifw/ecore.git] / src / examples / ecore_client_bench.c
1 #include <stdio.h>
2 #include <Ecore.h>
3 #include <Ecore_Con.h>
4
5 /* Ecore_Con client example
6  * 2010 Mike Blumenkrantz
7  */
8
9 #define NUM_CLIENTS 30000
10
11 static Eina_Counter *counter;
12 static int add = 0;
13 static int del = 0;
14
15 Eina_Bool
16 _add(void *data, int type, Ecore_Con_Event_Server_Add *ev)
17 {
18    ++add;
19    printf("Connection #%i!\n", add);
20    if (add == NUM_CLIENTS)
21      ecore_main_loop_quit();
22
23    return ECORE_CALLBACK_RENEW;
24 }
25
26 Eina_Bool
27 _del(void *data, int type, Ecore_Con_Event_Server_Add *ev)
28 {
29    ++del;
30    printf("Connection lost! #%i!\n", del);
31
32    return ECORE_CALLBACK_RENEW;
33 }
34
35 static void
36 _spawn(void *data)
37 {
38    int x;
39
40    for (x = 0; x < NUM_CLIENTS; x++)
41      {
42 //        printf("Creating connection %i\n", x);
43         if (!ecore_con_server_connect(ECORE_CON_REMOTE_NODELAY, "127.0.0.1", 8080, NULL))
44           {
45              printf("CRITICAL ERROR!\n"
46                     "Could not create connection #%i!\n", x);
47              exit(1);
48           }
49      }
50    printf("***Job done***\n");
51 }
52
53 int
54 main(void)
55 {
56    double done;
57    eina_init();
58    ecore_init();
59    ecore_con_init();
60
61    eina_log_domain_level_set("ecore_con", EINA_LOG_LEVEL_ERR);
62    eina_log_domain_level_set("eina", EINA_LOG_LEVEL_ERR);
63    counter = eina_counter_new("client");
64    eina_counter_start(counter);
65    done = ecore_time_get();
66
67    ecore_job_add(_spawn, NULL);
68
69 /* set event handler for server connect */
70    ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb)_add, NULL);
71    ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb)_del, NULL);
72
73 /* start client */
74    ecore_main_loop_begin();
75    eina_counter_stop(counter, 1);
76    printf("\nTime elapsed for %i connections: %f seconds\n%s", NUM_CLIENTS, ecore_time_get() - done, eina_counter_dump(counter));
77    return 0;
78 }
79