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_Client");
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->disable_proxy = (compl_type & ECORE_CON_SUPER_SSL & ECORE_CON_NO_PROXY) == ECORE_CON_NO_PROXY;
448 svr->reject_excess_clients = EINA_FALSE;
450 svr->client_limit = -1;
452 type = compl_type & ECORE_CON_TYPE;
454 if ((!svr->disable_proxy) && (type > ECORE_CON_LOCAL_ABSTRACT))
456 /* never use proxies on local connections */
457 if (_ecore_con_proxy_once)
458 svr->ecs = _ecore_con_proxy_once;
459 else if (_ecore_con_proxy_global)
460 svr->ecs = _ecore_con_proxy_global;
461 _ecore_con_proxy_once = NULL;
464 if ((!svr->ecs->lookup) &&
465 (!ecore_con_lookup(svr->name, (Ecore_Con_Dns_Cb)ecore_con_socks_dns_cb, svr)))
467 if (svr->ecs->lookup)
468 svr->ecs_state = ECORE_CON_PROXY_STATE_RESOLVED;
471 EINA_SAFETY_ON_TRUE_GOTO(ecore_con_ssl_server_prepare(svr, compl_type & ECORE_CON_SSL), error);
473 EINA_SAFETY_ON_TRUE_GOTO(((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)) &&
480 if ((type == ECORE_CON_LOCAL_USER) ||
481 (type == ECORE_CON_LOCAL_SYSTEM) ||
482 (type == ECORE_CON_LOCAL_ABSTRACT))
485 EINA_SAFETY_ON_FALSE_GOTO(ecore_con_local_connect(svr, _ecore_con_cl_handler), error);
487 EINA_SAFETY_ON_FALSE_GOTO(ecore_con_local_connect(svr, _ecore_con_cl_handler, svr), error);
490 if ((type == ECORE_CON_REMOTE_TCP) ||
491 (type == ECORE_CON_REMOTE_NODELAY) ||
492 (type == ECORE_CON_REMOTE_CORK))
495 EINA_SAFETY_ON_FALSE_GOTO(ecore_con_info_tcp_connect(svr, _ecore_con_cb_tcp_connect, svr), error);
497 else if ((type == ECORE_CON_REMOTE_UDP) || (type == ECORE_CON_REMOTE_BROADCAST))
499 EINA_SAFETY_ON_FALSE_GOTO(ecore_con_info_udp_connect(svr, _ecore_con_cb_udp_connect, svr), error);
501 servers = eina_list_append(servers, svr);
502 ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER);
514 ecore_main_fd_handler_del(svr->fd_handler);
519 ecore_con_ssl_server_shutdown(svr);
525 ecore_con_server_timeout_set(Ecore_Con_Server *svr,
528 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
530 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_timeout_set");
535 svr->client_disconnect_time = timeout;
537 svr->disconnect_time = timeout;
541 ecore_con_server_timeout_get(Ecore_Con_Server *svr)
543 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
545 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_timeout_get");
549 return svr->created ? svr->client_disconnect_time : svr->disconnect_time;
553 ecore_con_server_del(Ecore_Con_Server *svr)
555 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
557 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_del");
564 _ecore_con_server_kill(svr);
569 ecore_con_server_data_get(Ecore_Con_Server *svr)
571 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
573 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_data_get");
581 ecore_con_server_data_set(Ecore_Con_Server *svr,
586 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
588 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_data_get");
598 ecore_con_server_connected_get(Ecore_Con_Server *svr)
600 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
602 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_connected_get");
612 EAPI const Eina_List *
613 ecore_con_server_clients_get(Ecore_Con_Server *svr)
615 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
617 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
618 "ecore_con_server_clients_get");
626 ecore_con_server_name_get(Ecore_Con_Server *svr)
628 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
630 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
631 "ecore_con_server_name_get");
639 ecore_con_server_port_get(Ecore_Con_Server *svr)
641 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
643 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
644 "ecore_con_server_port_get");
651 ecore_con_server_send(Ecore_Con_Server *svr,
655 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
657 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_send");
661 EINA_SAFETY_ON_TRUE_RETURN_VAL(svr->delete_me, 0);
663 EINA_SAFETY_ON_NULL_RETURN_VAL(data, 0);
665 EINA_SAFETY_ON_TRUE_RETURN_VAL(size < 1, 0);
668 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE);
672 svr->buf = eina_binbuf_new();
673 EINA_SAFETY_ON_NULL_RETURN_VAL(svr->buf, 0);
675 if ((svr->fd >= 0) && ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK))
678 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
679 /* realistically this isn't anything serious so we can just log and continue */
680 ERR("corking failed! %s", strerror(errno));
684 eina_binbuf_append_length(svr->buf, data, size);
690 ecore_con_server_client_limit_set(Ecore_Con_Server *svr,
692 char reject_excess_clients)
694 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
696 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
697 "ecore_con_server_client_limit_set");
701 svr->client_limit = client_limit;
702 svr->reject_excess_clients = reject_excess_clients;
706 ecore_con_server_ip_get(Ecore_Con_Server *svr)
708 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
710 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_ip_get");
718 ecore_con_server_uptime_get(Ecore_Con_Server *svr)
720 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
722 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_uptime_get");
726 return ecore_time_get() - svr->start_time;
730 ecore_con_server_flush(Ecore_Con_Server *svr)
732 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
734 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_flush");
738 _ecore_con_server_flush(svr);
746 * @addtogroup Ecore_Con_Client_Group Ecore Connection Client Functions
748 * Functions that operate on Ecore connection client objects.
754 * @example ecore_con_client_example.c
755 * Shows how to write a simple client that connects to the example server.
759 ecore_con_client_send(Ecore_Con_Client *cl,
763 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
765 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_send");
769 EINA_SAFETY_ON_TRUE_RETURN_VAL(cl->delete_me, 0);
771 EINA_SAFETY_ON_NULL_RETURN_VAL(data, 0);
773 EINA_SAFETY_ON_TRUE_RETURN_VAL(size < 1, 0);
776 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE);
778 if (cl->host_server && ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP))
779 sendto(cl->host_server->fd, data, size, 0, (struct sockaddr *)cl->client_addr,
780 cl->client_addr_len);
783 cl->buf = eina_binbuf_new();
784 EINA_SAFETY_ON_NULL_RETURN_VAL(cl->buf, 0);
786 if ((cl->fd >= 0) && ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK))
789 if (setsockopt(cl->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
790 /* realistically this isn't anything serious so we can just log and continue */
791 ERR("corking failed! %s", strerror(errno));
795 eina_binbuf_append_length(cl->buf, data, size);
800 EAPI Ecore_Con_Server *
801 ecore_con_client_server_get(Ecore_Con_Client *cl)
803 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
805 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
806 "ecore_con_client_server_get");
810 return cl->host_server;
814 ecore_con_client_connected_get(Ecore_Con_Client *cl)
816 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
818 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
819 "ecore_con_client_connected_get");
823 return !cl->delete_me;
827 ecore_con_client_timeout_set(Ecore_Con_Client *cl,
830 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
832 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
833 "ecore_con_client_timeout_set");
837 cl->disconnect_time = timeout;
839 _ecore_con_cl_timer_update(cl);
843 ecore_con_client_timeout_get(Ecore_Con_Client *cl)
845 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
847 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_timeout_get");
851 return cl->disconnect_time;
855 ecore_con_client_del(Ecore_Con_Client *cl)
857 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
859 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_del");
863 _ecore_con_client_kill(cl);
868 ecore_con_client_data_set(Ecore_Con_Client *cl,
871 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
873 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_data_set");
877 cl->data = (void *)data;
881 ecore_con_client_data_get(Ecore_Con_Client *cl)
883 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
885 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_data_get");
893 ecore_con_client_ip_get(Ecore_Con_Client *cl)
895 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
897 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_ip_get");
901 cl->ip = _ecore_con_pretty_ip(cl->client_addr);
907 ecore_con_client_port_get(Ecore_Con_Client *cl)
909 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
911 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_port_get");
914 if (cl->client_addr->sa_family == AF_INET)
915 return ((struct sockaddr_in*)cl->client_addr)->sin_port;
917 return ((struct sockaddr_in6*)cl->client_addr)->sin6_port;
924 ecore_con_client_uptime_get(Ecore_Con_Client *cl)
926 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
928 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_uptime_get");
932 return ecore_time_get() - cl->start_time;
936 ecore_con_client_flush(Ecore_Con_Client *cl)
938 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
940 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_flush");
944 _ecore_con_client_flush(cl);
948 ecore_con_server_fd_get(Ecore_Con_Server *svr)
950 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
952 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, __func__);
955 if (svr->created) return -1;
956 return ecore_main_fd_handler_fd_get(svr->fd_handler);
960 ecore_con_client_fd_get(Ecore_Con_Client *cl)
962 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
964 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, __func__);
967 return ecore_main_fd_handler_fd_get(cl->fd_handler);
975 ecore_con_event_proxy_bind(Ecore_Con_Server *svr)
977 Ecore_Con_Event_Proxy_Bind *e;
978 int ev = ECORE_CON_EVENT_PROXY_BIND;
980 e = ecore_con_event_proxy_bind_alloc();
981 EINA_SAFETY_ON_NULL_RETURN(e);
983 svr->event_count = eina_list_append(svr->event_count, e);
984 _ecore_con_server_timer_update(svr);
986 e->ip = svr->proxyip;
987 e->port = svr->proxyport;
988 ecore_event_add(ev, e,
989 _ecore_con_event_server_add_free, NULL);
990 _ecore_con_event_count++;
994 ecore_con_event_server_add(Ecore_Con_Server *svr)
996 /* we got our server! */
997 Ecore_Con_Event_Server_Add *e;
998 int ev = ECORE_CON_EVENT_SERVER_ADD;
1000 e = ecore_con_event_server_add_alloc();
1001 EINA_SAFETY_ON_NULL_RETURN(e);
1003 svr->connecting = EINA_FALSE;
1004 svr->start_time = ecore_time_get();
1005 svr->event_count = eina_list_append(svr->event_count, e);
1006 _ecore_con_server_timer_update(svr);
1008 if (svr->upgrade) ev = ECORE_CON_EVENT_SERVER_UPGRADE;
1009 ecore_event_add(ev, e,
1010 _ecore_con_event_server_add_free, NULL);
1011 _ecore_con_event_count++;
1015 ecore_con_event_server_del(Ecore_Con_Server *svr)
1017 Ecore_Con_Event_Server_Del *e;
1019 svr->delete_me = EINA_TRUE;
1020 INF("svr %p is dead", svr);
1021 e = ecore_con_event_server_del_alloc();
1022 EINA_SAFETY_ON_NULL_RETURN(e);
1024 svr->event_count = eina_list_append(svr->event_count, e);
1025 _ecore_con_server_timer_update(svr);
1029 svr->ecs_state = svr->ecs->lookup ? ECORE_CON_PROXY_STATE_RESOLVED : ECORE_CON_PROXY_STATE_DONE;
1030 eina_stringshare_replace(&svr->proxyip, NULL);
1033 ecore_event_add(ECORE_CON_EVENT_SERVER_DEL, e,
1034 _ecore_con_event_server_del_free, NULL);
1035 _ecore_con_event_count++;
1039 ecore_con_event_server_write(Ecore_Con_Server *svr, int num)
1041 Ecore_Con_Event_Server_Write *e;
1043 e = ecore_con_event_server_write_alloc();
1044 EINA_SAFETY_ON_NULL_RETURN(e);
1046 INF("Wrote %d bytes", num);
1047 svr->event_count = eina_list_append(svr->event_count, e);
1050 ecore_event_add(ECORE_CON_EVENT_SERVER_WRITE, e,
1051 (Ecore_End_Cb)_ecore_con_event_server_write_free, NULL);
1052 _ecore_con_event_count++;
1056 ecore_con_event_server_data(Ecore_Con_Server *svr, unsigned char *buf, int num, Eina_Bool duplicate)
1058 Ecore_Con_Event_Server_Data *e;
1060 e = ecore_con_event_server_data_alloc();
1061 EINA_SAFETY_ON_NULL_RETURN(e);
1063 svr->event_count = eina_list_append(svr->event_count, e);
1064 _ecore_con_server_timer_update(svr);
1068 e->data = malloc(num);
1071 ERR("server data allocation failure !");
1072 _ecore_con_event_server_data_free(NULL, e);
1075 memcpy(e->data, buf, num);
1080 ecore_event_add(ECORE_CON_EVENT_SERVER_DATA, e,
1081 _ecore_con_event_server_data_free, NULL);
1082 _ecore_con_event_count++;
1086 ecore_con_event_client_add(Ecore_Con_Client *cl)
1088 Ecore_Con_Event_Client_Add *e;
1089 int ev = ECORE_CON_EVENT_CLIENT_ADD;
1091 e = ecore_con_event_client_add_alloc();
1092 EINA_SAFETY_ON_NULL_RETURN(e);
1094 cl->event_count = eina_list_append(cl->event_count, e);
1095 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1096 _ecore_con_cl_timer_update(cl);
1098 if (cl->upgrade) ev = ECORE_CON_EVENT_CLIENT_UPGRADE;
1099 ecore_event_add(ev, e,
1100 (Ecore_End_Cb)_ecore_con_event_client_add_free, cl->host_server);
1101 _ecore_con_event_count++;
1105 ecore_con_event_client_del(Ecore_Con_Client *cl)
1107 Ecore_Con_Event_Client_Del *e;
1110 cl->delete_me = EINA_TRUE;
1111 INF("cl %p is dead", cl);
1112 e = ecore_con_event_client_del_alloc();
1113 EINA_SAFETY_ON_NULL_RETURN(e);
1114 cl->event_count = eina_list_append(cl->event_count, e);
1116 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1117 _ecore_con_cl_timer_update(cl);
1119 ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
1120 (Ecore_End_Cb)_ecore_con_event_client_del_free, cl->host_server);
1121 _ecore_con_event_count++;
1125 ecore_con_event_client_write(Ecore_Con_Client *cl, int num)
1127 Ecore_Con_Event_Client_Write *e;
1129 e = ecore_con_event_client_write_alloc();
1130 EINA_SAFETY_ON_NULL_RETURN(e);
1132 cl->event_count = eina_list_append(cl->event_count, e);
1133 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1136 ecore_event_add(ECORE_CON_EVENT_CLIENT_WRITE, e,
1137 (Ecore_End_Cb)_ecore_con_event_client_write_free, cl->host_server);
1138 _ecore_con_event_count++;
1142 ecore_con_event_client_data(Ecore_Con_Client *cl, unsigned char *buf, int num, Eina_Bool duplicate)
1144 Ecore_Con_Event_Client_Data *e;
1146 e = ecore_con_event_client_data_alloc();
1147 EINA_SAFETY_ON_NULL_RETURN(e);
1149 cl->event_count = eina_list_append(cl->event_count, e);
1150 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1151 _ecore_con_cl_timer_update(cl);
1155 e->data = malloc(num);
1158 ERR("client data allocation failure !");
1159 _ecore_con_event_client_data_free(cl->host_server, e);
1162 memcpy(e->data, buf, num);
1167 ecore_event_add(ECORE_CON_EVENT_CLIENT_DATA, e,
1168 (Ecore_End_Cb)_ecore_con_event_client_data_free, cl->host_server);
1169 _ecore_con_event_count++;
1174 ecore_con_server_infos_del(Ecore_Con_Server *svr, void *info)
1176 svr->infos = eina_list_remove(svr->infos, info);
1180 _ecore_con_event_server_error(Ecore_Con_Server *svr, char *error, Eina_Bool duplicate)
1182 Ecore_Con_Event_Server_Error *e;
1184 e = ecore_con_event_server_error_alloc();
1185 EINA_SAFETY_ON_NULL_RETURN(e);
1188 e->error = duplicate ? strdup(error) : error;
1190 svr->event_count = eina_list_append(svr->event_count, e);
1191 ecore_event_add(ECORE_CON_EVENT_SERVER_ERROR, e, (Ecore_End_Cb)_ecore_con_event_server_error_free, NULL);
1192 _ecore_con_event_count++;
1196 ecore_con_event_client_error(Ecore_Con_Client *cl, const char *error)
1198 Ecore_Con_Event_Client_Error *e;
1200 e = ecore_con_event_client_error_alloc();
1201 EINA_SAFETY_ON_NULL_RETURN(e);
1204 e->error = strdup(error);
1206 cl->event_count = eina_list_append(cl->event_count, e);
1207 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1208 ecore_event_add(ECORE_CON_EVENT_CLIENT_ERROR, e, (Ecore_End_Cb)_ecore_con_event_client_error_free, cl->host_server);
1209 _ecore_con_event_count++;
1213 _ecore_con_server_free(Ecore_Con_Server *svr)
1215 Ecore_Con_Client *cl;
1218 if (svr->event_count) return;
1222 ecore_con_info_data_clear(svr->infos->data);
1223 svr->infos = eina_list_remove_list(svr->infos, svr->infos);
1226 t_start = ecore_time_get();
1227 while (svr->buf && (!svr->delete_me))
1229 _ecore_con_server_flush(svr);
1230 t = ecore_time_get();
1231 if ((t - t_start) > 0.5)
1233 WRN("ECORE_CON: EEK - stuck in _ecore_con_server_free() trying\n"
1234 " to flush data out from the server, and have been for\n"
1235 " %1.1f seconds. This is taking too long. Aborting flush.",
1242 ecore_con_local_win32_server_del(svr);
1244 if (svr->event_count) return;
1245 ECORE_MAGIC_SET(svr, ECORE_MAGIC_NONE);
1248 eina_binbuf_free(svr->buf);
1250 EINA_LIST_FREE(svr->clients, cl)
1252 Ecore_Con_Event_Server_Add *ev;
1254 /* some pointer hacks here to prevent double frees if people are being stupid */
1255 EINA_LIST_FREE(cl->event_count, ev)
1257 cl->delete_me = EINA_TRUE;
1258 INF("cl %p is dead", cl);
1259 _ecore_con_client_free(cl);
1261 if ((svr->created) && (svr->path) && (svr->ppid == getpid()))
1264 ecore_con_ssl_server_shutdown(svr);
1269 eina_stringshare_del(svr->ip);
1270 eina_stringshare_del(svr->verify_name);
1272 if (svr->ecs_buf) eina_binbuf_free(svr->ecs_buf);
1273 if (svr->ecs_recvbuf) eina_binbuf_free(svr->ecs_recvbuf);
1275 if (svr->fd_handler)
1276 ecore_main_fd_handler_del(svr->fd_handler);
1281 if (svr->until_deletion)
1282 ecore_timer_del(svr->until_deletion);
1284 servers = eina_list_remove(servers, svr);
1290 _ecore_con_client_free(Ecore_Con_Client *cl)
1294 if (cl->event_count) return;
1296 t_start = ecore_time_get();
1297 while ((cl->buf) && (!cl->delete_me))
1299 _ecore_con_client_flush(cl);
1300 t = ecore_time_get();
1301 if ((t - t_start) > 0.5)
1303 WRN("EEK - stuck in _ecore_con_client_free() trying\n"
1304 " to flush data out from the client, and have been for\n"
1305 " %1.1f seconds. This is taking too long. Aborting flush.",
1310 cl->host_server->clients = eina_list_remove(cl->host_server->clients, cl);
1313 ecore_con_local_win32_client_del(cl);
1316 if (cl->event_count) return;
1317 ECORE_MAGIC_SET(cl, ECORE_MAGIC_NONE);
1319 if (cl->buf) eina_binbuf_free(cl->buf);
1321 if (cl->host_server->type & ECORE_CON_SSL)
1322 ecore_con_ssl_client_shutdown(cl);
1325 ecore_main_fd_handler_del(cl->fd_handler);
1330 free(cl->client_addr);
1331 cl->client_addr = NULL;
1333 if (cl->until_deletion)
1334 ecore_timer_del(cl->until_deletion);
1336 eina_stringshare_del(cl->ip);
1343 _ecore_con_server_timer(Ecore_Con_Server *svr)
1345 ecore_con_server_del(svr);
1347 svr->until_deletion = NULL;
1348 return ECORE_CALLBACK_CANCEL;
1352 _ecore_con_server_timer_update(Ecore_Con_Server *svr)
1354 if (svr->disconnect_time)
1356 if (svr->disconnect_time > 0)
1358 if (svr->until_deletion)
1359 ecore_timer_interval_set(svr->until_deletion, svr->disconnect_time);
1361 svr->until_deletion = ecore_timer_add(svr->disconnect_time, (Ecore_Task_Cb)_ecore_con_server_timer, svr);
1363 else if (svr->until_deletion)
1365 ecore_timer_del(svr->until_deletion);
1366 svr->until_deletion = NULL;
1371 if (svr->until_deletion)
1373 ecore_timer_del(svr->until_deletion);
1374 svr->until_deletion = NULL;
1380 _ecore_con_client_timer(Ecore_Con_Client *cl)
1382 ecore_con_client_del(cl);
1384 cl->until_deletion = NULL;
1385 return ECORE_CALLBACK_CANCEL;
1389 _ecore_con_cl_timer_update(Ecore_Con_Client *cl)
1391 if (cl->disconnect_time)
1393 if (cl->disconnect_time > 0)
1395 if (cl->until_deletion)
1396 ecore_timer_interval_set(cl->until_deletion, cl->disconnect_time);
1398 cl->until_deletion = ecore_timer_add(cl->disconnect_time, (Ecore_Task_Cb)_ecore_con_client_timer, cl);
1400 else if (cl->until_deletion)
1402 ecore_timer_del(cl->until_deletion);
1403 cl->until_deletion = NULL;
1408 if (cl->host_server->client_disconnect_time > 0)
1410 if (cl->until_deletion)
1411 ecore_timer_interval_set(cl->until_deletion, cl->host_server->client_disconnect_time);
1413 cl->until_deletion = ecore_timer_add(cl->host_server->client_disconnect_time, (Ecore_Task_Cb)_ecore_con_client_timer, cl);
1415 else if (cl->until_deletion)
1417 ecore_timer_del(cl->until_deletion);
1418 cl->until_deletion = NULL;
1424 _ecore_con_cb_tcp_listen(void *data,
1425 Ecore_Con_Info *net_info)
1427 Ecore_Con_Server *svr;
1429 const char *memerr = NULL;
1434 if (!net_info) /* error message has already been handled */
1437 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1438 net_info->info.ai_protocol);
1439 if (svr->fd < 0) goto error;
1440 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1441 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1445 if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, (const void *)&lin,
1446 sizeof(struct linger)) < 0)
1449 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY)
1451 #ifdef HAVE_NETINET_TCP_H
1454 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag,
1462 if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
1465 if (listen(svr->fd, 4096) < 0) goto error;
1467 svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
1468 _ecore_con_svr_tcp_handler, svr, NULL, NULL);
1469 if (!svr->fd_handler)
1471 memerr = "Memory allocation failure";
1478 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1479 ecore_con_ssl_server_shutdown(svr);
1480 _ecore_con_server_kill(svr);
1484 _ecore_con_cb_udp_listen(void *data,
1485 Ecore_Con_Info *net_info)
1487 Ecore_Con_Server *svr;
1488 Ecore_Con_Type type;
1489 struct ip_mreq mreq;
1491 struct ipv6_mreq mreq6;
1494 const char *memerr = NULL;
1498 type &= ECORE_CON_TYPE;
1501 if (!net_info) /* error message has already been handled */
1504 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1505 net_info->info.ai_protocol);
1506 if (svr->fd < 0) goto error;
1508 if (type == ECORE_CON_REMOTE_MCAST)
1510 if (net_info->info.ai_family == AF_INET)
1512 if (!inet_pton(net_info->info.ai_family, net_info->ip,
1513 &mreq.imr_multiaddr))
1516 mreq.imr_interface.s_addr = htonl(INADDR_ANY);
1517 if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
1518 (const void *)&mreq, sizeof(mreq)) != 0)
1522 else if (net_info->info.ai_family == AF_INET6)
1524 if (!inet_pton(net_info->info.ai_family, net_info->ip,
1525 &mreq6.ipv6mr_multiaddr))
1527 mreq6.ipv6mr_interface = htonl(INADDR_ANY);
1528 if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
1529 (const void *)&mreq6, sizeof(mreq6)) != 0)
1535 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof(on)) != 0)
1537 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1538 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1540 if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
1544 ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
1545 _ecore_con_svr_udp_handler, svr, NULL, NULL);
1546 if (!svr->fd_handler)
1548 memerr = "Memory allocation failure";
1552 svr->ip = eina_stringshare_add(net_info->ip);
1557 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1558 ecore_con_ssl_server_shutdown(svr);
1559 _ecore_con_server_kill(svr);
1563 _ecore_con_cb_tcp_connect(void *data,
1564 Ecore_Con_Info *net_info)
1566 Ecore_Con_Server *svr;
1569 const char *memerr = NULL;
1574 if (!net_info) /* error message has already been handled */
1577 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1578 net_info->info.ai_protocol);
1579 if (svr->fd < 0) goto error;
1581 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1582 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1584 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate, sizeof(curstate)) < 0)
1587 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY)
1589 #ifdef HAVE_NETINET_TCP_H
1592 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)) < 0)
1599 res = connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen);
1601 if (res == SOCKET_ERROR)
1603 if (WSAGetLastError() != WSAEINPROGRESS)
1606 err = evil_format_message(WSAGetLastError());
1607 _ecore_con_event_server_error(svr, err, EINA_FALSE);
1608 ecore_con_ssl_server_shutdown(svr);
1609 _ecore_con_server_kill(svr);
1616 if (errno != EINPROGRESS) goto error;
1618 svr->connecting = EINA_TRUE;
1620 ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE,
1621 _ecore_con_cl_handler, svr, NULL, NULL);
1624 svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
1625 _ecore_con_cl_handler, svr, NULL, NULL);
1627 if (svr->type & ECORE_CON_SSL)
1629 svr->handshaking = EINA_TRUE;
1630 svr->ssl_state = ECORE_CON_SSL_STATE_INIT;
1631 DBG("%s ssl handshake", svr->ecs_state ? "Queuing" : "Beginning");
1632 if ((!svr->ecs_state) && ecore_con_ssl_server_init(svr))
1636 if (!svr->fd_handler)
1638 memerr = "Memory allocation failure";
1642 if ((!svr->ecs) || (svr->ecs->lookup))
1643 svr->ip = eina_stringshare_add(net_info->ip);
1648 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1649 ecore_con_ssl_server_shutdown(svr);
1650 _ecore_con_server_kill(svr);
1654 _ecore_con_cb_udp_connect(void *data,
1655 Ecore_Con_Info *net_info)
1657 Ecore_Con_Server *svr;
1660 const char *memerr = NULL;
1664 if (!net_info) /* error message has already been handled */
1667 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1668 net_info->info.ai_protocol);
1669 if (svr->fd < 0) goto error;
1670 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1671 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1672 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_BROADCAST)
1674 if (setsockopt(svr->fd, SOL_SOCKET, SO_BROADCAST,
1675 (const void *)&broadcast,
1676 sizeof(broadcast)) < 0)
1681 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR,
1682 (const void *)&curstate, sizeof(curstate)) < 0)
1685 if (connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
1688 svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE,
1689 _ecore_con_cl_udp_handler, svr, NULL, NULL);
1691 if (!svr->fd_handler)
1693 memerr = "Memory allocation failure";
1697 if ((!svr->ecs) || (svr->ecs->lookup))
1698 svr->ip = eina_stringshare_add(net_info->ip);
1703 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1704 ecore_con_ssl_server_shutdown(svr);
1705 _ecore_con_server_kill(svr);
1708 static Ecore_Con_State
1709 svr_try_connect_plain(Ecore_Con_Server *svr)
1713 socklen_t size = sizeof(int);
1715 res = getsockopt(svr->fd, SOL_SOCKET, SO_ERROR, (void *)&so_err, &size);
1717 if (res == SOCKET_ERROR)
1718 so_err = WSAGetLastError();
1720 if ((so_err == WSAEINPROGRESS) && !svr->delete_me)
1721 return ECORE_CON_INPROGRESS;
1727 if ((so_err == EINPROGRESS) && !svr->delete_me)
1728 return ECORE_CON_INPROGRESS;
1734 /* we lost our server! */
1735 ecore_con_event_server_error(svr, strerror(so_err));
1736 ERR("Connection lost: %s", strerror(so_err));
1737 _ecore_con_server_kill(svr);
1738 return ECORE_CON_DISCONNECTED;
1741 if ((!svr->delete_me) && (!svr->handshaking) && svr->connecting)
1745 if (ecore_con_socks_svr_init(svr))
1746 return ECORE_CON_INPROGRESS;
1749 ecore_con_event_server_add(svr);
1752 if (svr->fd_handler && (!svr->buf))
1753 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
1755 if (!svr->delete_me)
1756 return ECORE_CON_CONNECTED;
1758 return ECORE_CON_DISCONNECTED;
1762 _ecore_con_pretty_ip(struct sockaddr *client_addr)
1765 char ipbuf[INET_ADDRSTRLEN + 1];
1767 char ipbuf[INET6_ADDRSTRLEN + 1];
1769 int family = client_addr->sa_family;
1775 src = &(((struct sockaddr_in *)client_addr)->sin_addr);
1779 src = &(((struct sockaddr_in6 *)client_addr)->sin6_addr);
1781 if (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)src))
1784 src = (char*)src + 12;
1789 return eina_stringshare_add("0.0.0.0");
1792 if (!inet_ntop(family, src, ipbuf, sizeof(ipbuf)))
1793 return eina_stringshare_add("0.0.0.0");
1795 ipbuf[sizeof(ipbuf) - 1] = 0;
1796 return eina_stringshare_add(ipbuf);
1800 _ecore_con_svr_tcp_handler(void *data,
1801 Ecore_Fd_Handler *fd_handler __UNUSED__)
1803 Ecore_Con_Server *svr;
1804 Ecore_Con_Client *cl = NULL;
1805 unsigned char client_addr[256];
1806 unsigned int client_addr_len;
1807 const char *clerr = NULL;
1811 return ECORE_CALLBACK_RENEW;
1814 return ECORE_CALLBACK_RENEW;
1816 if ((svr->client_limit >= 0) && (!svr->reject_excess_clients) &&
1817 (svr->client_count >= (unsigned int)svr->client_limit))
1818 return ECORE_CALLBACK_RENEW;
1822 cl = calloc(1, sizeof(Ecore_Con_Client));
1825 ecore_con_event_server_error(svr, "Memory allocation failure when attempting to add a new client");
1826 return ECORE_CALLBACK_RENEW;
1828 cl->host_server = svr;
1830 client_addr_len = sizeof(client_addr);
1831 memset(&client_addr, 0, client_addr_len);
1832 cl->fd = accept(svr->fd, (struct sockaddr *)&client_addr, (socklen_t *)&client_addr_len);
1833 if (cl->fd < 0) goto error;
1834 if ((svr->client_limit >= 0) && (svr->reject_excess_clients) &&
1835 (svr->client_count >= (unsigned int)svr->client_limit))
1837 clerr = "Maximum client limit reached";
1841 if (fcntl(cl->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1842 if (fcntl(cl->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1843 cl->fd_handler = ecore_main_fd_handler_add(cl->fd, ECORE_FD_READ,
1844 _ecore_con_svr_cl_handler, cl, NULL, NULL);
1845 if (!cl->fd_handler) goto error;
1846 ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
1848 if ((!svr->upgrade) && (svr->type & ECORE_CON_SSL))
1850 cl->handshaking = EINA_TRUE;
1851 cl->ssl_state = ECORE_CON_SSL_STATE_INIT;
1852 if (ecore_con_ssl_client_init(cl))
1856 cl->client_addr = malloc(client_addr_len);
1857 if (!cl->client_addr)
1859 clerr = "Memory allocation failure when attempting to add a new client";
1862 cl->client_addr_len = client_addr_len;
1863 memcpy(cl->client_addr, &client_addr, client_addr_len);
1865 svr->clients = eina_list_append(svr->clients, cl);
1866 svr->client_count++;
1868 if ((!cl->delete_me) && (!cl->handshaking))
1869 ecore_con_event_client_add(cl);
1871 return ECORE_CALLBACK_RENEW;
1874 if (cl->fd_handler) ecore_main_fd_handler_del(cl->fd_handler);
1875 if (cl->fd >= 0) close(cl->fd);
1877 if (clerr || errno) ecore_con_event_server_error(svr, clerr ?: strerror(errno));
1878 return ECORE_CALLBACK_RENEW;
1882 _ecore_con_cl_read(Ecore_Con_Server *svr)
1885 Eina_Bool lost_server = EINA_TRUE;
1886 unsigned char buf[READBUFSIZ];
1890 /* only possible with non-ssl connections */
1891 if (svr->connecting && (svr_try_connect_plain(svr) != ECORE_CON_CONNECTED))
1894 if (svr->handshaking && (!svr->ecs_state))
1896 DBG("Continuing ssl handshake");
1897 if (!ecore_con_ssl_server_init(svr))
1898 lost_server = EINA_FALSE;
1899 _ecore_con_server_timer_update(svr);
1902 if (svr->ecs_state || !(svr->type & ECORE_CON_SSL))
1905 num = read(svr->fd, buf, sizeof(buf));
1906 /* 0 is not a valid return value for a tcp socket */
1907 if ((num > 0) || ((num < 0) && (errno == EAGAIN)))
1908 lost_server = EINA_FALSE;
1910 ecore_con_event_server_error(svr, strerror(errno));
1914 num = ecore_con_ssl_server_read(svr, buf, sizeof(buf));
1915 /* this is not an actual 0 return, 0 here just means non-fatal error such as EAGAIN */
1917 lost_server = EINA_FALSE;
1920 if ((!svr->delete_me) && (num > 0))
1923 ecore_con_socks_read(svr, buf, num);
1925 ecore_con_event_server_data(svr, buf, num, EINA_TRUE);
1929 _ecore_con_server_kill(svr);
1933 _ecore_con_cl_handler(void *data,
1934 Ecore_Fd_Handler *fd_handler)
1936 Ecore_Con_Server *svr;
1937 Eina_Bool want_read, want_write;
1941 return ECORE_CALLBACK_RENEW;
1944 return ECORE_CALLBACK_RENEW;
1946 want_read = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ);
1947 want_write = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE);
1949 if ((!svr->ecs_state) && svr->handshaking && (want_read || want_write))
1951 DBG("Continuing ssl handshake: preparing to %s...", want_read ? "read" : "write");
1955 char buf[READBUFSIZ];
1957 len = recv(svr->fd, buf, sizeof(buf), MSG_DONTWAIT | MSG_PEEK);
1958 DBG("%zu bytes in buffer", len);
1961 if (ecore_con_ssl_server_init(svr))
1963 ERR("ssl handshaking failed!");
1964 svr->handshaking = EINA_FALSE;
1966 else if (!svr->ssl_state)
1967 ecore_con_event_server_add(svr);
1968 return ECORE_CALLBACK_RENEW;
1970 if (svr->ecs && svr->ecs_state && (svr->ecs_state < ECORE_CON_PROXY_STATE_READ) && (!svr->ecs_buf))
1972 if (svr->ecs_state < ECORE_CON_PROXY_STATE_INIT)
1974 INF("PROXY STATE++");
1977 if (ecore_con_socks_svr_init(svr)) return ECORE_CALLBACK_RENEW;
1980 _ecore_con_cl_read(svr);
1981 else if (want_write) /* only possible with non-ssl connections */
1983 if (svr->connecting && (!svr_try_connect_plain(svr)) && (!svr->ecs_state))
1984 return ECORE_CALLBACK_RENEW;
1986 _ecore_con_server_flush(svr);
1989 return ECORE_CALLBACK_RENEW;
1993 _ecore_con_cl_udp_handler(void *data,
1994 Ecore_Fd_Handler *fd_handler)
1996 unsigned char buf[READBUFSIZ];
1998 Ecore_Con_Server *svr;
1999 Eina_Bool want_read, want_write;
2001 want_read = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ);
2002 want_write = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE);
2005 if (svr->delete_me || svr->delete_me || ((!want_read) && (!want_write)))
2006 return ECORE_CALLBACK_RENEW;
2010 _ecore_con_server_flush(svr);
2011 return ECORE_CALLBACK_RENEW;
2014 num = read(svr->fd, buf, READBUFSIZ);
2016 if ((!svr->delete_me) && (num > 0))
2017 ecore_con_event_server_data(svr, buf, num, EINA_TRUE);
2019 if (num < 0 && (errno != EAGAIN) && (errno != EINTR))
2021 ecore_con_event_server_error(svr, strerror(errno));
2022 _ecore_con_server_kill(svr);
2025 return ECORE_CALLBACK_RENEW;
2029 _ecore_con_svr_udp_handler(void *data,
2030 Ecore_Fd_Handler *fd_handler)
2032 unsigned char buf[READBUFSIZ];
2033 unsigned char client_addr[256];
2034 socklen_t client_addr_len = sizeof(client_addr);
2036 Ecore_Con_Server *svr;
2037 Ecore_Con_Client *cl = NULL;
2042 return ECORE_CALLBACK_RENEW;
2044 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
2046 _ecore_con_client_flush(cl);
2047 return ECORE_CALLBACK_RENEW;
2050 if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
2051 return ECORE_CALLBACK_RENEW;
2054 num = fcntl(svr->fd, F_SETFL, O_NONBLOCK);
2056 num = recvfrom(svr->fd, (char *)buf, sizeof(buf), 0,
2057 (struct sockaddr *)&client_addr,
2061 num = recvfrom(svr->fd, buf, sizeof(buf), MSG_DONTWAIT,
2062 (struct sockaddr *)&client_addr,
2066 if (num < 0 && (errno != EAGAIN) && (errno != EINTR))
2068 ecore_con_event_server_error(svr, strerror(errno));
2069 if (!svr->delete_me)
2070 ecore_con_event_client_del(NULL);
2071 _ecore_con_server_kill(svr);
2072 return ECORE_CALLBACK_CANCEL;
2076 /* Create a new client for use in the client data event */
2077 cl = calloc(1, sizeof(Ecore_Con_Client));
2078 EINA_SAFETY_ON_NULL_RETURN_VAL(cl, ECORE_CALLBACK_RENEW);
2080 cl->host_server = svr;
2081 cl->client_addr = malloc(client_addr_len);
2082 if (!cl->client_addr)
2085 return ECORE_CALLBACK_RENEW;
2087 cl->client_addr_len = client_addr_len;
2089 memcpy(cl->client_addr, &client_addr, client_addr_len);
2090 ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
2091 svr->clients = eina_list_append(svr->clients, cl);
2092 svr->client_count++;
2094 ecore_con_event_client_add(cl);
2095 ecore_con_event_client_data(cl, buf, num, EINA_TRUE);
2097 return ECORE_CALLBACK_RENEW;
2101 _ecore_con_svr_cl_read(Ecore_Con_Client *cl)
2104 Eina_Bool lost_client = EINA_TRUE;
2105 unsigned char buf[READBUFSIZ];
2109 if (cl->handshaking)
2111 /* add an extra handshake attempt just before read, even though
2112 * read also attempts to handshake, to try to finish sooner
2114 if (ecore_con_ssl_client_init(cl))
2115 lost_client = EINA_FALSE;
2117 _ecore_con_cl_timer_update(cl);
2120 if (!(cl->host_server->type & ECORE_CON_SSL) || (!cl->upgrade))
2122 num = read(cl->fd, buf, sizeof(buf));
2123 /* 0 is not a valid return value for a tcp socket */
2124 if ((num > 0) || ((num < 0) && ((errno == EAGAIN) || (errno == EINTR))))
2125 lost_client = EINA_FALSE;
2127 ecore_con_event_client_error(cl, strerror(errno));
2131 num = ecore_con_ssl_client_read(cl, buf, sizeof(buf));
2132 /* this is not an actual 0 return, 0 here just means non-fatal error such as EAGAIN */
2134 lost_client = EINA_FALSE;
2137 if ((!cl->delete_me) && (num > 0))
2138 ecore_con_event_client_data(cl, buf, num, EINA_TRUE);
2140 if (lost_client) _ecore_con_client_kill(cl);
2144 _ecore_con_svr_cl_handler(void *data,
2145 Ecore_Fd_Handler *fd_handler)
2147 Ecore_Con_Client *cl;
2151 return ECORE_CALLBACK_RENEW;
2153 if (cl->handshaking && ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ | ECORE_FD_WRITE))
2155 if (ecore_con_ssl_client_init(cl))
2157 ERR("ssl handshaking failed!");
2158 _ecore_con_client_kill(cl);
2159 return ECORE_CALLBACK_RENEW;
2161 else if (!cl->ssl_state)
2162 ecore_con_event_client_add(cl);
2164 else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
2165 _ecore_con_svr_cl_read(cl);
2167 else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
2168 _ecore_con_client_flush(cl);
2170 return ECORE_CALLBACK_RENEW;
2174 _ecore_con_server_flush(Ecore_Con_Server *svr)
2177 size_t buf_len, buf_offset;
2180 DBG("(svr=%p,buf=%p)", svr, svr->buf);
2182 if (ecore_con_local_win32_server_flush(svr))
2186 if ((!svr->buf) && (!svr->ecs_buf) && svr->fd_handler)
2188 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
2192 buf = svr->buf ? eina_binbuf_string_get(svr->buf) : eina_binbuf_string_get(svr->ecs_buf);
2193 buf_len = svr->buf ? eina_binbuf_length_get(svr->buf) : eina_binbuf_length_get(svr->ecs_buf);
2194 buf_offset = svr->buf ? svr->write_buf_offset : svr->ecs_buf_offset;
2195 num = buf_len - buf_offset;
2197 /* check whether we need to write anything at all.
2198 * we must not write zero bytes with SSL_write() since it
2199 * causes undefined behaviour
2201 /* we thank Tommy[D] for needing to check negative buffer sizes
2202 * here because his system is amazing.
2204 if (num <= 0) return;
2206 if ((!svr->ecs_state) && svr->handshaking)
2208 DBG("Continuing ssl handshake");
2209 if (ecore_con_ssl_server_init(svr))
2210 _ecore_con_server_kill(svr);
2211 _ecore_con_server_timer_update(svr);
2215 if (svr->ecs_state || (!(svr->type & ECORE_CON_SSL)))
2216 count = write(svr->fd, buf + buf_offset, num);
2218 count = ecore_con_ssl_server_write(svr, buf + buf_offset, num);
2222 if ((errno != EAGAIN) && (errno != EINTR))
2224 ecore_con_event_server_error(svr, strerror(errno));
2225 _ecore_con_server_kill(svr);
2230 if (count && (!svr->ecs_state)) ecore_con_event_server_write(svr, count);
2232 buf_offset = svr->ecs_buf_offset += count;
2234 buf_offset = svr->write_buf_offset += count;
2235 if (buf_offset >= buf_len)
2239 svr->ecs_buf_offset = 0;
2240 eina_binbuf_free(svr->ecs_buf);
2241 svr->ecs_buf = NULL;
2242 INF("PROXY STATE++");
2247 svr->write_buf_offset = 0;
2248 eina_binbuf_free(svr->buf);
2251 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK)
2254 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
2255 /* realistically this isn't anything serious so we can just log and continue */
2256 ERR("uncorking failed! %s", strerror(errno));
2260 if (svr->fd_handler)
2261 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
2263 else if ((count < num) && svr->fd_handler)
2264 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE);
2268 _ecore_con_client_flush(Ecore_Con_Client *cl)
2270 int num = 0, count = 0;
2273 if (ecore_con_local_win32_client_flush(cl))
2277 if (!cl->buf && cl->fd_handler)
2279 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ);
2283 if (cl->handshaking)
2285 if (ecore_con_ssl_client_init(cl))
2288 _ecore_con_cl_timer_update(cl);
2293 num = eina_binbuf_length_get(cl->buf) - cl->buf_offset;
2294 if (num <= 0) return;
2295 if (!(cl->host_server->type & ECORE_CON_SSL) || (!cl->upgrade))
2296 count = write(cl->fd, eina_binbuf_string_get(cl->buf) + cl->buf_offset, num);
2298 count = ecore_con_ssl_client_write(cl, eina_binbuf_string_get(cl->buf) + cl->buf_offset, num);
2303 if ((errno != EAGAIN) && (errno != EINTR) && (!cl->delete_me))
2305 ecore_con_event_client_error(cl, strerror(errno));
2306 _ecore_con_client_kill(cl);
2312 if (count) ecore_con_event_client_write(cl, count);
2313 cl->buf_offset += count, num -= count;
2314 if (cl->buf_offset >= eina_binbuf_length_get(cl->buf))
2317 eina_binbuf_free(cl->buf);
2320 if ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK)
2323 if (setsockopt(cl->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
2324 /* realistically this isn't anything serious so we can just log and continue */
2325 ERR("uncorking failed! %s", strerror(errno));
2329 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ);
2331 else if (cl->fd_handler && (num >= 0))
2332 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_WRITE);
2336 _ecore_con_event_client_add_free(Ecore_Con_Server *svr,
2339 Ecore_Con_Event_Client_Add *e;
2344 e->client->event_count = eina_list_remove(e->client->event_count, e);
2345 if (e->client->host_server)
2347 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, ev);
2348 if ((!svr->event_count) && (svr->delete_me))
2349 _ecore_con_server_free(svr);
2351 if ((!e->client->event_count) && (e->client->delete_me))
2352 ecore_con_client_del(e->client);
2355 ecore_con_event_client_add_free(e);
2356 _ecore_con_event_count--;
2357 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2358 ecore_con_mempool_shutdown();
2362 _ecore_con_event_client_del_free(Ecore_Con_Server *svr,
2365 Ecore_Con_Event_Client_Del *e;
2370 e->client->event_count = eina_list_remove(e->client->event_count, e);
2371 if (e->client->host_server)
2373 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, ev);
2374 if ((!svr->event_count) && (svr->delete_me))
2375 _ecore_con_server_free(svr);
2377 if (!e->client->event_count)
2378 _ecore_con_client_free(e->client);
2380 ecore_con_event_client_del_free(e);
2381 _ecore_con_event_count--;
2382 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2383 ecore_con_mempool_shutdown();
2387 _ecore_con_event_client_write_free(Ecore_Con_Server *svr,
2388 Ecore_Con_Event_Client_Write *e)
2392 e->client->event_count = eina_list_remove(e->client->event_count, e);
2393 if (e->client->host_server)
2395 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, e);
2396 if ((!svr->event_count) && (svr->delete_me))
2397 _ecore_con_server_free(svr);
2399 if (((!e->client->event_count) && (e->client->delete_me)) ||
2400 ((e->client->host_server &&
2401 ((e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP ||
2402 (e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_MCAST))))
2403 ecore_con_client_del(e->client);
2405 ecore_con_event_client_write_free(e);
2406 _ecore_con_event_count--;
2407 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2408 ecore_con_mempool_shutdown();
2412 _ecore_con_event_client_data_free(Ecore_Con_Server *svr,
2415 Ecore_Con_Event_Client_Data *e;
2420 e->client->event_count = eina_list_remove(e->client->event_count, e);
2421 if (e->client->host_server)
2423 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, ev);
2425 if ((!svr->event_count) && (svr->delete_me))
2426 _ecore_con_server_free(svr);
2427 if (((!e->client->event_count) && (e->client->delete_me)) ||
2428 ((e->client->host_server &&
2429 ((e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP ||
2430 (e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_MCAST))))
2431 ecore_con_client_del(e->client);
2434 ecore_con_event_client_data_free(e);
2435 _ecore_con_event_count--;
2436 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2437 ecore_con_mempool_shutdown();
2441 _ecore_con_event_server_add_free(void *data __UNUSED__,
2444 Ecore_Con_Event_Server_Add *e;
2449 e->server->event_count = eina_list_remove(e->server->event_count, ev);
2450 if ((!e->server->event_count) && (e->server->delete_me))
2451 _ecore_con_server_free(e->server);
2453 ecore_con_event_server_add_free(e);
2454 _ecore_con_event_count--;
2455 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2456 ecore_con_mempool_shutdown();
2460 _ecore_con_event_server_del_free(void *data __UNUSED__,
2463 Ecore_Con_Event_Server_Del *e;
2468 e->server->event_count = eina_list_remove(e->server->event_count, ev);
2469 if (!e->server->event_count)
2470 _ecore_con_server_free(e->server);
2472 ecore_con_event_server_del_free(e);
2473 _ecore_con_event_count--;
2474 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2475 ecore_con_mempool_shutdown();
2479 _ecore_con_event_server_write_free(void *data __UNUSED__,
2480 Ecore_Con_Event_Server_Write *e)
2484 e->server->event_count = eina_list_remove(e->server->event_count, e);
2485 if ((!e->server->event_count) && (e->server->delete_me))
2486 _ecore_con_server_free(e->server);
2489 ecore_con_event_server_write_free(e);
2490 _ecore_con_event_count--;
2491 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2492 ecore_con_mempool_shutdown();
2496 _ecore_con_event_server_data_free(void *data __UNUSED__,
2499 Ecore_Con_Event_Server_Data *e;
2504 e->server->event_count = eina_list_remove(e->server->event_count, ev);
2505 if ((!e->server->event_count) && (e->server->delete_me))
2506 _ecore_con_server_free(e->server);
2510 ecore_con_event_server_data_free(e);
2511 _ecore_con_event_count--;
2512 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2513 ecore_con_mempool_shutdown();
2518 _ecore_con_event_server_error_free(void *data __UNUSED__, Ecore_Con_Event_Server_Error *e)
2522 e->server->event_count = eina_list_remove(e->server->event_count, e);
2523 if ((!e->server->event_count) && (e->server->delete_me))
2524 _ecore_con_server_free(e->server);
2527 ecore_con_event_server_error_free(e);
2528 _ecore_con_event_count--;
2529 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2530 ecore_con_mempool_shutdown();
2534 _ecore_con_event_client_error_free(Ecore_Con_Server *svr, Ecore_Con_Event_Client_Error *e)
2538 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, e);
2539 if ((!e->client->event_count) && (e->client->delete_me))
2540 _ecore_con_client_free(e->client);
2541 if (e->client->host_server)
2543 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, e);
2544 if ((!svr->event_count) && (svr->delete_me))
2545 _ecore_con_server_free(svr);
2549 ecore_con_event_client_error_free(e);
2550 _ecore_con_event_count--;
2551 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2552 ecore_con_mempool_shutdown();
2556 _ecore_con_lookup_done(void *data,
2557 Ecore_Con_Info *infos)
2559 Ecore_Con_Server *svr;
2560 Ecore_Con_Lookup *lk;
2566 lk->done_cb(infos->info.ai_canonname, infos->ip,
2567 infos->info.ai_addr, infos->info.ai_addrlen,
2570 lk->done_cb(NULL, NULL, NULL, 0, (void *)lk->data);