diff options
author | David Walter Seikel | 2013-01-13 17:29:19 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 17:29:19 +1000 |
commit | 07274513e984f0b5544586c74508ccd16e7dcafa (patch) | |
tree | b32ff2a9136fbc1a4a6a0ed1e4d79cde0f5f16d9 /libraries/ecore/src/examples/ecore_con_server_http_example.c | |
parent | Added Irrlicht 1.8, but without all the Windows binaries. (diff) | |
download | SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.zip SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.gz SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.bz2 SledjHamr-07274513e984f0b5544586c74508ccd16e7dcafa.tar.xz |
Remove EFL, since it's been released now.
Diffstat (limited to 'libraries/ecore/src/examples/ecore_con_server_http_example.c')
-rw-r--r-- | libraries/ecore/src/examples/ecore_con_server_http_example.c | 135 |
1 files changed, 0 insertions, 135 deletions
diff --git a/libraries/ecore/src/examples/ecore_con_server_http_example.c b/libraries/ecore/src/examples/ecore_con_server_http_example.c deleted file mode 100644 index d3fdeee..0000000 --- a/libraries/ecore/src/examples/ecore_con_server_http_example.c +++ /dev/null | |||
@@ -1,135 +0,0 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <sys/time.h> | ||
3 | #include <Ecore.h> | ||
4 | #include <Ecore_Con.h> | ||
5 | |||
6 | #ifdef HAVE_CONFIG_H | ||
7 | # include "config.h" | ||
8 | #else | ||
9 | # define __UNUSED__ | ||
10 | #endif | ||
11 | |||
12 | static const char response_template[] = | ||
13 | "HTTP/1.0 200 OK\r\n" | ||
14 | "Server: Ecore_Con custom server\r\n" | ||
15 | "Content-Length: %zd\r\n" | ||
16 | "Content-Type: text/html; charset=UTF-8\r\n" | ||
17 | "Set-Cookie: MYCOOKIE=1; path=/; expires=%s\r\n" | ||
18 | "Set-Cookie: SESSIONCOOKIE=1; path=/\r\n" | ||
19 | "\r\n" | ||
20 | "%s"; | ||
21 | |||
22 | struct _Client { | ||
23 | int sdata; | ||
24 | }; | ||
25 | |||
26 | Eina_Bool | ||
27 | _add(void *data __UNUSED__, int type __UNUSED__, Ecore_Con_Event_Client_Add *ev) | ||
28 | { | ||
29 | struct _Client *client = malloc(sizeof(*client)); | ||
30 | client->sdata = 0; | ||
31 | static char buf[4096]; | ||
32 | char welcome[] = "Welcome to Ecore_Con server!"; | ||
33 | time_t t; | ||
34 | |||
35 | printf("Client with ip %s, port %d, connected = %d!\n", | ||
36 | ecore_con_client_ip_get(ev->client), | ||
37 | ecore_con_client_port_get(ev->client), | ||
38 | ecore_con_client_connected_get(ev->client)); | ||
39 | |||
40 | ecore_con_client_data_set(ev->client, client); | ||
41 | |||
42 | t = time(NULL); | ||
43 | t += 60 * 60 * 24; | ||
44 | snprintf(buf, sizeof(buf), response_template, sizeof(welcome) - 1, ctime(&t), welcome); | ||
45 | |||
46 | ecore_con_client_send(ev->client, buf, strlen(buf)); | ||
47 | ecore_con_client_flush(ev->client); | ||
48 | |||
49 | |||
50 | return ECORE_CALLBACK_RENEW; | ||
51 | } | ||
52 | |||
53 | |||
54 | Eina_Bool | ||
55 | _del(void *data __UNUSED__, int type __UNUSED__, Ecore_Con_Event_Client_Del *ev) | ||
56 | { | ||
57 | struct _Client *client; | ||
58 | |||
59 | if (!ev->client) | ||
60 | return ECORE_CALLBACK_RENEW; | ||
61 | |||
62 | client = ecore_con_client_data_get(ev->client); | ||
63 | |||
64 | printf("Lost client with ip %s!\n", ecore_con_client_ip_get(ev->client)); | ||
65 | printf("Total data received from this client: %d\n", client->sdata); | ||
66 | printf("Client was connected for %0.3f seconds.\n", | ||
67 | ecore_con_client_uptime_get(ev->client)); | ||
68 | |||
69 | if (client) | ||
70 | free(client); | ||
71 | |||
72 | ecore_con_client_del(ev->client); | ||
73 | |||
74 | return ECORE_CALLBACK_RENEW; | ||
75 | } | ||
76 | |||
77 | Eina_Bool | ||
78 | _data(void *data __UNUSED__, int type __UNUSED__, Ecore_Con_Event_Client_Data *ev) | ||
79 | { | ||
80 | char fmt[128]; | ||
81 | struct _Client *client = ecore_con_client_data_get(ev->client); | ||
82 | |||
83 | snprintf(fmt, sizeof(fmt), | ||
84 | "\nReceived %i bytes from client %s port %d:\n" | ||
85 | ">>>>>\n" | ||
86 | "%%.%is\n" | ||
87 | ">>>>>\n\n", | ||
88 | ev->size, ecore_con_client_ip_get(ev->client), | ||
89 | ecore_con_client_port_get(ev->client), ev->size); | ||
90 | |||
91 | printf(fmt, ev->data); | ||
92 | |||
93 | client->sdata += ev->size; | ||
94 | |||
95 | return ECORE_CALLBACK_RENEW; | ||
96 | } | ||
97 | |||
98 | int main(void) | ||
99 | { | ||
100 | Ecore_Con_Server *svr; | ||
101 | Ecore_Con_Client *cl; | ||
102 | const Eina_List *clients, *l; | ||
103 | |||
104 | eina_init(); | ||
105 | ecore_init(); | ||
106 | ecore_con_init(); | ||
107 | |||
108 | if (!(svr = ecore_con_server_add(ECORE_CON_REMOTE_TCP, "127.0.0.1", 8080, NULL))) | ||
109 | exit(1); | ||
110 | |||
111 | ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, (Ecore_Event_Handler_Cb)_add, NULL); | ||
112 | ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, (Ecore_Event_Handler_Cb)_del, NULL); | ||
113 | ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA, (Ecore_Event_Handler_Cb)_data, NULL); | ||
114 | ecore_con_server_client_limit_set(svr, 3, 0); | ||
115 | |||
116 | ecore_main_loop_begin(); | ||
117 | |||
118 | clients = ecore_con_server_clients_get(svr); | ||
119 | printf("Clients still connected to this server when exiting: %d\n", | ||
120 | eina_list_count(clients)); | ||
121 | EINA_LIST_FOREACH(clients, l, cl) | ||
122 | { | ||
123 | printf("%s\n", ecore_con_client_ip_get(cl)); | ||
124 | free(ecore_con_client_data_get(cl)); | ||
125 | } | ||
126 | |||
127 | printf("Server was up for %0.3f seconds\n", | ||
128 | ecore_con_server_uptime_get(svr)); | ||
129 | |||
130 | ecore_con_shutdown(); | ||
131 | ecore_shutdown(); | ||
132 | eina_shutdown(); | ||
133 | |||
134 | return 0; | ||
135 | } | ||