13 #ifdef HAVE_NETINET_TCP_H
14 # include <netinet/tcp.h>
17 #ifdef HAVE_NETINET_IN_H
18 # include <netinet/in.h>
21 #ifdef HAVE_ARPA_INET_H
22 # include <arpa/inet.h>
25 #ifdef HAVE_SYS_SOCKET_H
26 # include <sys/socket.h>
33 #ifdef HAVE_WS2TCPIP_H
34 # include <ws2tcpip.h>
42 #include "ecore_private.h"
43 #include "Ecore_Con.h"
44 #include "ecore_con_private.h"
46 static Eina_Bool _ecore_con_client_timer(Ecore_Con_Client *cl);
47 static void _ecore_con_cl_timer_update(Ecore_Con_Client *cl);
48 static Eina_Bool _ecore_con_server_timer(Ecore_Con_Server *svr);
49 static void _ecore_con_server_timer_update(Ecore_Con_Server *svr);
51 static void _ecore_con_cb_tcp_connect(void *data,
52 Ecore_Con_Info *info);
53 static void _ecore_con_cb_udp_connect(void *data,
54 Ecore_Con_Info *info);
55 static void _ecore_con_cb_tcp_listen(void *data,
56 Ecore_Con_Info *info);
57 static void _ecore_con_cb_udp_listen(void *data,
58 Ecore_Con_Info *info);
60 static void _ecore_con_server_free(Ecore_Con_Server *svr);
61 static void _ecore_con_client_free(Ecore_Con_Client *cl);
63 static void _ecore_con_cl_read(Ecore_Con_Server *svr);
64 static Eina_Bool _ecore_con_svr_tcp_handler(void *data,
65 Ecore_Fd_Handler *fd_handler);
66 static Eina_Bool _ecore_con_cl_handler(void *data,
67 Ecore_Fd_Handler *fd_handler);
68 static Eina_Bool _ecore_con_cl_udp_handler(void *data,
69 Ecore_Fd_Handler *fd_handler);
70 static Eina_Bool _ecore_con_svr_udp_handler(void *data,
71 Ecore_Fd_Handler *fd_handler);
73 static void _ecore_con_svr_cl_read(Ecore_Con_Client *cl);
74 static Eina_Bool _ecore_con_svr_cl_handler(void *data,
75 Ecore_Fd_Handler *fd_handler);
77 static void _ecore_con_server_flush(Ecore_Con_Server *svr);
78 static void _ecore_con_client_flush(Ecore_Con_Client *cl);
80 static void _ecore_con_event_client_add_free(Ecore_Con_Server *svr,
82 static void _ecore_con_event_client_del_free(Ecore_Con_Server *svr,
84 static void _ecore_con_event_client_data_free(Ecore_Con_Server *svr,
86 static void _ecore_con_event_server_add_free(void *data,
88 static void _ecore_con_event_server_del_free(void *data,
90 static void _ecore_con_event_server_data_free(void *data,
92 static void _ecore_con_event_server_error_free(void *data,
93 Ecore_Con_Event_Server_Error *e);
94 static void _ecore_con_event_client_error_free(Ecore_Con_Server *svr,
95 Ecore_Con_Event_Client_Error *e);
96 static void _ecore_con_event_server_write_free(void *data,
97 Ecore_Con_Event_Server_Write *e);
98 static void _ecore_con_event_client_write_free(Ecore_Con_Server *svr,
99 Ecore_Con_Event_Client_Write *e);
101 static void _ecore_con_lookup_done(void *data,
102 Ecore_Con_Info *infos);
104 static const char * _ecore_con_pretty_ip(struct sockaddr *client_addr);
108 _ecore_con_client_kill(Ecore_Con_Client *cl)
111 DBG("Multi kill request for client %p", cl);
114 ecore_con_event_client_del(cl);
117 INF("Lost client %s", (cl->ip) ? cl->ip : "");
119 ecore_main_fd_handler_del(cl->fd_handler);
121 cl->fd_handler = NULL;
125 _ecore_con_server_kill(Ecore_Con_Server *svr)
128 DBG("Multi kill request for svr %p", svr);
130 ecore_con_event_server_del(svr);
133 ecore_main_fd_handler_del(svr->fd_handler);
135 svr->fd_handler = NULL;
138 #define _ecore_con_server_kill(svr) do { \
139 DBG("KILL %p", (svr)); \
140 _ecore_con_server_kill((svr)); \
143 #define _ecore_con_client_kill(cl) do { \
144 DBG("KILL %p", (cl)); \
145 _ecore_con_client_kill((cl)); \
148 EAPI int ECORE_CON_EVENT_CLIENT_ADD = 0;
149 EAPI int ECORE_CON_EVENT_CLIENT_DEL = 0;
150 EAPI int ECORE_CON_EVENT_SERVER_ADD = 0;
151 EAPI int ECORE_CON_EVENT_SERVER_DEL = 0;
152 EAPI int ECORE_CON_EVENT_CLIENT_DATA = 0;
153 EAPI int ECORE_CON_EVENT_SERVER_DATA = 0;
154 EAPI int ECORE_CON_EVENT_CLIENT_WRITE = 0;
155 EAPI int ECORE_CON_EVENT_SERVER_WRITE = 0;
156 EAPI int ECORE_CON_EVENT_CLIENT_ERROR = 0;
157 EAPI int ECORE_CON_EVENT_SERVER_ERROR = 0;
158 EAPI int ECORE_CON_EVENT_PROXY_BIND = 0;
160 static Eina_List *servers = NULL;
161 static int _ecore_con_init_count = 0;
162 static int _ecore_con_event_count = 0;
163 int _ecore_con_log_dom = -1;
164 Ecore_Con_Socks *_ecore_con_proxy_once = NULL;
165 Ecore_Con_Socks *_ecore_con_proxy_global = NULL;
170 if (++_ecore_con_init_count != 1)
171 return _ecore_con_init_count;
175 return --_ecore_con_init_count;
180 return --_ecore_con_init_count;
182 _ecore_con_log_dom = eina_log_domain_register
183 ("ecore_con", ECORE_CON_DEFAULT_LOG_COLOR);
184 if (_ecore_con_log_dom < 0)
186 EINA_LOG_ERR("Impossible to create a log domain for Ecore Con.");
188 return --_ecore_con_init_count;
191 ecore_con_mempool_init();
193 ECORE_CON_EVENT_CLIENT_ADD = ecore_event_type_new();
194 ECORE_CON_EVENT_CLIENT_DEL = ecore_event_type_new();
195 ECORE_CON_EVENT_SERVER_ADD = ecore_event_type_new();
196 ECORE_CON_EVENT_SERVER_DEL = ecore_event_type_new();
197 ECORE_CON_EVENT_CLIENT_DATA = ecore_event_type_new();
198 ECORE_CON_EVENT_SERVER_DATA = ecore_event_type_new();
199 ECORE_CON_EVENT_CLIENT_WRITE = ecore_event_type_new();
200 ECORE_CON_EVENT_SERVER_WRITE = ecore_event_type_new();
201 ECORE_CON_EVENT_CLIENT_ERROR = ecore_event_type_new();
202 ECORE_CON_EVENT_SERVER_ERROR = ecore_event_type_new();
203 ECORE_CON_EVENT_PROXY_BIND = ecore_event_type_new();
206 eina_magic_string_set(ECORE_MAGIC_CON_SERVER, "Ecore_Con_Server");
207 eina_magic_string_set(ECORE_MAGIC_CON_CLIENT, "Ecore_Con_Server");
208 eina_magic_string_set(ECORE_MAGIC_CON_URL, "Ecore_Con_Url");
210 /* TODO Remember return value, if it fails, use gethostbyname() */
211 ecore_con_socks_init();
212 ecore_con_ssl_init();
213 ecore_con_info_init();
215 return _ecore_con_init_count;
219 ecore_con_shutdown(void)
222 Ecore_Con_Server *svr;
224 if (--_ecore_con_init_count != 0)
225 return _ecore_con_init_count;
227 EINA_LIST_FOREACH_SAFE(servers, l, l2, svr)
229 Ecore_Con_Event_Server_Add *ev;
231 svr->delete_me = EINA_TRUE;
232 INF("svr %p is dead", svr);
233 /* some pointer hacks here to prevent double frees if people are being stupid */
234 EINA_LIST_FREE(svr->event_count, ev)
236 _ecore_con_server_free(svr);
239 ecore_con_socks_shutdown();
240 if (!_ecore_con_event_count) ecore_con_mempool_shutdown();
242 ecore_con_info_shutdown();
243 ecore_con_ssl_shutdown();
244 eina_log_domain_unregister(_ecore_con_log_dom);
245 _ecore_con_log_dom = -1;
251 return _ecore_con_init_count;
255 ecore_con_lookup(const char *name,
256 Ecore_Con_Dns_Cb done_cb,
259 Ecore_Con_Server *svr;
260 Ecore_Con_Lookup *lk;
261 struct addrinfo hints;
263 if (!name || !done_cb)
266 svr = calloc(1, sizeof(Ecore_Con_Server));
270 lk = malloc(sizeof (Ecore_Con_Lookup));
277 lk->done_cb = done_cb;
280 svr->name = strdup(name);
284 svr->type = ECORE_CON_REMOTE_TCP;
287 svr->created = EINA_TRUE;
288 svr->reject_excess_clients = EINA_FALSE;
289 svr->client_limit = -1;
291 svr->ppid = getpid();
293 memset(&hints, 0, sizeof(struct addrinfo));
294 hints.ai_family = AF_UNSPEC;
295 hints.ai_socktype = SOCK_STREAM;
296 hints.ai_flags = AI_CANONNAME;
297 hints.ai_protocol = IPPROTO_TCP;
298 hints.ai_canonname = NULL;
299 hints.ai_next = NULL;
300 hints.ai_addr = NULL;
302 if (ecore_con_info_get(svr, _ecore_con_lookup_done, svr,
314 * @addtogroup Ecore_Con_Server_Group Ecore Connection Server Functions
316 * Functions that operate on Ecore server objects.
322 * @example ecore_con_server_example.c
323 * Shows how to write a simple server using the Ecore_Con library.
326 EAPI Ecore_Con_Server *
327 ecore_con_server_add(Ecore_Con_Type compl_type,
332 Ecore_Con_Server *svr;
335 if (port < 0 || !name)
336 return NULL; /* local user socket: FILE: ~/.ecore/[name]/[port] */
338 /* local system socket: FILE: /tmp/.ecore_service|[name]|[port] */
339 /* remote system socket: TCP/IP: [name]:[port] */
340 svr = calloc(1, sizeof(Ecore_Con_Server));
344 svr->name = strdup(name);
348 svr->type = compl_type;
350 svr->data = (void *)data;
351 svr->created = EINA_TRUE;
352 svr->use_cert = (compl_type & ECORE_CON_SSL & ECORE_CON_LOAD_CERT) == ECORE_CON_LOAD_CERT;
353 svr->reject_excess_clients = EINA_FALSE;
354 svr->client_limit = -1;
356 svr->ppid = getpid();
357 if (ecore_con_ssl_server_prepare(svr, compl_type & ECORE_CON_SSL))
360 type = compl_type & ECORE_CON_TYPE;
362 if ((type == ECORE_CON_LOCAL_USER) ||
363 (type == ECORE_CON_LOCAL_SYSTEM) ||
364 (type == ECORE_CON_LOCAL_ABSTRACT))
367 if (!ecore_con_local_listen(svr))
370 if (!ecore_con_local_listen(svr, _ecore_con_svr_tcp_handler, svr))
374 if ((type == ECORE_CON_REMOTE_TCP) ||
375 (type == ECORE_CON_REMOTE_NODELAY) ||
376 (type == ECORE_CON_REMOTE_CORK))
379 if (!ecore_con_info_tcp_listen(svr, _ecore_con_cb_tcp_listen,
383 else if ((type == ECORE_CON_REMOTE_MCAST) ||
384 (type == ECORE_CON_REMOTE_UDP))
386 if (!ecore_con_info_udp_listen(svr, _ecore_con_cb_udp_listen,
390 servers = eina_list_append(servers, svr);
391 ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER);
404 ecore_main_fd_handler_del(svr->fd_handler);
410 eina_binbuf_free(svr->buf);
413 eina_stringshare_del(svr->ip);
415 ecore_con_ssl_server_shutdown(svr);
420 EAPI Ecore_Con_Server *
421 ecore_con_server_connect(Ecore_Con_Type compl_type,
426 Ecore_Con_Server *svr;
429 if ((!name) || (!name[0]))
431 /* local user socket: FILE: ~/.ecore/[name]/[port] */
432 /* local system socket: FILE: /tmp/.ecore_service|[name]|[port] */
433 /* remote system socket: TCP/IP: [name]:[port] */
434 svr = calloc(1, sizeof(Ecore_Con_Server));
438 svr->name = strdup(name);
442 svr->type = compl_type;
444 svr->data = (void *)data;
445 svr->created = EINA_FALSE;
446 svr->use_cert = (compl_type & ECORE_CON_SSL & ECORE_CON_LOAD_CERT) == ECORE_CON_LOAD_CERT;
447 svr->reject_excess_clients = EINA_FALSE;
449 svr->client_limit = -1;
451 type = compl_type & ECORE_CON_TYPE;
453 if (type > ECORE_CON_LOCAL_ABSTRACT)
455 /* never use proxies on local connections */
456 if (_ecore_con_proxy_once)
457 svr->ecs = _ecore_con_proxy_once;
458 else if (_ecore_con_proxy_global)
459 svr->ecs = _ecore_con_proxy_global;
460 _ecore_con_proxy_once = NULL;
463 if ((!svr->ecs->lookup) &&
464 (!ecore_con_lookup(svr->name, (Ecore_Con_Dns_Cb)ecore_con_socks_dns_cb, svr)))
466 if (svr->ecs->lookup)
467 svr->ecs_state = ECORE_CON_PROXY_STATE_RESOLVED;
470 if (ecore_con_ssl_server_prepare(svr, compl_type & ECORE_CON_SSL))
473 if (((type == ECORE_CON_REMOTE_TCP) ||
474 (type == ECORE_CON_REMOTE_NODELAY) ||
475 (type == ECORE_CON_REMOTE_CORK) ||
476 (type == ECORE_CON_REMOTE_UDP) ||
477 (type == ECORE_CON_REMOTE_BROADCAST)) &&
481 if ((type == ECORE_CON_LOCAL_USER) ||
482 (type == ECORE_CON_LOCAL_SYSTEM) ||
483 (type == ECORE_CON_LOCAL_ABSTRACT))
486 if (!ecore_con_local_connect(svr, _ecore_con_cl_handler))
489 if (!ecore_con_local_connect(svr, _ecore_con_cl_handler, svr))
493 if ((type == ECORE_CON_REMOTE_TCP) ||
494 (type == ECORE_CON_REMOTE_NODELAY) ||
495 (type == ECORE_CON_REMOTE_CORK))
498 if (!ecore_con_info_tcp_connect(svr, _ecore_con_cb_tcp_connect,
502 else if ((type == ECORE_CON_REMOTE_UDP) ||
503 (type == ECORE_CON_REMOTE_BROADCAST))
505 if (!ecore_con_info_udp_connect(svr, _ecore_con_cb_udp_connect,
509 servers = eina_list_append(servers, svr);
510 ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER);
522 ecore_main_fd_handler_del(svr->fd_handler);
527 ecore_con_ssl_server_shutdown(svr);
533 ecore_con_server_timeout_set(Ecore_Con_Server *svr,
536 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
538 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_timeout_set");
543 svr->client_disconnect_time = timeout;
545 svr->disconnect_time = timeout;
549 ecore_con_server_timeout_get(Ecore_Con_Server *svr)
551 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
553 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_timeout_get");
557 return svr->created ? svr->client_disconnect_time : svr->disconnect_time;
561 ecore_con_server_del(Ecore_Con_Server *svr)
563 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
565 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_del");
572 _ecore_con_server_kill(svr);
577 ecore_con_server_data_get(Ecore_Con_Server *svr)
579 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
581 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_data_get");
589 ecore_con_server_data_set(Ecore_Con_Server *svr,
594 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
596 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_data_get");
606 ecore_con_server_connected_get(Ecore_Con_Server *svr)
608 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
610 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_connected_get");
620 EAPI const Eina_List *
621 ecore_con_server_clients_get(Ecore_Con_Server *svr)
623 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
625 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
626 "ecore_con_server_clients_get");
634 ecore_con_server_name_get(Ecore_Con_Server *svr)
636 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
638 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
639 "ecore_con_server_name_get");
647 ecore_con_server_port_get(Ecore_Con_Server *svr)
649 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
651 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
652 "ecore_con_server_port_get");
659 ecore_con_server_send(Ecore_Con_Server *svr,
663 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
665 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_send");
669 EINA_SAFETY_ON_TRUE_RETURN_VAL(svr->delete_me, 0);
671 EINA_SAFETY_ON_NULL_RETURN_VAL(data, 0);
673 EINA_SAFETY_ON_TRUE_RETURN_VAL(size < 1, 0);
676 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE);
680 svr->buf = eina_binbuf_new();
681 EINA_SAFETY_ON_NULL_RETURN_VAL(svr->buf, 0);
683 if ((svr->fd >= 0) && ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK))
686 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
687 /* realistically this isn't anything serious so we can just log and continue */
688 ERR("corking failed! %s", strerror(errno));
692 eina_binbuf_append_length(svr->buf, data, size);
698 ecore_con_server_client_limit_set(Ecore_Con_Server *svr,
700 char reject_excess_clients)
702 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
704 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
705 "ecore_con_server_client_limit_set");
709 svr->client_limit = client_limit;
710 svr->reject_excess_clients = reject_excess_clients;
714 ecore_con_server_ip_get(Ecore_Con_Server *svr)
716 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
718 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_ip_get");
726 ecore_con_server_uptime_get(Ecore_Con_Server *svr)
728 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
730 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_uptime_get");
734 return ecore_time_get() - svr->start_time;
738 ecore_con_server_flush(Ecore_Con_Server *svr)
740 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
742 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_flush");
746 _ecore_con_server_flush(svr);
754 * @addtogroup Ecore_Con_Client_Group Ecore Connection Client Functions
756 * Functions that operate on Ecore connection client objects.
762 * @example ecore_con_client_example.c
763 * Shows how to write a simple client that connects to the example server.
767 ecore_con_client_send(Ecore_Con_Client *cl,
771 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
773 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_send");
777 EINA_SAFETY_ON_TRUE_RETURN_VAL(cl->delete_me, 0);
779 EINA_SAFETY_ON_NULL_RETURN_VAL(data, 0);
781 EINA_SAFETY_ON_TRUE_RETURN_VAL(size < 1, 0);
784 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE);
786 if (cl->host_server && ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP))
787 sendto(cl->host_server->fd, data, size, 0, (struct sockaddr *)cl->client_addr,
788 cl->client_addr_len);
791 cl->buf = eina_binbuf_new();
792 EINA_SAFETY_ON_NULL_RETURN_VAL(cl->buf, 0);
794 if ((cl->fd >= 0) && ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK))
797 if (setsockopt(cl->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
798 /* realistically this isn't anything serious so we can just log and continue */
799 ERR("corking failed! %s", strerror(errno));
803 eina_binbuf_append_length(cl->buf, data, size);
808 EAPI Ecore_Con_Server *
809 ecore_con_client_server_get(Ecore_Con_Client *cl)
811 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
813 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
814 "ecore_con_client_server_get");
818 return cl->host_server;
822 ecore_con_client_connected_get(Ecore_Con_Client *cl)
824 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
826 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
827 "ecore_con_client_connected_get");
831 return !cl->delete_me;
835 ecore_con_client_timeout_set(Ecore_Con_Client *cl,
838 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
840 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
841 "ecore_con_client_timeout_set");
845 cl->disconnect_time = timeout;
847 _ecore_con_cl_timer_update(cl);
851 ecore_con_client_timeout_get(Ecore_Con_Client *cl)
853 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
855 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_timeout_get");
859 return cl->disconnect_time;
863 ecore_con_client_del(Ecore_Con_Client *cl)
865 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
867 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_del");
871 _ecore_con_client_kill(cl);
876 ecore_con_client_data_set(Ecore_Con_Client *cl,
879 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
881 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_data_set");
885 cl->data = (void *)data;
889 ecore_con_client_data_get(Ecore_Con_Client *cl)
891 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
893 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_data_get");
901 ecore_con_client_ip_get(Ecore_Con_Client *cl)
903 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
905 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_ip_get");
909 cl->ip = _ecore_con_pretty_ip(cl->client_addr);
915 ecore_con_client_port_get(Ecore_Con_Client *cl)
917 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
919 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_port_get");
922 if (cl->client_addr->sa_family == AF_INET)
923 return ((struct sockaddr_in*)cl->client_addr)->sin_port;
925 return ((struct sockaddr_in6*)cl->client_addr)->sin6_port;
932 ecore_con_client_uptime_get(Ecore_Con_Client *cl)
934 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
936 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_uptime_get");
940 return ecore_time_get() - cl->start_time;
944 ecore_con_client_flush(Ecore_Con_Client *cl)
946 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
948 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_flush");
952 _ecore_con_client_flush(cl);
956 ecore_con_server_fd_get(Ecore_Con_Server *svr)
958 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
960 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, __func__);
963 if (svr->created) return -1;
964 return ecore_main_fd_handler_fd_get(svr->fd_handler);
968 ecore_con_client_fd_get(Ecore_Con_Client *cl)
970 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
972 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, __func__);
975 return ecore_main_fd_handler_fd_get(cl->fd_handler);
983 ecore_con_event_proxy_bind(Ecore_Con_Server *svr)
985 Ecore_Con_Event_Proxy_Bind *e;
986 int ev = ECORE_CON_EVENT_PROXY_BIND;
988 e = ecore_con_event_proxy_bind_alloc();
989 EINA_SAFETY_ON_NULL_RETURN(e);
991 svr->event_count = eina_list_append(svr->event_count, e);
992 _ecore_con_server_timer_update(svr);
994 e->ip = svr->proxyip;
995 e->port = svr->proxyport;
996 ecore_event_add(ev, e,
997 _ecore_con_event_server_add_free, NULL);
998 _ecore_con_event_count++;
1002 ecore_con_event_server_add(Ecore_Con_Server *svr)
1004 /* we got our server! */
1005 Ecore_Con_Event_Server_Add *e;
1006 int ev = ECORE_CON_EVENT_SERVER_ADD;
1008 e = ecore_con_event_server_add_alloc();
1009 EINA_SAFETY_ON_NULL_RETURN(e);
1011 svr->connecting = EINA_FALSE;
1012 svr->start_time = ecore_time_get();
1013 svr->event_count = eina_list_append(svr->event_count, e);
1014 _ecore_con_server_timer_update(svr);
1016 if (svr->upgrade) ev = ECORE_CON_EVENT_SERVER_UPGRADE;
1017 ecore_event_add(ev, e,
1018 _ecore_con_event_server_add_free, NULL);
1019 _ecore_con_event_count++;
1023 ecore_con_event_server_del(Ecore_Con_Server *svr)
1025 Ecore_Con_Event_Server_Del *e;
1027 svr->delete_me = EINA_TRUE;
1028 INF("svr %p is dead", svr);
1029 e = ecore_con_event_server_del_alloc();
1030 EINA_SAFETY_ON_NULL_RETURN(e);
1032 svr->event_count = eina_list_append(svr->event_count, e);
1033 _ecore_con_server_timer_update(svr);
1037 svr->ecs_state = svr->ecs->lookup ? ECORE_CON_PROXY_STATE_RESOLVED : ECORE_CON_PROXY_STATE_DONE;
1038 eina_stringshare_replace(&svr->proxyip, NULL);
1041 ecore_event_add(ECORE_CON_EVENT_SERVER_DEL, e,
1042 _ecore_con_event_server_del_free, NULL);
1043 _ecore_con_event_count++;
1047 ecore_con_event_server_write(Ecore_Con_Server *svr, int num)
1049 Ecore_Con_Event_Server_Write *e;
1051 e = ecore_con_event_server_write_alloc();
1052 EINA_SAFETY_ON_NULL_RETURN(e);
1054 INF("Wrote %d bytes", num);
1055 svr->event_count = eina_list_append(svr->event_count, e);
1058 ecore_event_add(ECORE_CON_EVENT_SERVER_WRITE, e,
1059 (Ecore_End_Cb)_ecore_con_event_server_write_free, NULL);
1060 _ecore_con_event_count++;
1064 ecore_con_event_server_data(Ecore_Con_Server *svr, unsigned char *buf, int num, Eina_Bool duplicate)
1066 Ecore_Con_Event_Server_Data *e;
1068 e = ecore_con_event_server_data_alloc();
1069 EINA_SAFETY_ON_NULL_RETURN(e);
1071 svr->event_count = eina_list_append(svr->event_count, e);
1072 _ecore_con_server_timer_update(svr);
1076 e->data = malloc(num);
1079 ERR("server data allocation failure !");
1080 _ecore_con_event_server_data_free(NULL, e);
1083 memcpy(e->data, buf, num);
1088 ecore_event_add(ECORE_CON_EVENT_SERVER_DATA, e,
1089 _ecore_con_event_server_data_free, NULL);
1090 _ecore_con_event_count++;
1094 ecore_con_event_client_add(Ecore_Con_Client *cl)
1096 Ecore_Con_Event_Client_Add *e;
1097 int ev = ECORE_CON_EVENT_CLIENT_ADD;
1099 e = ecore_con_event_client_add_alloc();
1100 EINA_SAFETY_ON_NULL_RETURN(e);
1102 cl->event_count = eina_list_append(cl->event_count, e);
1103 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1104 _ecore_con_cl_timer_update(cl);
1106 if (cl->upgrade) ev = ECORE_CON_EVENT_CLIENT_UPGRADE;
1107 ecore_event_add(ev, e,
1108 (Ecore_End_Cb)_ecore_con_event_client_add_free, cl->host_server);
1109 _ecore_con_event_count++;
1113 ecore_con_event_client_del(Ecore_Con_Client *cl)
1115 Ecore_Con_Event_Client_Del *e;
1118 cl->delete_me = EINA_TRUE;
1119 INF("cl %p is dead", cl);
1120 e = ecore_con_event_client_del_alloc();
1121 EINA_SAFETY_ON_NULL_RETURN(e);
1122 cl->event_count = eina_list_append(cl->event_count, e);
1124 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1125 _ecore_con_cl_timer_update(cl);
1127 ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
1128 (Ecore_End_Cb)_ecore_con_event_client_del_free, cl->host_server);
1129 _ecore_con_event_count++;
1133 ecore_con_event_client_write(Ecore_Con_Client *cl, int num)
1135 Ecore_Con_Event_Client_Write *e;
1137 e = ecore_con_event_client_write_alloc();
1138 EINA_SAFETY_ON_NULL_RETURN(e);
1140 cl->event_count = eina_list_append(cl->event_count, e);
1141 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1144 ecore_event_add(ECORE_CON_EVENT_CLIENT_WRITE, e,
1145 (Ecore_End_Cb)_ecore_con_event_client_write_free, cl->host_server);
1146 _ecore_con_event_count++;
1150 ecore_con_event_client_data(Ecore_Con_Client *cl, unsigned char *buf, int num, Eina_Bool duplicate)
1152 Ecore_Con_Event_Client_Data *e;
1154 e = ecore_con_event_client_data_alloc();
1155 EINA_SAFETY_ON_NULL_RETURN(e);
1157 cl->event_count = eina_list_append(cl->event_count, e);
1158 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1159 _ecore_con_cl_timer_update(cl);
1163 e->data = malloc(num);
1166 ERR("client data allocation failure !");
1167 _ecore_con_event_client_data_free(cl->host_server, e);
1170 memcpy(e->data, buf, num);
1175 ecore_event_add(ECORE_CON_EVENT_CLIENT_DATA, e,
1176 (Ecore_End_Cb)_ecore_con_event_client_data_free, cl->host_server);
1177 _ecore_con_event_count++;
1182 ecore_con_server_infos_del(Ecore_Con_Server *svr, void *info)
1184 svr->infos = eina_list_remove(svr->infos, info);
1188 _ecore_con_event_server_error(Ecore_Con_Server *svr, char *error, Eina_Bool duplicate)
1190 Ecore_Con_Event_Server_Error *e;
1192 e = ecore_con_event_server_error_alloc();
1193 EINA_SAFETY_ON_NULL_RETURN(e);
1196 e->error = duplicate ? strdup(error) : error;
1198 svr->event_count = eina_list_append(svr->event_count, e);
1199 ecore_event_add(ECORE_CON_EVENT_SERVER_ERROR, e, (Ecore_End_Cb)_ecore_con_event_server_error_free, NULL);
1200 _ecore_con_event_count++;
1204 ecore_con_event_client_error(Ecore_Con_Client *cl, const char *error)
1206 Ecore_Con_Event_Client_Error *e;
1208 e = ecore_con_event_client_error_alloc();
1209 EINA_SAFETY_ON_NULL_RETURN(e);
1212 e->error = strdup(error);
1214 cl->event_count = eina_list_append(cl->event_count, e);
1215 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1216 ecore_event_add(ECORE_CON_EVENT_CLIENT_ERROR, e, (Ecore_End_Cb)_ecore_con_event_client_error_free, cl->host_server);
1217 _ecore_con_event_count++;
1221 _ecore_con_server_free(Ecore_Con_Server *svr)
1223 Ecore_Con_Client *cl;
1226 if (svr->event_count) return;
1230 ecore_con_info_data_clear(svr->infos->data);
1231 svr->infos = eina_list_remove_list(svr->infos, svr->infos);
1234 t_start = ecore_time_get();
1235 while (svr->buf && (!svr->delete_me))
1237 _ecore_con_server_flush(svr);
1238 t = ecore_time_get();
1239 if ((t - t_start) > 0.5)
1241 WRN("ECORE_CON: EEK - stuck in _ecore_con_server_free() trying\n"
1242 " to flush data out from the server, and have been for\n"
1243 " %1.1f seconds. This is taking too long. Aborting flush.",
1250 ecore_con_local_win32_server_del(svr);
1252 if (svr->event_count) return;
1253 ECORE_MAGIC_SET(svr, ECORE_MAGIC_NONE);
1256 eina_binbuf_free(svr->buf);
1258 EINA_LIST_FREE(svr->clients, cl)
1260 Ecore_Con_Event_Server_Add *ev;
1262 /* some pointer hacks here to prevent double frees if people are being stupid */
1263 EINA_LIST_FREE(cl->event_count, ev)
1265 cl->delete_me = EINA_TRUE;
1266 INF("cl %p is dead", cl);
1267 _ecore_con_client_free(cl);
1269 if ((svr->created) && (svr->path) && (svr->ppid == getpid()))
1272 ecore_con_ssl_server_shutdown(svr);
1277 eina_stringshare_del(svr->ip);
1278 eina_stringshare_del(svr->verify_name);
1280 if (svr->ecs_buf) eina_binbuf_free(svr->ecs_buf);
1281 if (svr->ecs_recvbuf) eina_binbuf_free(svr->ecs_recvbuf);
1283 if (svr->fd_handler)
1284 ecore_main_fd_handler_del(svr->fd_handler);
1289 if (svr->until_deletion)
1290 ecore_timer_del(svr->until_deletion);
1292 servers = eina_list_remove(servers, svr);
1298 _ecore_con_client_free(Ecore_Con_Client *cl)
1302 if (cl->event_count) return;
1304 t_start = ecore_time_get();
1305 while ((cl->buf) && (!cl->delete_me))
1307 _ecore_con_client_flush(cl);
1308 t = ecore_time_get();
1309 if ((t - t_start) > 0.5)
1311 WRN("EEK - stuck in _ecore_con_client_free() trying\n"
1312 " to flush data out from the client, and have been for\n"
1313 " %1.1f seconds. This is taking too long. Aborting flush.",
1318 cl->host_server->clients = eina_list_remove(cl->host_server->clients, cl);
1321 ecore_con_local_win32_client_del(cl);
1324 if (cl->event_count) return;
1325 ECORE_MAGIC_SET(cl, ECORE_MAGIC_NONE);
1327 if (cl->buf) eina_binbuf_free(cl->buf);
1329 if (cl->host_server->type & ECORE_CON_SSL)
1330 ecore_con_ssl_client_shutdown(cl);
1333 ecore_main_fd_handler_del(cl->fd_handler);
1338 free(cl->client_addr);
1339 cl->client_addr = NULL;
1341 if (cl->until_deletion)
1342 ecore_timer_del(cl->until_deletion);
1344 eina_stringshare_del(cl->ip);
1351 _ecore_con_server_timer(Ecore_Con_Server *svr)
1353 ecore_con_server_del(svr);
1355 svr->until_deletion = NULL;
1356 return ECORE_CALLBACK_CANCEL;
1360 _ecore_con_server_timer_update(Ecore_Con_Server *svr)
1362 if (svr->disconnect_time)
1364 if (svr->disconnect_time > 0)
1366 if (svr->until_deletion)
1367 ecore_timer_interval_set(svr->until_deletion, svr->disconnect_time);
1369 svr->until_deletion = ecore_timer_add(svr->disconnect_time, (Ecore_Task_Cb)_ecore_con_server_timer, svr);
1371 else if (svr->until_deletion)
1373 ecore_timer_del(svr->until_deletion);
1374 svr->until_deletion = NULL;
1379 if (svr->until_deletion)
1381 ecore_timer_del(svr->until_deletion);
1382 svr->until_deletion = NULL;
1388 _ecore_con_client_timer(Ecore_Con_Client *cl)
1390 ecore_con_client_del(cl);
1392 cl->until_deletion = NULL;
1393 return ECORE_CALLBACK_CANCEL;
1397 _ecore_con_cl_timer_update(Ecore_Con_Client *cl)
1399 if (cl->disconnect_time)
1401 if (cl->disconnect_time > 0)
1403 if (cl->until_deletion)
1404 ecore_timer_interval_set(cl->until_deletion, cl->disconnect_time);
1406 cl->until_deletion = ecore_timer_add(cl->disconnect_time, (Ecore_Task_Cb)_ecore_con_client_timer, cl);
1408 else if (cl->until_deletion)
1410 ecore_timer_del(cl->until_deletion);
1411 cl->until_deletion = NULL;
1416 if (cl->host_server->client_disconnect_time > 0)
1418 if (cl->until_deletion)
1419 ecore_timer_interval_set(cl->until_deletion, cl->host_server->client_disconnect_time);
1421 cl->until_deletion = ecore_timer_add(cl->host_server->client_disconnect_time, (Ecore_Task_Cb)_ecore_con_client_timer, cl);
1423 else if (cl->until_deletion)
1425 ecore_timer_del(cl->until_deletion);
1426 cl->until_deletion = NULL;
1432 _ecore_con_cb_tcp_listen(void *data,
1433 Ecore_Con_Info *net_info)
1435 Ecore_Con_Server *svr;
1437 const char *memerr = NULL;
1442 if (!net_info) /* error message has already been handled */
1445 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1446 net_info->info.ai_protocol);
1447 if (svr->fd < 0) goto error;
1448 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1449 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1453 if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, (const void *)&lin,
1454 sizeof(struct linger)) < 0)
1457 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY)
1459 #ifdef HAVE_NETINET_TCP_H
1462 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag,
1470 if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
1473 if (listen(svr->fd, 4096) < 0) goto error;
1475 svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
1476 _ecore_con_svr_tcp_handler, svr, NULL, NULL);
1477 if (!svr->fd_handler)
1479 memerr = "Memory allocation failure";
1486 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1487 ecore_con_ssl_server_shutdown(svr);
1488 _ecore_con_server_kill(svr);
1492 _ecore_con_cb_udp_listen(void *data,
1493 Ecore_Con_Info *net_info)
1495 Ecore_Con_Server *svr;
1496 Ecore_Con_Type type;
1497 struct ip_mreq mreq;
1499 struct ipv6_mreq mreq6;
1502 const char *memerr = NULL;
1506 type &= ECORE_CON_TYPE;
1509 if (!net_info) /* error message has already been handled */
1512 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1513 net_info->info.ai_protocol);
1514 if (svr->fd < 0) goto error;
1516 if (type == ECORE_CON_REMOTE_MCAST)
1518 if (net_info->info.ai_family == AF_INET)
1520 if (!inet_pton(net_info->info.ai_family, net_info->ip,
1521 &mreq.imr_multiaddr))
1524 mreq.imr_interface.s_addr = htonl(INADDR_ANY);
1525 if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
1526 (const void *)&mreq, sizeof(mreq)) != 0)
1530 else if (net_info->info.ai_family == AF_INET6)
1532 if (!inet_pton(net_info->info.ai_family, net_info->ip,
1533 &mreq6.ipv6mr_multiaddr))
1535 mreq6.ipv6mr_interface = htonl(INADDR_ANY);
1536 if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
1537 (const void *)&mreq6, sizeof(mreq6)) != 0)
1543 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof(on)) != 0)
1545 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1546 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1548 if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
1552 ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
1553 _ecore_con_svr_udp_handler, svr, NULL, NULL);
1554 if (!svr->fd_handler)
1556 memerr = "Memory allocation failure";
1560 svr->ip = eina_stringshare_add(net_info->ip);
1565 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1566 ecore_con_ssl_server_shutdown(svr);
1567 _ecore_con_server_kill(svr);
1571 _ecore_con_cb_tcp_connect(void *data,
1572 Ecore_Con_Info *net_info)
1574 Ecore_Con_Server *svr;
1577 const char *memerr = NULL;
1582 if (!net_info) /* error message has already been handled */
1585 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1586 net_info->info.ai_protocol);
1587 if (svr->fd < 0) goto error;
1589 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1590 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1592 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate, sizeof(curstate)) < 0)
1595 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY)
1597 #ifdef HAVE_NETINET_TCP_H
1600 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)) < 0)
1607 res = connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen);
1609 if (res == SOCKET_ERROR)
1611 if (WSAGetLastError() != WSAEINPROGRESS)
1614 err = evil_format_message(WSAGetLastError());
1615 _ecore_con_event_server_error(svr, err, EINA_FALSE);
1616 ecore_con_ssl_server_shutdown(svr);
1617 _ecore_con_server_kill(svr);
1624 if (errno != EINPROGRESS) goto error;
1626 svr->connecting = EINA_TRUE;
1628 ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE,
1629 _ecore_con_cl_handler, svr, NULL, NULL);
1632 svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
1633 _ecore_con_cl_handler, svr, NULL, NULL);
1635 if (svr->type & ECORE_CON_SSL)
1637 svr->handshaking = EINA_TRUE;
1638 svr->ssl_state = ECORE_CON_SSL_STATE_INIT;
1639 DBG("%s ssl handshake", svr->ecs_state ? "Queuing" : "Beginning");
1640 if ((!svr->ecs_state) && ecore_con_ssl_server_init(svr))
1644 if (!svr->fd_handler)
1646 memerr = "Memory allocation failure";
1650 if ((!svr->ecs) || (svr->ecs->lookup))
1651 svr->ip = eina_stringshare_add(net_info->ip);
1656 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1657 ecore_con_ssl_server_shutdown(svr);
1658 _ecore_con_server_kill(svr);
1662 _ecore_con_cb_udp_connect(void *data,
1663 Ecore_Con_Info *net_info)
1665 Ecore_Con_Server *svr;
1668 const char *memerr = NULL;
1672 if (!net_info) /* error message has already been handled */
1675 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1676 net_info->info.ai_protocol);
1677 if (svr->fd < 0) goto error;
1678 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1679 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1680 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_BROADCAST)
1682 if (setsockopt(svr->fd, SOL_SOCKET, SO_BROADCAST,
1683 (const void *)&broadcast,
1684 sizeof(broadcast)) < 0)
1689 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR,
1690 (const void *)&curstate, sizeof(curstate)) < 0)
1693 if (connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
1696 svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE,
1697 _ecore_con_cl_udp_handler, svr, NULL, NULL);
1699 if (!svr->fd_handler)
1701 memerr = "Memory allocation failure";
1705 if ((!svr->ecs) || (svr->ecs->lookup))
1706 svr->ip = eina_stringshare_add(net_info->ip);
1711 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1712 ecore_con_ssl_server_shutdown(svr);
1713 _ecore_con_server_kill(svr);
1716 static Ecore_Con_State
1717 svr_try_connect_plain(Ecore_Con_Server *svr)
1721 socklen_t size = sizeof(int);
1723 res = getsockopt(svr->fd, SOL_SOCKET, SO_ERROR, (void *)&so_err, &size);
1725 if (res == SOCKET_ERROR)
1726 so_err = WSAGetLastError();
1728 if ((so_err == WSAEINPROGRESS) && !svr->delete_me)
1729 return ECORE_CON_INPROGRESS;
1735 if ((so_err == EINPROGRESS) && !svr->delete_me)
1736 return ECORE_CON_INPROGRESS;
1742 /* we lost our server! */
1743 ecore_con_event_server_error(svr, strerror(so_err));
1744 ERR("Connection lost: %s", strerror(so_err));
1745 _ecore_con_server_kill(svr);
1746 return ECORE_CON_DISCONNECTED;
1749 if ((!svr->delete_me) && (!svr->handshaking) && svr->connecting)
1753 if (ecore_con_socks_svr_init(svr))
1754 return ECORE_CON_INPROGRESS;
1757 ecore_con_event_server_add(svr);
1760 if (svr->fd_handler && (!svr->buf))
1761 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
1763 if (!svr->delete_me)
1764 return ECORE_CON_CONNECTED;
1766 return ECORE_CON_DISCONNECTED;
1770 _ecore_con_pretty_ip(struct sockaddr *client_addr)
1773 char ipbuf[INET_ADDRSTRLEN + 1];
1775 char ipbuf[INET6_ADDRSTRLEN + 1];
1777 int family = client_addr->sa_family;
1783 src = &(((struct sockaddr_in *)client_addr)->sin_addr);
1787 src = &(((struct sockaddr_in6 *)client_addr)->sin6_addr);
1789 if (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)src))
1792 src = (char*)src + 12;
1797 return eina_stringshare_add("0.0.0.0");
1800 if (!inet_ntop(family, src, ipbuf, sizeof(ipbuf)))
1801 return eina_stringshare_add("0.0.0.0");
1803 ipbuf[sizeof(ipbuf) - 1] = 0;
1804 return eina_stringshare_add(ipbuf);
1808 _ecore_con_svr_tcp_handler(void *data,
1809 Ecore_Fd_Handler *fd_handler __UNUSED__)
1811 Ecore_Con_Server *svr;
1812 Ecore_Con_Client *cl = NULL;
1813 unsigned char client_addr[256];
1814 unsigned int client_addr_len;
1815 const char *clerr = NULL;
1819 return ECORE_CALLBACK_RENEW;
1822 return ECORE_CALLBACK_RENEW;
1824 if ((svr->client_limit >= 0) && (!svr->reject_excess_clients) &&
1825 (svr->client_count >= (unsigned int)svr->client_limit))
1826 return ECORE_CALLBACK_RENEW;
1830 cl = calloc(1, sizeof(Ecore_Con_Client));
1833 ecore_con_event_server_error(svr, "Memory allocation failure when attempting to add a new client");
1834 return ECORE_CALLBACK_RENEW;
1836 cl->host_server = svr;
1838 client_addr_len = sizeof(client_addr);
1839 memset(&client_addr, 0, client_addr_len);
1840 cl->fd = accept(svr->fd, (struct sockaddr *)&client_addr, (socklen_t *)&client_addr_len);
1841 if (cl->fd < 0) goto error;
1842 if ((svr->client_limit >= 0) && (svr->reject_excess_clients) &&
1843 (svr->client_count >= (unsigned int)svr->client_limit))
1845 clerr = "Maximum client limit reached";
1849 if (fcntl(cl->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1850 if (fcntl(cl->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1851 cl->fd_handler = ecore_main_fd_handler_add(cl->fd, ECORE_FD_READ,
1852 _ecore_con_svr_cl_handler, cl, NULL, NULL);
1853 if (!cl->fd_handler) goto error;
1854 ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
1856 if ((!svr->upgrade) && (svr->type & ECORE_CON_SSL))
1858 cl->handshaking = EINA_TRUE;
1859 cl->ssl_state = ECORE_CON_SSL_STATE_INIT;
1860 if (ecore_con_ssl_client_init(cl))
1864 cl->client_addr = malloc(client_addr_len);
1865 if (!cl->client_addr)
1867 clerr = "Memory allocation failure when attempting to add a new client";
1870 cl->client_addr_len = client_addr_len;
1871 memcpy(cl->client_addr, &client_addr, client_addr_len);
1873 svr->clients = eina_list_append(svr->clients, cl);
1874 svr->client_count++;
1876 if ((!cl->delete_me) && (!cl->handshaking))
1877 ecore_con_event_client_add(cl);
1879 return ECORE_CALLBACK_RENEW;
1882 if (cl->fd_handler) ecore_main_fd_handler_del(cl->fd_handler);
1883 if (cl->fd >= 0) close(cl->fd);
1885 if (clerr || errno) ecore_con_event_server_error(svr, clerr ?: strerror(errno));
1886 return ECORE_CALLBACK_RENEW;
1890 _ecore_con_cl_read(Ecore_Con_Server *svr)
1893 Eina_Bool lost_server = EINA_TRUE;
1894 unsigned char buf[READBUFSIZ];
1898 /* only possible with non-ssl connections */
1899 if (svr->connecting && (svr_try_connect_plain(svr) != ECORE_CON_CONNECTED))
1902 if (svr->handshaking && (!svr->ecs_state))
1904 DBG("Continuing ssl handshake");
1905 if (!ecore_con_ssl_server_init(svr))
1906 lost_server = EINA_FALSE;
1907 _ecore_con_server_timer_update(svr);
1910 if (svr->ecs_state || !(svr->type & ECORE_CON_SSL))
1913 num = read(svr->fd, buf, sizeof(buf));
1914 /* 0 is not a valid return value for a tcp socket */
1915 if ((num > 0) || ((num < 0) && (errno == EAGAIN)))
1916 lost_server = EINA_FALSE;
1918 ecore_con_event_server_error(svr, strerror(errno));
1922 num = ecore_con_ssl_server_read(svr, buf, sizeof(buf));
1923 /* this is not an actual 0 return, 0 here just means non-fatal error such as EAGAIN */
1925 lost_server = EINA_FALSE;
1928 if ((!svr->delete_me) && (num > 0))
1931 ecore_con_socks_read(svr, buf, num);
1933 ecore_con_event_server_data(svr, buf, num, EINA_TRUE);
1937 _ecore_con_server_kill(svr);
1941 _ecore_con_cl_handler(void *data,
1942 Ecore_Fd_Handler *fd_handler)
1944 Ecore_Con_Server *svr;
1945 Eina_Bool want_read, want_write;
1949 return ECORE_CALLBACK_RENEW;
1952 return ECORE_CALLBACK_RENEW;
1954 want_read = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ);
1955 want_write = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE);
1957 if ((!svr->ecs_state) && svr->handshaking && (want_read || want_write))
1959 DBG("Continuing ssl handshake: preparing to %s...", want_read ? "read" : "write");
1963 char buf[READBUFSIZ];
1965 len = recv(svr->fd, buf, sizeof(buf), MSG_DONTWAIT | MSG_PEEK);
1966 DBG("%zu bytes in buffer", len);
1969 if (ecore_con_ssl_server_init(svr))
1971 ERR("ssl handshaking failed!");
1972 svr->handshaking = EINA_FALSE;
1974 else if (!svr->ssl_state)
1975 ecore_con_event_server_add(svr);
1976 return ECORE_CALLBACK_RENEW;
1978 if (svr->ecs && svr->ecs_state && (svr->ecs_state < ECORE_CON_PROXY_STATE_READ) && (!svr->ecs_buf))
1980 if (svr->ecs_state < ECORE_CON_PROXY_STATE_INIT)
1982 INF("PROXY STATE++");
1985 if (ecore_con_socks_svr_init(svr)) return ECORE_CALLBACK_RENEW;
1988 _ecore_con_cl_read(svr);
1989 else if (want_write) /* only possible with non-ssl connections */
1991 if (svr->connecting && (!svr_try_connect_plain(svr)) && (!svr->ecs_state))
1992 return ECORE_CALLBACK_RENEW;
1994 _ecore_con_server_flush(svr);
1997 return ECORE_CALLBACK_RENEW;
2001 _ecore_con_cl_udp_handler(void *data,
2002 Ecore_Fd_Handler *fd_handler)
2004 unsigned char buf[READBUFSIZ];
2006 Ecore_Con_Server *svr;
2007 Eina_Bool want_read, want_write;
2009 want_read = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ);
2010 want_write = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE);
2013 if (svr->delete_me || svr->delete_me || ((!want_read) && (!want_write)))
2014 return ECORE_CALLBACK_RENEW;
2018 _ecore_con_server_flush(svr);
2019 return ECORE_CALLBACK_RENEW;
2022 num = read(svr->fd, buf, READBUFSIZ);
2024 if ((!svr->delete_me) && (num > 0))
2025 ecore_con_event_server_data(svr, buf, num, EINA_TRUE);
2027 if (num < 0 && (errno != EAGAIN) && (errno != EINTR))
2029 ecore_con_event_server_error(svr, strerror(errno));
2030 _ecore_con_server_kill(svr);
2033 return ECORE_CALLBACK_RENEW;
2037 _ecore_con_svr_udp_handler(void *data,
2038 Ecore_Fd_Handler *fd_handler)
2040 unsigned char buf[READBUFSIZ];
2041 unsigned char client_addr[256];
2042 socklen_t client_addr_len = sizeof(client_addr);
2044 Ecore_Con_Server *svr;
2045 Ecore_Con_Client *cl = NULL;
2050 return ECORE_CALLBACK_RENEW;
2052 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
2054 _ecore_con_client_flush(cl);
2055 return ECORE_CALLBACK_RENEW;
2058 if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
2059 return ECORE_CALLBACK_RENEW;
2062 num = fcntl(svr->fd, F_SETFL, O_NONBLOCK);
2064 num = recvfrom(svr->fd, (char *)buf, sizeof(buf), 0,
2065 (struct sockaddr *)&client_addr,
2069 num = recvfrom(svr->fd, buf, sizeof(buf), MSG_DONTWAIT,
2070 (struct sockaddr *)&client_addr,
2074 if (num < 0 && (errno != EAGAIN) && (errno != EINTR))
2076 ecore_con_event_server_error(svr, strerror(errno));
2077 if (!svr->delete_me)
2078 ecore_con_event_client_del(NULL);
2079 _ecore_con_server_kill(svr);
2080 return ECORE_CALLBACK_CANCEL;
2084 /* Create a new client for use in the client data event */
2085 cl = calloc(1, sizeof(Ecore_Con_Client));
2086 EINA_SAFETY_ON_NULL_RETURN_VAL(cl, ECORE_CALLBACK_RENEW);
2088 cl->host_server = svr;
2089 cl->client_addr = malloc(client_addr_len);
2090 if (!cl->client_addr)
2093 return ECORE_CALLBACK_RENEW;
2095 cl->client_addr_len = client_addr_len;
2097 memcpy(cl->client_addr, &client_addr, client_addr_len);
2098 ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
2099 svr->clients = eina_list_append(svr->clients, cl);
2100 svr->client_count++;
2102 ecore_con_event_client_add(cl);
2103 ecore_con_event_client_data(cl, buf, num, EINA_TRUE);
2105 return ECORE_CALLBACK_RENEW;
2109 _ecore_con_svr_cl_read(Ecore_Con_Client *cl)
2112 Eina_Bool lost_client = EINA_TRUE;
2113 unsigned char buf[READBUFSIZ];
2117 if (cl->handshaking)
2119 /* add an extra handshake attempt just before read, even though
2120 * read also attempts to handshake, to try to finish sooner
2122 if (ecore_con_ssl_client_init(cl))
2123 lost_client = EINA_FALSE;
2125 _ecore_con_cl_timer_update(cl);
2128 if (!(cl->host_server->type & ECORE_CON_SSL) || (!cl->upgrade))
2130 num = read(cl->fd, buf, sizeof(buf));
2131 /* 0 is not a valid return value for a tcp socket */
2132 if ((num > 0) || ((num < 0) && ((errno == EAGAIN) || (errno == EINTR))))
2133 lost_client = EINA_FALSE;
2135 ecore_con_event_client_error(cl, strerror(errno));
2139 num = ecore_con_ssl_client_read(cl, buf, sizeof(buf));
2140 /* this is not an actual 0 return, 0 here just means non-fatal error such as EAGAIN */
2142 lost_client = EINA_FALSE;
2145 if ((!cl->delete_me) && (num > 0))
2146 ecore_con_event_client_data(cl, buf, num, EINA_TRUE);
2148 if (lost_client) _ecore_con_client_kill(cl);
2152 _ecore_con_svr_cl_handler(void *data,
2153 Ecore_Fd_Handler *fd_handler)
2155 Ecore_Con_Client *cl;
2159 return ECORE_CALLBACK_RENEW;
2161 if (cl->handshaking && ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ | ECORE_FD_WRITE))
2163 if (ecore_con_ssl_client_init(cl))
2165 ERR("ssl handshaking failed!");
2166 _ecore_con_client_kill(cl);
2167 return ECORE_CALLBACK_RENEW;
2169 else if (!cl->ssl_state)
2170 ecore_con_event_client_add(cl);
2172 else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
2173 _ecore_con_svr_cl_read(cl);
2175 else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
2176 _ecore_con_client_flush(cl);
2178 return ECORE_CALLBACK_RENEW;
2182 _ecore_con_server_flush(Ecore_Con_Server *svr)
2185 size_t buf_len, buf_offset;
2188 DBG("(svr=%p,buf=%p)", svr, svr->buf);
2190 if (ecore_con_local_win32_server_flush(svr))
2194 if ((!svr->buf) && (!svr->ecs_buf) && svr->fd_handler)
2196 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
2200 buf = svr->buf ? eina_binbuf_string_get(svr->buf) : eina_binbuf_string_get(svr->ecs_buf);
2201 buf_len = svr->buf ? eina_binbuf_length_get(svr->buf) : eina_binbuf_length_get(svr->ecs_buf);
2202 buf_offset = svr->buf ? svr->write_buf_offset : svr->ecs_buf_offset;
2203 num = buf_len - buf_offset;
2205 /* check whether we need to write anything at all.
2206 * we must not write zero bytes with SSL_write() since it
2207 * causes undefined behaviour
2209 /* we thank Tommy[D] for needing to check negative buffer sizes
2210 * here because his system is amazing.
2212 if (num <= 0) return;
2214 if ((!svr->ecs_state) && svr->handshaking)
2216 DBG("Continuing ssl handshake");
2217 if (ecore_con_ssl_server_init(svr))
2218 _ecore_con_server_kill(svr);
2219 _ecore_con_server_timer_update(svr);
2223 if (svr->ecs_state || (!(svr->type & ECORE_CON_SSL)))
2224 count = write(svr->fd, buf + buf_offset, num);
2226 count = ecore_con_ssl_server_write(svr, buf + buf_offset, num);
2230 if ((errno != EAGAIN) && (errno != EINTR))
2232 ecore_con_event_server_error(svr, strerror(errno));
2233 _ecore_con_server_kill(svr);
2238 if (count && (!svr->ecs_state)) ecore_con_event_server_write(svr, count);
2240 buf_offset = svr->ecs_buf_offset += count;
2242 buf_offset = svr->write_buf_offset += count;
2243 if (buf_offset >= buf_len)
2247 svr->ecs_buf_offset = 0;
2248 eina_binbuf_free(svr->ecs_buf);
2249 svr->ecs_buf = NULL;
2250 INF("PROXY STATE++");
2255 svr->write_buf_offset = 0;
2256 eina_binbuf_free(svr->buf);
2259 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK)
2262 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
2263 /* realistically this isn't anything serious so we can just log and continue */
2264 ERR("uncorking failed! %s", strerror(errno));
2268 if (svr->fd_handler)
2269 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
2271 else if ((count < num) && svr->fd_handler)
2272 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE);
2276 _ecore_con_client_flush(Ecore_Con_Client *cl)
2278 int num = 0, count = 0;
2281 if (ecore_con_local_win32_client_flush(cl))
2285 if (!cl->buf && cl->fd_handler)
2287 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ);
2291 if (cl->handshaking)
2293 if (ecore_con_ssl_client_init(cl))
2296 _ecore_con_cl_timer_update(cl);
2301 num = eina_binbuf_length_get(cl->buf) - cl->buf_offset;
2302 if (num <= 0) return;
2303 if (!(cl->host_server->type & ECORE_CON_SSL) || (!cl->upgrade))
2304 count = write(cl->fd, eina_binbuf_string_get(cl->buf) + cl->buf_offset, num);
2306 count = ecore_con_ssl_client_write(cl, eina_binbuf_string_get(cl->buf) + cl->buf_offset, num);
2311 if ((errno != EAGAIN) && (errno != EINTR) && (!cl->delete_me))
2313 ecore_con_event_client_error(cl, strerror(errno));
2314 _ecore_con_client_kill(cl);
2320 if (count) ecore_con_event_client_write(cl, count);
2321 cl->buf_offset += count, num -= count;
2322 if (cl->buf_offset >= eina_binbuf_length_get(cl->buf))
2325 eina_binbuf_free(cl->buf);
2328 if ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK)
2331 if (setsockopt(cl->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
2332 /* realistically this isn't anything serious so we can just log and continue */
2333 ERR("uncorking failed! %s", strerror(errno));
2337 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ);
2339 else if (cl->fd_handler && (num >= 0))
2340 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_WRITE);
2344 _ecore_con_event_client_add_free(Ecore_Con_Server *svr,
2347 Ecore_Con_Event_Client_Add *e;
2352 e->client->event_count = eina_list_remove(e->client->event_count, e);
2353 if (e->client->host_server)
2355 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, ev);
2356 if ((!svr->event_count) && (svr->delete_me))
2357 _ecore_con_server_free(svr);
2359 if ((!e->client->event_count) && (e->client->delete_me))
2360 ecore_con_client_del(e->client);
2363 ecore_con_event_client_add_free(e);
2364 _ecore_con_event_count--;
2365 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2366 ecore_con_mempool_shutdown();
2370 _ecore_con_event_client_del_free(Ecore_Con_Server *svr,
2373 Ecore_Con_Event_Client_Del *e;
2378 e->client->event_count = eina_list_remove(e->client->event_count, e);
2379 if (e->client->host_server)
2381 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, ev);
2382 if ((!svr->event_count) && (svr->delete_me))
2383 _ecore_con_server_free(svr);
2385 if (!e->client->event_count)
2386 _ecore_con_client_free(e->client);
2388 ecore_con_event_client_del_free(e);
2389 _ecore_con_event_count--;
2390 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2391 ecore_con_mempool_shutdown();
2395 _ecore_con_event_client_write_free(Ecore_Con_Server *svr,
2396 Ecore_Con_Event_Client_Write *e)
2400 e->client->event_count = eina_list_remove(e->client->event_count, e);
2401 if (e->client->host_server)
2403 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, e);
2404 if ((!svr->event_count) && (svr->delete_me))
2405 _ecore_con_server_free(svr);
2407 if (((!e->client->event_count) && (e->client->delete_me)) ||
2408 ((e->client->host_server &&
2409 ((e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP ||
2410 (e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_MCAST))))
2411 ecore_con_client_del(e->client);
2413 ecore_con_event_client_write_free(e);
2414 _ecore_con_event_count--;
2415 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2416 ecore_con_mempool_shutdown();
2420 _ecore_con_event_client_data_free(Ecore_Con_Server *svr,
2423 Ecore_Con_Event_Client_Data *e;
2428 e->client->event_count = eina_list_remove(e->client->event_count, e);
2429 if (e->client->host_server)
2431 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, ev);
2433 if ((!svr->event_count) && (svr->delete_me))
2434 _ecore_con_server_free(svr);
2435 if (((!e->client->event_count) && (e->client->delete_me)) ||
2436 ((e->client->host_server &&
2437 ((e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP ||
2438 (e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_MCAST))))
2439 ecore_con_client_del(e->client);
2442 ecore_con_event_client_data_free(e);
2443 _ecore_con_event_count--;
2444 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2445 ecore_con_mempool_shutdown();
2449 _ecore_con_event_server_add_free(void *data __UNUSED__,
2452 Ecore_Con_Event_Server_Add *e;
2457 e->server->event_count = eina_list_remove(e->server->event_count, ev);
2458 if ((!e->server->event_count) && (e->server->delete_me))
2459 _ecore_con_server_free(e->server);
2461 ecore_con_event_server_add_free(e);
2462 _ecore_con_event_count--;
2463 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2464 ecore_con_mempool_shutdown();
2468 _ecore_con_event_server_del_free(void *data __UNUSED__,
2471 Ecore_Con_Event_Server_Del *e;
2476 e->server->event_count = eina_list_remove(e->server->event_count, ev);
2477 if (!e->server->event_count)
2478 _ecore_con_server_free(e->server);
2480 ecore_con_event_server_del_free(e);
2481 _ecore_con_event_count--;
2482 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2483 ecore_con_mempool_shutdown();
2487 _ecore_con_event_server_write_free(void *data __UNUSED__,
2488 Ecore_Con_Event_Server_Write *e)
2492 e->server->event_count = eina_list_remove(e->server->event_count, e);
2493 if ((!e->server->event_count) && (e->server->delete_me))
2494 _ecore_con_server_free(e->server);
2497 ecore_con_event_server_write_free(e);
2498 _ecore_con_event_count--;
2499 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2500 ecore_con_mempool_shutdown();
2504 _ecore_con_event_server_data_free(void *data __UNUSED__,
2507 Ecore_Con_Event_Server_Data *e;
2512 e->server->event_count = eina_list_remove(e->server->event_count, ev);
2513 if ((!e->server->event_count) && (e->server->delete_me))
2514 _ecore_con_server_free(e->server);
2518 ecore_con_event_server_data_free(e);
2519 _ecore_con_event_count--;
2520 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2521 ecore_con_mempool_shutdown();
2526 _ecore_con_event_server_error_free(void *data __UNUSED__, Ecore_Con_Event_Server_Error *e)
2530 e->server->event_count = eina_list_remove(e->server->event_count, e);
2531 if ((!e->server->event_count) && (e->server->delete_me))
2532 _ecore_con_server_free(e->server);
2535 ecore_con_event_server_error_free(e);
2536 _ecore_con_event_count--;
2537 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2538 ecore_con_mempool_shutdown();
2542 _ecore_con_event_client_error_free(Ecore_Con_Server *svr, Ecore_Con_Event_Client_Error *e)
2546 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, e);
2547 if ((!e->client->event_count) && (e->client->delete_me))
2548 _ecore_con_client_free(e->client);
2549 if (e->client->host_server)
2551 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, e);
2552 if ((!svr->event_count) && (svr->delete_me))
2553 _ecore_con_server_free(svr);
2557 ecore_con_event_client_error_free(e);
2558 _ecore_con_event_count--;
2559 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2560 ecore_con_mempool_shutdown();
2564 _ecore_con_lookup_done(void *data,
2565 Ecore_Con_Info *infos)
2567 Ecore_Con_Server *svr;
2568 Ecore_Con_Lookup *lk;
2574 lk->done_cb(infos->info.ai_canonname, infos->ip,
2575 infos->info.ai_addr, infos->info.ai_addrlen,
2578 lk->done_cb(NULL, NULL, NULL, 0, (void *)lk->data);