From: Jihoon Kim <jihoon48.kim@samsung.com>
[framework/uifw/ecore.git] / src / examples / 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 10000
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 main(void)
54 {
55    double done;
56    eina_init();
57    ecore_init();
58    ecore_con_init();
59
60    eina_log_domain_level_set("ecore_con", EINA_LOG_LEVEL_ERR);
61    eina_log_domain_level_set("eina", EINA_LOG_LEVEL_ERR);
62    counter = eina_counter_new("client");
63    eina_counter_start(counter);
64    done = ecore_time_get();
65
66    ecore_job_add(_spawn, NULL);
67
68 /* set event handler for server connect */
69    ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb)_add, NULL);
70    ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb)_del, NULL);
71
72 /* start client */
73    ecore_main_loop_begin();
74    eina_counter_stop(counter, 1);
75    printf("\nTime elapsed for %i connections: %f seconds\n%s", NUM_CLIENTS, ecore_time_get() - done, eina_counter_dump(counter));
76    return 0;
77 }