aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ecore/src/examples/ecore_client_bench.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ecore/src/examples/ecore_client_bench.c')
-rw-r--r--libraries/ecore/src/examples/ecore_client_bench.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/libraries/ecore/src/examples/ecore_client_bench.c b/libraries/ecore/src/examples/ecore_client_bench.c
new file mode 100644
index 0000000..2a58dcf
--- /dev/null
+++ b/libraries/ecore/src/examples/ecore_client_bench.c
@@ -0,0 +1,77 @@
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
11static Eina_Counter *counter;
12static int add = 0;
13static int del = 0;
14
15Eina_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
26Eina_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
35static 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
53int 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}