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->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 if (ecore_con_ssl_server_prepare(svr, compl_type & ECORE_CON_SSL))
474 if (((type == ECORE_CON_REMOTE_TCP) ||
475 (type == ECORE_CON_REMOTE_NODELAY) ||
476 (type == ECORE_CON_REMOTE_CORK) ||
477 (type == ECORE_CON_REMOTE_UDP) ||
478 (type == ECORE_CON_REMOTE_BROADCAST)) &&
482 if ((type == ECORE_CON_LOCAL_USER) ||
483 (type == ECORE_CON_LOCAL_SYSTEM) ||
484 (type == ECORE_CON_LOCAL_ABSTRACT))
487 if (!ecore_con_local_connect(svr, _ecore_con_cl_handler))
490 if (!ecore_con_local_connect(svr, _ecore_con_cl_handler, svr))
494 if ((type == ECORE_CON_REMOTE_TCP) ||
495 (type == ECORE_CON_REMOTE_NODELAY) ||
496 (type == ECORE_CON_REMOTE_CORK))
499 if (!ecore_con_info_tcp_connect(svr, _ecore_con_cb_tcp_connect,
503 else if ((type == ECORE_CON_REMOTE_UDP) ||
504 (type == ECORE_CON_REMOTE_BROADCAST))
506 if (!ecore_con_info_udp_connect(svr, _ecore_con_cb_udp_connect,
510 servers = eina_list_append(servers, svr);
511 ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER);
523 ecore_main_fd_handler_del(svr->fd_handler);
528 ecore_con_ssl_server_shutdown(svr);
534 ecore_con_server_timeout_set(Ecore_Con_Server *svr,
537 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
539 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_timeout_set");
544 svr->client_disconnect_time = timeout;
546 svr->disconnect_time = timeout;
550 ecore_con_server_timeout_get(Ecore_Con_Server *svr)
552 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
554 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_timeout_get");
558 return svr->created ? svr->client_disconnect_time : svr->disconnect_time;
562 ecore_con_server_del(Ecore_Con_Server *svr)
564 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
566 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_del");
573 _ecore_con_server_kill(svr);
578 ecore_con_server_data_get(Ecore_Con_Server *svr)
580 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
582 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_data_get");
590 ecore_con_server_data_set(Ecore_Con_Server *svr,
595 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
597 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_data_get");
607 ecore_con_server_connected_get(Ecore_Con_Server *svr)
609 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
611 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_connected_get");
621 EAPI const Eina_List *
622 ecore_con_server_clients_get(Ecore_Con_Server *svr)
624 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
626 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
627 "ecore_con_server_clients_get");
635 ecore_con_server_name_get(Ecore_Con_Server *svr)
637 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
639 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
640 "ecore_con_server_name_get");
648 ecore_con_server_port_get(Ecore_Con_Server *svr)
650 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
652 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
653 "ecore_con_server_port_get");
660 ecore_con_server_send(Ecore_Con_Server *svr,
664 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
666 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_send");
670 EINA_SAFETY_ON_TRUE_RETURN_VAL(svr->delete_me, 0);
672 EINA_SAFETY_ON_NULL_RETURN_VAL(data, 0);
674 EINA_SAFETY_ON_TRUE_RETURN_VAL(size < 1, 0);
677 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE);
681 svr->buf = eina_binbuf_new();
682 EINA_SAFETY_ON_NULL_RETURN_VAL(svr->buf, 0);
684 if ((svr->fd >= 0) && ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK))
687 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
688 /* realistically this isn't anything serious so we can just log and continue */
689 ERR("corking failed! %s", strerror(errno));
693 eina_binbuf_append_length(svr->buf, data, size);
699 ecore_con_server_client_limit_set(Ecore_Con_Server *svr,
701 char reject_excess_clients)
703 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
705 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
706 "ecore_con_server_client_limit_set");
710 svr->client_limit = client_limit;
711 svr->reject_excess_clients = reject_excess_clients;
715 ecore_con_server_ip_get(Ecore_Con_Server *svr)
717 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
719 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_ip_get");
727 ecore_con_server_uptime_get(Ecore_Con_Server *svr)
729 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
731 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_uptime_get");
735 return ecore_time_get() - svr->start_time;
739 ecore_con_server_flush(Ecore_Con_Server *svr)
741 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
743 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_flush");
747 _ecore_con_server_flush(svr);
755 * @addtogroup Ecore_Con_Client_Group Ecore Connection Client Functions
757 * Functions that operate on Ecore connection client objects.
763 * @example ecore_con_client_example.c
764 * Shows how to write a simple client that connects to the example server.
768 ecore_con_client_send(Ecore_Con_Client *cl,
772 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
774 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_send");
778 EINA_SAFETY_ON_TRUE_RETURN_VAL(cl->delete_me, 0);
780 EINA_SAFETY_ON_NULL_RETURN_VAL(data, 0);
782 EINA_SAFETY_ON_TRUE_RETURN_VAL(size < 1, 0);
785 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE);
787 if (cl->host_server && ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP))
788 sendto(cl->host_server->fd, data, size, 0, (struct sockaddr *)cl->client_addr,
789 cl->client_addr_len);
792 cl->buf = eina_binbuf_new();
793 EINA_SAFETY_ON_NULL_RETURN_VAL(cl->buf, 0);
795 if ((cl->fd >= 0) && ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK))
798 if (setsockopt(cl->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
799 /* realistically this isn't anything serious so we can just log and continue */
800 ERR("corking failed! %s", strerror(errno));
804 eina_binbuf_append_length(cl->buf, data, size);
809 EAPI Ecore_Con_Server *
810 ecore_con_client_server_get(Ecore_Con_Client *cl)
812 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
814 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
815 "ecore_con_client_server_get");
819 return cl->host_server;
823 ecore_con_client_connected_get(Ecore_Con_Client *cl)
825 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
827 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
828 "ecore_con_client_connected_get");
832 return !cl->delete_me;
836 ecore_con_client_timeout_set(Ecore_Con_Client *cl,
839 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
841 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
842 "ecore_con_client_timeout_set");
846 cl->disconnect_time = timeout;
848 _ecore_con_cl_timer_update(cl);
852 ecore_con_client_timeout_get(Ecore_Con_Client *cl)
854 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
856 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_timeout_get");
860 return cl->disconnect_time;
864 ecore_con_client_del(Ecore_Con_Client *cl)
866 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
868 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_del");
872 _ecore_con_client_kill(cl);
877 ecore_con_client_data_set(Ecore_Con_Client *cl,
880 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
882 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_data_set");
886 cl->data = (void *)data;
890 ecore_con_client_data_get(Ecore_Con_Client *cl)
892 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
894 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_data_get");
902 ecore_con_client_ip_get(Ecore_Con_Client *cl)
904 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
906 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_ip_get");
910 cl->ip = _ecore_con_pretty_ip(cl->client_addr);
916 ecore_con_client_port_get(Ecore_Con_Client *cl)
918 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
920 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_port_get");
923 if (cl->client_addr->sa_family == AF_INET)
924 return ((struct sockaddr_in*)cl->client_addr)->sin_port;
926 return ((struct sockaddr_in6*)cl->client_addr)->sin6_port;
933 ecore_con_client_uptime_get(Ecore_Con_Client *cl)
935 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
937 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_uptime_get");
941 return ecore_time_get() - cl->start_time;
945 ecore_con_client_flush(Ecore_Con_Client *cl)
947 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
949 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_flush");
953 _ecore_con_client_flush(cl);
957 ecore_con_server_fd_get(Ecore_Con_Server *svr)
959 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
961 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, __func__);
964 if (svr->created) return -1;
965 return ecore_main_fd_handler_fd_get(svr->fd_handler);
969 ecore_con_client_fd_get(Ecore_Con_Client *cl)
971 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
973 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, __func__);
976 return ecore_main_fd_handler_fd_get(cl->fd_handler);
984 ecore_con_event_proxy_bind(Ecore_Con_Server *svr)
986 Ecore_Con_Event_Proxy_Bind *e;
987 int ev = ECORE_CON_EVENT_PROXY_BIND;
989 e = ecore_con_event_proxy_bind_alloc();
990 EINA_SAFETY_ON_NULL_RETURN(e);
992 svr->event_count = eina_list_append(svr->event_count, e);
993 _ecore_con_server_timer_update(svr);
995 e->ip = svr->proxyip;
996 e->port = svr->proxyport;
997 ecore_event_add(ev, e,
998 _ecore_con_event_server_add_free, NULL);
999 _ecore_con_event_count++;
1003 ecore_con_event_server_add(Ecore_Con_Server *svr)
1005 /* we got our server! */
1006 Ecore_Con_Event_Server_Add *e;
1007 int ev = ECORE_CON_EVENT_SERVER_ADD;
1009 e = ecore_con_event_server_add_alloc();
1010 EINA_SAFETY_ON_NULL_RETURN(e);
1012 svr->connecting = EINA_FALSE;
1013 svr->start_time = ecore_time_get();
1014 svr->event_count = eina_list_append(svr->event_count, e);
1015 _ecore_con_server_timer_update(svr);
1017 if (svr->upgrade) ev = ECORE_CON_EVENT_SERVER_UPGRADE;
1018 ecore_event_add(ev, e,
1019 _ecore_con_event_server_add_free, NULL);
1020 _ecore_con_event_count++;
1024 ecore_con_event_server_del(Ecore_Con_Server *svr)
1026 Ecore_Con_Event_Server_Del *e;
1028 svr->delete_me = EINA_TRUE;
1029 INF("svr %p is dead", svr);
1030 e = ecore_con_event_server_del_alloc();
1031 EINA_SAFETY_ON_NULL_RETURN(e);
1033 svr->event_count = eina_list_append(svr->event_count, e);
1034 _ecore_con_server_timer_update(svr);
1038 svr->ecs_state = svr->ecs->lookup ? ECORE_CON_PROXY_STATE_RESOLVED : ECORE_CON_PROXY_STATE_DONE;
1039 eina_stringshare_replace(&svr->proxyip, NULL);
1042 ecore_event_add(ECORE_CON_EVENT_SERVER_DEL, e,
1043 _ecore_con_event_server_del_free, NULL);
1044 _ecore_con_event_count++;
1048 ecore_con_event_server_write(Ecore_Con_Server *svr, int num)
1050 Ecore_Con_Event_Server_Write *e;
1052 e = ecore_con_event_server_write_alloc();
1053 EINA_SAFETY_ON_NULL_RETURN(e);
1055 INF("Wrote %d bytes", num);
1056 svr->event_count = eina_list_append(svr->event_count, e);
1059 ecore_event_add(ECORE_CON_EVENT_SERVER_WRITE, e,
1060 (Ecore_End_Cb)_ecore_con_event_server_write_free, NULL);
1061 _ecore_con_event_count++;
1065 ecore_con_event_server_data(Ecore_Con_Server *svr, unsigned char *buf, int num, Eina_Bool duplicate)
1067 Ecore_Con_Event_Server_Data *e;
1069 e = ecore_con_event_server_data_alloc();
1070 EINA_SAFETY_ON_NULL_RETURN(e);
1072 svr->event_count = eina_list_append(svr->event_count, e);
1073 _ecore_con_server_timer_update(svr);
1077 e->data = malloc(num);
1080 ERR("server data allocation failure !");
1081 _ecore_con_event_server_data_free(NULL, e);
1084 memcpy(e->data, buf, num);
1089 ecore_event_add(ECORE_CON_EVENT_SERVER_DATA, e,
1090 _ecore_con_event_server_data_free, NULL);
1091 _ecore_con_event_count++;
1095 ecore_con_event_client_add(Ecore_Con_Client *cl)
1097 Ecore_Con_Event_Client_Add *e;
1098 int ev = ECORE_CON_EVENT_CLIENT_ADD;
1100 e = ecore_con_event_client_add_alloc();
1101 EINA_SAFETY_ON_NULL_RETURN(e);
1103 cl->event_count = eina_list_append(cl->event_count, e);
1104 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1105 _ecore_con_cl_timer_update(cl);
1107 if (cl->upgrade) ev = ECORE_CON_EVENT_CLIENT_UPGRADE;
1108 ecore_event_add(ev, e,
1109 (Ecore_End_Cb)_ecore_con_event_client_add_free, cl->host_server);
1110 _ecore_con_event_count++;
1114 ecore_con_event_client_del(Ecore_Con_Client *cl)
1116 Ecore_Con_Event_Client_Del *e;
1119 cl->delete_me = EINA_TRUE;
1120 INF("cl %p is dead", cl);
1121 e = ecore_con_event_client_del_alloc();
1122 EINA_SAFETY_ON_NULL_RETURN(e);
1123 cl->event_count = eina_list_append(cl->event_count, e);
1125 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1126 _ecore_con_cl_timer_update(cl);
1128 ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
1129 (Ecore_End_Cb)_ecore_con_event_client_del_free, cl->host_server);
1130 _ecore_con_event_count++;
1134 ecore_con_event_client_write(Ecore_Con_Client *cl, int num)
1136 Ecore_Con_Event_Client_Write *e;
1138 e = ecore_con_event_client_write_alloc();
1139 EINA_SAFETY_ON_NULL_RETURN(e);
1141 cl->event_count = eina_list_append(cl->event_count, e);
1142 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1145 ecore_event_add(ECORE_CON_EVENT_CLIENT_WRITE, e,
1146 (Ecore_End_Cb)_ecore_con_event_client_write_free, cl->host_server);
1147 _ecore_con_event_count++;
1151 ecore_con_event_client_data(Ecore_Con_Client *cl, unsigned char *buf, int num, Eina_Bool duplicate)
1153 Ecore_Con_Event_Client_Data *e;
1155 e = ecore_con_event_client_data_alloc();
1156 EINA_SAFETY_ON_NULL_RETURN(e);
1158 cl->event_count = eina_list_append(cl->event_count, e);
1159 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1160 _ecore_con_cl_timer_update(cl);
1164 e->data = malloc(num);
1167 ERR("client data allocation failure !");
1168 _ecore_con_event_client_data_free(cl->host_server, e);
1171 memcpy(e->data, buf, num);
1176 ecore_event_add(ECORE_CON_EVENT_CLIENT_DATA, e,
1177 (Ecore_End_Cb)_ecore_con_event_client_data_free, cl->host_server);
1178 _ecore_con_event_count++;
1183 ecore_con_server_infos_del(Ecore_Con_Server *svr, void *info)
1185 svr->infos = eina_list_remove(svr->infos, info);
1189 _ecore_con_event_server_error(Ecore_Con_Server *svr, char *error, Eina_Bool duplicate)
1191 Ecore_Con_Event_Server_Error *e;
1193 e = ecore_con_event_server_error_alloc();
1194 EINA_SAFETY_ON_NULL_RETURN(e);
1197 e->error = duplicate ? strdup(error) : error;
1199 svr->event_count = eina_list_append(svr->event_count, e);
1200 ecore_event_add(ECORE_CON_EVENT_SERVER_ERROR, e, (Ecore_End_Cb)_ecore_con_event_server_error_free, NULL);
1201 _ecore_con_event_count++;
1205 ecore_con_event_client_error(Ecore_Con_Client *cl, const char *error)
1207 Ecore_Con_Event_Client_Error *e;
1209 e = ecore_con_event_client_error_alloc();
1210 EINA_SAFETY_ON_NULL_RETURN(e);
1213 e->error = strdup(error);
1215 cl->event_count = eina_list_append(cl->event_count, e);
1216 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1217 ecore_event_add(ECORE_CON_EVENT_CLIENT_ERROR, e, (Ecore_End_Cb)_ecore_con_event_client_error_free, cl->host_server);
1218 _ecore_con_event_count++;
1222 _ecore_con_server_free(Ecore_Con_Server *svr)
1224 Ecore_Con_Client *cl;
1227 if (svr->event_count) return;
1231 ecore_con_info_data_clear(svr->infos->data);
1232 svr->infos = eina_list_remove_list(svr->infos, svr->infos);
1235 t_start = ecore_time_get();
1236 while (svr->buf && (!svr->delete_me))
1238 _ecore_con_server_flush(svr);
1239 t = ecore_time_get();
1240 if ((t - t_start) > 0.5)
1242 WRN("ECORE_CON: EEK - stuck in _ecore_con_server_free() trying\n"
1243 " to flush data out from the server, and have been for\n"
1244 " %1.1f seconds. This is taking too long. Aborting flush.",
1251 ecore_con_local_win32_server_del(svr);
1253 if (svr->event_count) return;
1254 ECORE_MAGIC_SET(svr, ECORE_MAGIC_NONE);
1257 eina_binbuf_free(svr->buf);
1259 EINA_LIST_FREE(svr->clients, cl)
1261 Ecore_Con_Event_Server_Add *ev;
1263 /* some pointer hacks here to prevent double frees if people are being stupid */
1264 EINA_LIST_FREE(cl->event_count, ev)
1266 cl->delete_me = EINA_TRUE;
1267 INF("cl %p is dead", cl);
1268 _ecore_con_client_free(cl);
1270 if ((svr->created) && (svr->path) && (svr->ppid == getpid()))
1273 ecore_con_ssl_server_shutdown(svr);
1278 eina_stringshare_del(svr->ip);
1279 eina_stringshare_del(svr->verify_name);
1281 if (svr->ecs_buf) eina_binbuf_free(svr->ecs_buf);
1282 if (svr->ecs_recvbuf) eina_binbuf_free(svr->ecs_recvbuf);
1284 if (svr->fd_handler)
1285 ecore_main_fd_handler_del(svr->fd_handler);
1290 if (svr->until_deletion)
1291 ecore_timer_del(svr->until_deletion);
1293 servers = eina_list_remove(servers, svr);
1299 _ecore_con_client_free(Ecore_Con_Client *cl)
1303 if (cl->event_count) return;
1305 t_start = ecore_time_get();
1306 while ((cl->buf) && (!cl->delete_me))
1308 _ecore_con_client_flush(cl);
1309 t = ecore_time_get();
1310 if ((t - t_start) > 0.5)
1312 WRN("EEK - stuck in _ecore_con_client_free() trying\n"
1313 " to flush data out from the client, and have been for\n"
1314 " %1.1f seconds. This is taking too long. Aborting flush.",
1319 cl->host_server->clients = eina_list_remove(cl->host_server->clients, cl);
1322 ecore_con_local_win32_client_del(cl);
1325 if (cl->event_count) return;
1326 ECORE_MAGIC_SET(cl, ECORE_MAGIC_NONE);
1328 if (cl->buf) eina_binbuf_free(cl->buf);
1330 if (cl->host_server->type & ECORE_CON_SSL)
1331 ecore_con_ssl_client_shutdown(cl);
1334 ecore_main_fd_handler_del(cl->fd_handler);
1339 free(cl->client_addr);
1340 cl->client_addr = NULL;
1342 if (cl->until_deletion)
1343 ecore_timer_del(cl->until_deletion);
1345 eina_stringshare_del(cl->ip);
1352 _ecore_con_server_timer(Ecore_Con_Server *svr)
1354 ecore_con_server_del(svr);
1356 svr->until_deletion = NULL;
1357 return ECORE_CALLBACK_CANCEL;
1361 _ecore_con_server_timer_update(Ecore_Con_Server *svr)
1363 if (svr->disconnect_time)
1365 if (svr->disconnect_time > 0)
1367 if (svr->until_deletion)
1368 ecore_timer_interval_set(svr->until_deletion, svr->disconnect_time);
1370 svr->until_deletion = ecore_timer_add(svr->disconnect_time, (Ecore_Task_Cb)_ecore_con_server_timer, svr);
1372 else if (svr->until_deletion)
1374 ecore_timer_del(svr->until_deletion);
1375 svr->until_deletion = NULL;
1380 if (svr->until_deletion)
1382 ecore_timer_del(svr->until_deletion);
1383 svr->until_deletion = NULL;
1389 _ecore_con_client_timer(Ecore_Con_Client *cl)
1391 ecore_con_client_del(cl);
1393 cl->until_deletion = NULL;
1394 return ECORE_CALLBACK_CANCEL;
1398 _ecore_con_cl_timer_update(Ecore_Con_Client *cl)
1400 if (cl->disconnect_time)
1402 if (cl->disconnect_time > 0)
1404 if (cl->until_deletion)
1405 ecore_timer_interval_set(cl->until_deletion, cl->disconnect_time);
1407 cl->until_deletion = ecore_timer_add(cl->disconnect_time, (Ecore_Task_Cb)_ecore_con_client_timer, cl);
1409 else if (cl->until_deletion)
1411 ecore_timer_del(cl->until_deletion);
1412 cl->until_deletion = NULL;
1417 if (cl->host_server->client_disconnect_time > 0)
1419 if (cl->until_deletion)
1420 ecore_timer_interval_set(cl->until_deletion, cl->host_server->client_disconnect_time);
1422 cl->until_deletion = ecore_timer_add(cl->host_server->client_disconnect_time, (Ecore_Task_Cb)_ecore_con_client_timer, cl);
1424 else if (cl->until_deletion)
1426 ecore_timer_del(cl->until_deletion);
1427 cl->until_deletion = NULL;
1433 _ecore_con_cb_tcp_listen(void *data,
1434 Ecore_Con_Info *net_info)
1436 Ecore_Con_Server *svr;
1438 const char *memerr = NULL;
1443 if (!net_info) /* error message has already been handled */
1446 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1447 net_info->info.ai_protocol);
1448 if (svr->fd < 0) goto error;
1449 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1450 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1454 if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, (const void *)&lin,
1455 sizeof(struct linger)) < 0)
1458 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY)
1460 #ifdef HAVE_NETINET_TCP_H
1463 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag,
1471 if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
1474 if (listen(svr->fd, 4096) < 0) goto error;
1476 svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
1477 _ecore_con_svr_tcp_handler, svr, NULL, NULL);
1478 if (!svr->fd_handler)
1480 memerr = "Memory allocation failure";
1487 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1488 ecore_con_ssl_server_shutdown(svr);
1489 _ecore_con_server_kill(svr);
1493 _ecore_con_cb_udp_listen(void *data,
1494 Ecore_Con_Info *net_info)
1496 Ecore_Con_Server *svr;
1497 Ecore_Con_Type type;
1498 struct ip_mreq mreq;
1500 struct ipv6_mreq mreq6;
1503 const char *memerr = NULL;
1507 type &= ECORE_CON_TYPE;
1510 if (!net_info) /* error message has already been handled */
1513 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1514 net_info->info.ai_protocol);
1515 if (svr->fd < 0) goto error;
1517 if (type == ECORE_CON_REMOTE_MCAST)
1519 if (net_info->info.ai_family == AF_INET)
1521 if (!inet_pton(net_info->info.ai_family, net_info->ip,
1522 &mreq.imr_multiaddr))
1525 mreq.imr_interface.s_addr = htonl(INADDR_ANY);
1526 if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
1527 (const void *)&mreq, sizeof(mreq)) != 0)
1531 else if (net_info->info.ai_family == AF_INET6)
1533 if (!inet_pton(net_info->info.ai_family, net_info->ip,
1534 &mreq6.ipv6mr_multiaddr))
1536 mreq6.ipv6mr_interface = htonl(INADDR_ANY);
1537 if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
1538 (const void *)&mreq6, sizeof(mreq6)) != 0)
1544 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof(on)) != 0)
1546 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1547 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1549 if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
1553 ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
1554 _ecore_con_svr_udp_handler, svr, NULL, NULL);
1555 if (!svr->fd_handler)
1557 memerr = "Memory allocation failure";
1561 svr->ip = eina_stringshare_add(net_info->ip);
1566 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1567 ecore_con_ssl_server_shutdown(svr);
1568 _ecore_con_server_kill(svr);
1572 _ecore_con_cb_tcp_connect(void *data,
1573 Ecore_Con_Info *net_info)
1575 Ecore_Con_Server *svr;
1578 const char *memerr = NULL;
1583 if (!net_info) /* error message has already been handled */
1586 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1587 net_info->info.ai_protocol);
1588 if (svr->fd < 0) goto error;
1590 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1591 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1593 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate, sizeof(curstate)) < 0)
1596 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY)
1598 #ifdef HAVE_NETINET_TCP_H
1601 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)) < 0)
1608 res = connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen);
1610 if (res == SOCKET_ERROR)
1612 if (WSAGetLastError() != WSAEINPROGRESS)
1615 err = evil_format_message(WSAGetLastError());
1616 _ecore_con_event_server_error(svr, err, EINA_FALSE);
1617 ecore_con_ssl_server_shutdown(svr);
1618 _ecore_con_server_kill(svr);
1625 if (errno != EINPROGRESS) goto error;
1627 svr->connecting = EINA_TRUE;
1629 ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE,
1630 _ecore_con_cl_handler, svr, NULL, NULL);
1633 svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
1634 _ecore_con_cl_handler, svr, NULL, NULL);
1636 if (svr->type & ECORE_CON_SSL)
1638 svr->handshaking = EINA_TRUE;
1639 svr->ssl_state = ECORE_CON_SSL_STATE_INIT;
1640 DBG("%s ssl handshake", svr->ecs_state ? "Queuing" : "Beginning");
1641 if ((!svr->ecs_state) && ecore_con_ssl_server_init(svr))
1645 if (!svr->fd_handler)
1647 memerr = "Memory allocation failure";
1651 if ((!svr->ecs) || (svr->ecs->lookup))
1652 svr->ip = eina_stringshare_add(net_info->ip);
1657 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1658 ecore_con_ssl_server_shutdown(svr);
1659 _ecore_con_server_kill(svr);
1663 _ecore_con_cb_udp_connect(void *data,
1664 Ecore_Con_Info *net_info)
1666 Ecore_Con_Server *svr;
1669 const char *memerr = NULL;
1673 if (!net_info) /* error message has already been handled */
1676 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1677 net_info->info.ai_protocol);
1678 if (svr->fd < 0) goto error;
1679 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1680 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1681 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_BROADCAST)
1683 if (setsockopt(svr->fd, SOL_SOCKET, SO_BROADCAST,
1684 (const void *)&broadcast,
1685 sizeof(broadcast)) < 0)
1690 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR,
1691 (const void *)&curstate, sizeof(curstate)) < 0)
1694 if (connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
1697 svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE,
1698 _ecore_con_cl_udp_handler, svr, NULL, NULL);
1700 if (!svr->fd_handler)
1702 memerr = "Memory allocation failure";
1706 if ((!svr->ecs) || (svr->ecs->lookup))
1707 svr->ip = eina_stringshare_add(net_info->ip);
1712 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1713 ecore_con_ssl_server_shutdown(svr);
1714 _ecore_con_server_kill(svr);
1717 static Ecore_Con_State
1718 svr_try_connect_plain(Ecore_Con_Server *svr)
1722 socklen_t size = sizeof(int);
1724 res = getsockopt(svr->fd, SOL_SOCKET, SO_ERROR, (void *)&so_err, &size);
1726 if (res == SOCKET_ERROR)
1727 so_err = WSAGetLastError();
1729 if ((so_err == WSAEINPROGRESS) && !svr->delete_me)
1730 return ECORE_CON_INPROGRESS;
1736 if ((so_err == EINPROGRESS) && !svr->delete_me)
1737 return ECORE_CON_INPROGRESS;
1743 /* we lost our server! */
1744 ecore_con_event_server_error(svr, strerror(so_err));
1745 ERR("Connection lost: %s", strerror(so_err));
1746 _ecore_con_server_kill(svr);
1747 return ECORE_CON_DISCONNECTED;
1750 if ((!svr->delete_me) && (!svr->handshaking) && svr->connecting)
1754 if (ecore_con_socks_svr_init(svr))
1755 return ECORE_CON_INPROGRESS;
1758 ecore_con_event_server_add(svr);
1761 if (svr->fd_handler && (!svr->buf))
1762 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
1764 if (!svr->delete_me)
1765 return ECORE_CON_CONNECTED;
1767 return ECORE_CON_DISCONNECTED;
1771 _ecore_con_pretty_ip(struct sockaddr *client_addr)
1774 char ipbuf[INET_ADDRSTRLEN + 1];
1776 char ipbuf[INET6_ADDRSTRLEN + 1];
1778 int family = client_addr->sa_family;
1784 src = &(((struct sockaddr_in *)client_addr)->sin_addr);
1788 src = &(((struct sockaddr_in6 *)client_addr)->sin6_addr);
1790 if (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)src))
1793 src = (char*)src + 12;
1798 return eina_stringshare_add("0.0.0.0");
1801 if (!inet_ntop(family, src, ipbuf, sizeof(ipbuf)))
1802 return eina_stringshare_add("0.0.0.0");
1804 ipbuf[sizeof(ipbuf) - 1] = 0;
1805 return eina_stringshare_add(ipbuf);
1809 _ecore_con_svr_tcp_handler(void *data,
1810 Ecore_Fd_Handler *fd_handler __UNUSED__)
1812 Ecore_Con_Server *svr;
1813 Ecore_Con_Client *cl = NULL;
1814 unsigned char client_addr[256];
1815 unsigned int client_addr_len;
1816 const char *clerr = NULL;
1820 return ECORE_CALLBACK_RENEW;
1823 return ECORE_CALLBACK_RENEW;
1825 if ((svr->client_limit >= 0) && (!svr->reject_excess_clients) &&
1826 (svr->client_count >= (unsigned int)svr->client_limit))
1827 return ECORE_CALLBACK_RENEW;
1831 cl = calloc(1, sizeof(Ecore_Con_Client));
1834 ecore_con_event_server_error(svr, "Memory allocation failure when attempting to add a new client");
1835 return ECORE_CALLBACK_RENEW;
1837 cl->host_server = svr;
1839 client_addr_len = sizeof(client_addr);
1840 memset(&client_addr, 0, client_addr_len);
1841 cl->fd = accept(svr->fd, (struct sockaddr *)&client_addr, (socklen_t *)&client_addr_len);
1842 if (cl->fd < 0) goto error;
1843 if ((svr->client_limit >= 0) && (svr->reject_excess_clients) &&
1844 (svr->client_count >= (unsigned int)svr->client_limit))
1846 clerr = "Maximum client limit reached";
1850 if (fcntl(cl->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1851 if (fcntl(cl->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1852 cl->fd_handler = ecore_main_fd_handler_add(cl->fd, ECORE_FD_READ,
1853 _ecore_con_svr_cl_handler, cl, NULL, NULL);
1854 if (!cl->fd_handler) goto error;
1855 ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
1857 if ((!svr->upgrade) && (svr->type & ECORE_CON_SSL))
1859 cl->handshaking = EINA_TRUE;
1860 cl->ssl_state = ECORE_CON_SSL_STATE_INIT;
1861 if (ecore_con_ssl_client_init(cl))
1865 cl->client_addr = malloc(client_addr_len);
1866 if (!cl->client_addr)
1868 clerr = "Memory allocation failure when attempting to add a new client";
1871 cl->client_addr_len = client_addr_len;
1872 memcpy(cl->client_addr, &client_addr, client_addr_len);
1874 svr->clients = eina_list_append(svr->clients, cl);
1875 svr->client_count++;
1877 if ((!cl->delete_me) && (!cl->handshaking))
1878 ecore_con_event_client_add(cl);
1880 return ECORE_CALLBACK_RENEW;
1883 if (cl->fd_handler) ecore_main_fd_handler_del(cl->fd_handler);
1884 if (cl->fd >= 0) close(cl->fd);
1886 if (clerr || errno) ecore_con_event_server_error(svr, clerr ?: strerror(errno));
1887 return ECORE_CALLBACK_RENEW;
1891 _ecore_con_cl_read(Ecore_Con_Server *svr)
1894 Eina_Bool lost_server = EINA_TRUE;
1895 unsigned char buf[READBUFSIZ];
1899 /* only possible with non-ssl connections */
1900 if (svr->connecting && (svr_try_connect_plain(svr) != ECORE_CON_CONNECTED))
1903 if (svr->handshaking && (!svr->ecs_state))
1905 DBG("Continuing ssl handshake");
1906 if (!ecore_con_ssl_server_init(svr))
1907 lost_server = EINA_FALSE;
1908 _ecore_con_server_timer_update(svr);
1911 if (svr->ecs_state || !(svr->type & ECORE_CON_SSL))
1914 num = read(svr->fd, buf, sizeof(buf));
1915 /* 0 is not a valid return value for a tcp socket */
1916 if ((num > 0) || ((num < 0) && (errno == EAGAIN)))
1917 lost_server = EINA_FALSE;
1919 ecore_con_event_server_error(svr, strerror(errno));
1923 num = ecore_con_ssl_server_read(svr, buf, sizeof(buf));
1924 /* this is not an actual 0 return, 0 here just means non-fatal error such as EAGAIN */
1926 lost_server = EINA_FALSE;
1929 if ((!svr->delete_me) && (num > 0))
1932 ecore_con_socks_read(svr, buf, num);
1934 ecore_con_event_server_data(svr, buf, num, EINA_TRUE);
1938 _ecore_con_server_kill(svr);
1942 _ecore_con_cl_handler(void *data,
1943 Ecore_Fd_Handler *fd_handler)
1945 Ecore_Con_Server *svr;
1946 Eina_Bool want_read, want_write;
1950 return ECORE_CALLBACK_RENEW;
1953 return ECORE_CALLBACK_RENEW;
1955 want_read = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ);
1956 want_write = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE);
1958 if ((!svr->ecs_state) && svr->handshaking && (want_read || want_write))
1960 DBG("Continuing ssl handshake: preparing to %s...", want_read ? "read" : "write");
1964 char buf[READBUFSIZ];
1966 len = recv(svr->fd, buf, sizeof(buf), MSG_DONTWAIT | MSG_PEEK);
1967 DBG("%zu bytes in buffer", len);
1970 if (ecore_con_ssl_server_init(svr))
1972 ERR("ssl handshaking failed!");
1973 svr->handshaking = EINA_FALSE;
1975 else if (!svr->ssl_state)
1976 ecore_con_event_server_add(svr);
1977 return ECORE_CALLBACK_RENEW;
1979 if (svr->ecs && svr->ecs_state && (svr->ecs_state < ECORE_CON_PROXY_STATE_READ) && (!svr->ecs_buf))
1981 if (svr->ecs_state < ECORE_CON_PROXY_STATE_INIT)
1983 INF("PROXY STATE++");
1986 if (ecore_con_socks_svr_init(svr)) return ECORE_CALLBACK_RENEW;
1989 _ecore_con_cl_read(svr);
1990 else if (want_write) /* only possible with non-ssl connections */
1992 if (svr->connecting && (!svr_try_connect_plain(svr)) && (!svr->ecs_state))
1993 return ECORE_CALLBACK_RENEW;
1995 _ecore_con_server_flush(svr);
1998 return ECORE_CALLBACK_RENEW;
2002 _ecore_con_cl_udp_handler(void *data,
2003 Ecore_Fd_Handler *fd_handler)
2005 unsigned char buf[READBUFSIZ];
2007 Ecore_Con_Server *svr;
2008 Eina_Bool want_read, want_write;
2010 want_read = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ);
2011 want_write = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE);
2014 if (svr->delete_me || svr->delete_me || ((!want_read) && (!want_write)))
2015 return ECORE_CALLBACK_RENEW;
2019 _ecore_con_server_flush(svr);
2020 return ECORE_CALLBACK_RENEW;
2023 num = read(svr->fd, buf, READBUFSIZ);
2025 if ((!svr->delete_me) && (num > 0))
2026 ecore_con_event_server_data(svr, buf, num, EINA_TRUE);
2028 if (num < 0 && (errno != EAGAIN) && (errno != EINTR))
2030 ecore_con_event_server_error(svr, strerror(errno));
2031 _ecore_con_server_kill(svr);
2034 return ECORE_CALLBACK_RENEW;
2038 _ecore_con_svr_udp_handler(void *data,
2039 Ecore_Fd_Handler *fd_handler)
2041 unsigned char buf[READBUFSIZ];
2042 unsigned char client_addr[256];
2043 socklen_t client_addr_len = sizeof(client_addr);
2045 Ecore_Con_Server *svr;
2046 Ecore_Con_Client *cl = NULL;
2051 return ECORE_CALLBACK_RENEW;
2053 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
2055 _ecore_con_client_flush(cl);
2056 return ECORE_CALLBACK_RENEW;
2059 if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
2060 return ECORE_CALLBACK_RENEW;
2063 num = fcntl(svr->fd, F_SETFL, O_NONBLOCK);
2065 num = recvfrom(svr->fd, (char *)buf, sizeof(buf), 0,
2066 (struct sockaddr *)&client_addr,
2070 num = recvfrom(svr->fd, buf, sizeof(buf), MSG_DONTWAIT,
2071 (struct sockaddr *)&client_addr,
2075 if (num < 0 && (errno != EAGAIN) && (errno != EINTR))
2077 ecore_con_event_server_error(svr, strerror(errno));
2078 if (!svr->delete_me)
2079 ecore_con_event_client_del(NULL);
2080 _ecore_con_server_kill(svr);
2081 return ECORE_CALLBACK_CANCEL;
2085 /* Create a new client for use in the client data event */
2086 cl = calloc(1, sizeof(Ecore_Con_Client));
2087 EINA_SAFETY_ON_NULL_RETURN_VAL(cl, ECORE_CALLBACK_RENEW);
2089 cl->host_server = svr;
2090 cl->client_addr = malloc(client_addr_len);
2091 if (!cl->client_addr)
2094 return ECORE_CALLBACK_RENEW;
2096 cl->client_addr_len = client_addr_len;
2098 memcpy(cl->client_addr, &client_addr, client_addr_len);
2099 ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
2100 svr->clients = eina_list_append(svr->clients, cl);
2101 svr->client_count++;
2103 ecore_con_event_client_add(cl);
2104 ecore_con_event_client_data(cl, buf, num, EINA_TRUE);
2106 return ECORE_CALLBACK_RENEW;
2110 _ecore_con_svr_cl_read(Ecore_Con_Client *cl)
2113 Eina_Bool lost_client = EINA_TRUE;
2114 unsigned char buf[READBUFSIZ];
2118 if (cl->handshaking)
2120 /* add an extra handshake attempt just before read, even though
2121 * read also attempts to handshake, to try to finish sooner
2123 if (ecore_con_ssl_client_init(cl))
2124 lost_client = EINA_FALSE;
2126 _ecore_con_cl_timer_update(cl);
2129 if (!(cl->host_server->type & ECORE_CON_SSL) || (!cl->upgrade))
2131 num = read(cl->fd, buf, sizeof(buf));
2132 /* 0 is not a valid return value for a tcp socket */
2133 if ((num > 0) || ((num < 0) && ((errno == EAGAIN) || (errno == EINTR))))
2134 lost_client = EINA_FALSE;
2136 ecore_con_event_client_error(cl, strerror(errno));
2140 num = ecore_con_ssl_client_read(cl, buf, sizeof(buf));
2141 /* this is not an actual 0 return, 0 here just means non-fatal error such as EAGAIN */
2143 lost_client = EINA_FALSE;
2146 if ((!cl->delete_me) && (num > 0))
2147 ecore_con_event_client_data(cl, buf, num, EINA_TRUE);
2149 if (lost_client) _ecore_con_client_kill(cl);
2153 _ecore_con_svr_cl_handler(void *data,
2154 Ecore_Fd_Handler *fd_handler)
2156 Ecore_Con_Client *cl;
2160 return ECORE_CALLBACK_RENEW;
2162 if (cl->handshaking && ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ | ECORE_FD_WRITE))
2164 if (ecore_con_ssl_client_init(cl))
2166 ERR("ssl handshaking failed!");
2167 _ecore_con_client_kill(cl);
2168 return ECORE_CALLBACK_RENEW;
2170 else if (!cl->ssl_state)
2171 ecore_con_event_client_add(cl);
2173 else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
2174 _ecore_con_svr_cl_read(cl);
2176 else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
2177 _ecore_con_client_flush(cl);
2179 return ECORE_CALLBACK_RENEW;
2183 _ecore_con_server_flush(Ecore_Con_Server *svr)
2186 size_t buf_len, buf_offset;
2189 DBG("(svr=%p,buf=%p)", svr, svr->buf);
2191 if (ecore_con_local_win32_server_flush(svr))
2195 if ((!svr->buf) && (!svr->ecs_buf) && svr->fd_handler)
2197 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
2201 buf = svr->buf ? eina_binbuf_string_get(svr->buf) : eina_binbuf_string_get(svr->ecs_buf);
2202 buf_len = svr->buf ? eina_binbuf_length_get(svr->buf) : eina_binbuf_length_get(svr->ecs_buf);
2203 buf_offset = svr->buf ? svr->write_buf_offset : svr->ecs_buf_offset;
2204 num = buf_len - buf_offset;
2206 /* check whether we need to write anything at all.
2207 * we must not write zero bytes with SSL_write() since it
2208 * causes undefined behaviour
2210 /* we thank Tommy[D] for needing to check negative buffer sizes
2211 * here because his system is amazing.
2213 if (num <= 0) return;
2215 if ((!svr->ecs_state) && svr->handshaking)
2217 DBG("Continuing ssl handshake");
2218 if (ecore_con_ssl_server_init(svr))
2219 _ecore_con_server_kill(svr);
2220 _ecore_con_server_timer_update(svr);
2224 if (svr->ecs_state || (!(svr->type & ECORE_CON_SSL)))
2225 count = write(svr->fd, buf + buf_offset, num);
2227 count = ecore_con_ssl_server_write(svr, buf + buf_offset, num);
2231 if ((errno != EAGAIN) && (errno != EINTR))
2233 ecore_con_event_server_error(svr, strerror(errno));
2234 _ecore_con_server_kill(svr);
2239 if (count && (!svr->ecs_state)) ecore_con_event_server_write(svr, count);
2241 buf_offset = svr->ecs_buf_offset += count;
2243 buf_offset = svr->write_buf_offset += count;
2244 if (buf_offset >= buf_len)
2248 svr->ecs_buf_offset = 0;
2249 eina_binbuf_free(svr->ecs_buf);
2250 svr->ecs_buf = NULL;
2251 INF("PROXY STATE++");
2256 svr->write_buf_offset = 0;
2257 eina_binbuf_free(svr->buf);
2260 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK)
2263 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
2264 /* realistically this isn't anything serious so we can just log and continue */
2265 ERR("uncorking failed! %s", strerror(errno));
2269 if (svr->fd_handler)
2270 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
2272 else if ((count < num) && svr->fd_handler)
2273 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE);
2277 _ecore_con_client_flush(Ecore_Con_Client *cl)
2279 int num = 0, count = 0;
2282 if (ecore_con_local_win32_client_flush(cl))
2286 if (!cl->buf && cl->fd_handler)
2288 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ);
2292 if (cl->handshaking)
2294 if (ecore_con_ssl_client_init(cl))
2297 _ecore_con_cl_timer_update(cl);
2302 num = eina_binbuf_length_get(cl->buf) - cl->buf_offset;
2303 if (num <= 0) return;
2304 if (!(cl->host_server->type & ECORE_CON_SSL) || (!cl->upgrade))
2305 count = write(cl->fd, eina_binbuf_string_get(cl->buf) + cl->buf_offset, num);
2307 count = ecore_con_ssl_client_write(cl, eina_binbuf_string_get(cl->buf) + cl->buf_offset, num);
2312 if ((errno != EAGAIN) && (errno != EINTR) && (!cl->delete_me))
2314 ecore_con_event_client_error(cl, strerror(errno));
2315 _ecore_con_client_kill(cl);
2321 if (count) ecore_con_event_client_write(cl, count);
2322 cl->buf_offset += count, num -= count;
2323 if (cl->buf_offset >= eina_binbuf_length_get(cl->buf))
2326 eina_binbuf_free(cl->buf);
2329 if ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK)
2332 if (setsockopt(cl->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
2333 /* realistically this isn't anything serious so we can just log and continue */
2334 ERR("uncorking failed! %s", strerror(errno));
2338 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ);
2340 else if (cl->fd_handler && (num >= 0))
2341 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_WRITE);
2345 _ecore_con_event_client_add_free(Ecore_Con_Server *svr,
2348 Ecore_Con_Event_Client_Add *e;
2353 e->client->event_count = eina_list_remove(e->client->event_count, e);
2354 if (e->client->host_server)
2356 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, ev);
2357 if ((!svr->event_count) && (svr->delete_me))
2358 _ecore_con_server_free(svr);
2360 if ((!e->client->event_count) && (e->client->delete_me))
2361 ecore_con_client_del(e->client);
2364 ecore_con_event_client_add_free(e);
2365 _ecore_con_event_count--;
2366 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2367 ecore_con_mempool_shutdown();
2371 _ecore_con_event_client_del_free(Ecore_Con_Server *svr,
2374 Ecore_Con_Event_Client_Del *e;
2379 e->client->event_count = eina_list_remove(e->client->event_count, e);
2380 if (e->client->host_server)
2382 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, ev);
2383 if ((!svr->event_count) && (svr->delete_me))
2384 _ecore_con_server_free(svr);
2386 if (!e->client->event_count)
2387 _ecore_con_client_free(e->client);
2389 ecore_con_event_client_del_free(e);
2390 _ecore_con_event_count--;
2391 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2392 ecore_con_mempool_shutdown();
2396 _ecore_con_event_client_write_free(Ecore_Con_Server *svr,
2397 Ecore_Con_Event_Client_Write *e)
2401 e->client->event_count = eina_list_remove(e->client->event_count, e);
2402 if (e->client->host_server)
2404 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, e);
2405 if ((!svr->event_count) && (svr->delete_me))
2406 _ecore_con_server_free(svr);
2408 if (((!e->client->event_count) && (e->client->delete_me)) ||
2409 ((e->client->host_server &&
2410 ((e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP ||
2411 (e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_MCAST))))
2412 ecore_con_client_del(e->client);
2414 ecore_con_event_client_write_free(e);
2415 _ecore_con_event_count--;
2416 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2417 ecore_con_mempool_shutdown();
2421 _ecore_con_event_client_data_free(Ecore_Con_Server *svr,
2424 Ecore_Con_Event_Client_Data *e;
2429 e->client->event_count = eina_list_remove(e->client->event_count, e);
2430 if (e->client->host_server)
2432 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, ev);
2434 if ((!svr->event_count) && (svr->delete_me))
2435 _ecore_con_server_free(svr);
2436 if (((!e->client->event_count) && (e->client->delete_me)) ||
2437 ((e->client->host_server &&
2438 ((e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP ||
2439 (e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_MCAST))))
2440 ecore_con_client_del(e->client);
2443 ecore_con_event_client_data_free(e);
2444 _ecore_con_event_count--;
2445 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2446 ecore_con_mempool_shutdown();
2450 _ecore_con_event_server_add_free(void *data __UNUSED__,
2453 Ecore_Con_Event_Server_Add *e;
2458 e->server->event_count = eina_list_remove(e->server->event_count, ev);
2459 if ((!e->server->event_count) && (e->server->delete_me))
2460 _ecore_con_server_free(e->server);
2462 ecore_con_event_server_add_free(e);
2463 _ecore_con_event_count--;
2464 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2465 ecore_con_mempool_shutdown();
2469 _ecore_con_event_server_del_free(void *data __UNUSED__,
2472 Ecore_Con_Event_Server_Del *e;
2477 e->server->event_count = eina_list_remove(e->server->event_count, ev);
2478 if (!e->server->event_count)
2479 _ecore_con_server_free(e->server);
2481 ecore_con_event_server_del_free(e);
2482 _ecore_con_event_count--;
2483 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2484 ecore_con_mempool_shutdown();
2488 _ecore_con_event_server_write_free(void *data __UNUSED__,
2489 Ecore_Con_Event_Server_Write *e)
2493 e->server->event_count = eina_list_remove(e->server->event_count, e);
2494 if ((!e->server->event_count) && (e->server->delete_me))
2495 _ecore_con_server_free(e->server);
2498 ecore_con_event_server_write_free(e);
2499 _ecore_con_event_count--;
2500 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2501 ecore_con_mempool_shutdown();
2505 _ecore_con_event_server_data_free(void *data __UNUSED__,
2508 Ecore_Con_Event_Server_Data *e;
2513 e->server->event_count = eina_list_remove(e->server->event_count, ev);
2514 if ((!e->server->event_count) && (e->server->delete_me))
2515 _ecore_con_server_free(e->server);
2519 ecore_con_event_server_data_free(e);
2520 _ecore_con_event_count--;
2521 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2522 ecore_con_mempool_shutdown();
2527 _ecore_con_event_server_error_free(void *data __UNUSED__, Ecore_Con_Event_Server_Error *e)
2531 e->server->event_count = eina_list_remove(e->server->event_count, e);
2532 if ((!e->server->event_count) && (e->server->delete_me))
2533 _ecore_con_server_free(e->server);
2536 ecore_con_event_server_error_free(e);
2537 _ecore_con_event_count--;
2538 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2539 ecore_con_mempool_shutdown();
2543 _ecore_con_event_client_error_free(Ecore_Con_Server *svr, Ecore_Con_Event_Client_Error *e)
2547 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, e);
2548 if ((!e->client->event_count) && (e->client->delete_me))
2549 _ecore_con_client_free(e->client);
2550 if (e->client->host_server)
2552 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, e);
2553 if ((!svr->event_count) && (svr->delete_me))
2554 _ecore_con_server_free(svr);
2558 ecore_con_event_client_error_free(e);
2559 _ecore_con_event_count--;
2560 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2561 ecore_con_mempool_shutdown();
2565 _ecore_con_lookup_done(void *data,
2566 Ecore_Con_Info *infos)
2568 Ecore_Con_Server *svr;
2569 Ecore_Con_Lookup *lk;
2575 lk->done_cb(infos->info.ai_canonname, infos->ip,
2576 infos->info.ai_addr, infos->info.ai_addrlen,
2579 lk->done_cb(NULL, NULL, NULL, 0, (void *)lk->data);