17 # define alloca __builtin_alloca
19 # define alloca __alloca
20 # elif defined _MSC_VER
22 # define alloca _alloca
23 # elif !defined HAVE_ALLOCA
27 void *alloca (size_t);
33 #include <sys/types.h>
39 #ifdef HAVE_NETINET_TCP_H
40 # include <netinet/tcp.h>
43 #ifdef HAVE_NETINET_IN_H
44 # include <netinet/in.h>
47 #ifdef HAVE_ARPA_INET_H
48 # include <arpa/inet.h>
51 #ifdef HAVE_SYS_SOCKET_H
52 # include <sys/socket.h>
59 #ifdef HAVE_WS2TCPIP_H
60 # include <ws2tcpip.h>
68 #include "ecore_private.h"
69 #include "Ecore_Con.h"
70 #include "ecore_con_private.h"
72 static Eina_Bool _ecore_con_client_timer(Ecore_Con_Client *cl);
73 static void _ecore_con_cl_timer_update(Ecore_Con_Client *cl);
74 static Eina_Bool _ecore_con_server_timer(Ecore_Con_Server *svr);
75 static void _ecore_con_server_timer_update(Ecore_Con_Server *svr);
77 static void _ecore_con_cb_tcp_connect(void *data,
78 Ecore_Con_Info *info);
79 static void _ecore_con_cb_udp_connect(void *data,
80 Ecore_Con_Info *info);
81 static void _ecore_con_cb_tcp_listen(void *data,
82 Ecore_Con_Info *info);
83 static void _ecore_con_cb_udp_listen(void *data,
84 Ecore_Con_Info *info);
86 static void _ecore_con_server_free(Ecore_Con_Server *svr);
87 static void _ecore_con_client_free(Ecore_Con_Client *cl);
89 static void _ecore_con_cl_read(Ecore_Con_Server *svr);
90 static Eina_Bool _ecore_con_svr_tcp_handler(void *data,
91 Ecore_Fd_Handler *fd_handler);
92 static Eina_Bool _ecore_con_cl_handler(void *data,
93 Ecore_Fd_Handler *fd_handler);
94 static Eina_Bool _ecore_con_cl_udp_handler(void *data,
95 Ecore_Fd_Handler *fd_handler);
96 static Eina_Bool _ecore_con_svr_udp_handler(void *data,
97 Ecore_Fd_Handler *fd_handler);
99 static void _ecore_con_svr_cl_read(Ecore_Con_Client *cl);
100 static Eina_Bool _ecore_con_svr_cl_handler(void *data,
101 Ecore_Fd_Handler *fd_handler);
103 static void _ecore_con_server_flush(Ecore_Con_Server *svr);
104 static void _ecore_con_client_flush(Ecore_Con_Client *cl);
106 static void _ecore_con_event_client_add_free(Ecore_Con_Server *svr,
108 static void _ecore_con_event_client_del_free(Ecore_Con_Server *svr,
110 static void _ecore_con_event_client_data_free(Ecore_Con_Server *svr,
112 static void _ecore_con_event_server_add_free(void *data,
114 static void _ecore_con_event_server_del_free(void *data,
116 static void _ecore_con_event_server_data_free(void *data,
118 static void _ecore_con_event_server_error_free(void *data,
119 Ecore_Con_Event_Server_Error *e);
120 static void _ecore_con_event_client_error_free(Ecore_Con_Server *svr,
121 Ecore_Con_Event_Client_Error *e);
122 static void _ecore_con_event_server_write_free(void *data,
123 Ecore_Con_Event_Server_Write *e);
124 static void _ecore_con_event_client_write_free(Ecore_Con_Server *svr,
125 Ecore_Con_Event_Client_Write *e);
127 static void _ecore_con_lookup_done(void *data,
128 Ecore_Con_Info *infos);
130 static const char * _ecore_con_pretty_ip(struct sockaddr *client_addr);
134 _ecore_con_client_kill(Ecore_Con_Client *cl)
137 DBG("Multi kill request for client %p", cl);
140 ecore_con_event_client_del(cl);
143 INF("Lost client %s", (cl->ip) ? cl->ip : "");
145 ecore_main_fd_handler_del(cl->fd_handler);
147 cl->fd_handler = NULL;
151 _ecore_con_server_kill(Ecore_Con_Server *svr)
154 DBG("Multi kill request for svr %p", svr);
156 ecore_con_event_server_del(svr);
159 ecore_main_fd_handler_del(svr->fd_handler);
161 svr->fd_handler = NULL;
164 #define _ecore_con_server_kill(svr) do { \
165 DBG("KILL %p", (svr)); \
166 _ecore_con_server_kill((svr)); \
169 #define _ecore_con_client_kill(cl) do { \
170 DBG("KILL %p", (cl)); \
171 _ecore_con_client_kill((cl)); \
174 EAPI int ECORE_CON_EVENT_CLIENT_ADD = 0;
175 EAPI int ECORE_CON_EVENT_CLIENT_DEL = 0;
176 EAPI int ECORE_CON_EVENT_SERVER_ADD = 0;
177 EAPI int ECORE_CON_EVENT_SERVER_DEL = 0;
178 EAPI int ECORE_CON_EVENT_CLIENT_DATA = 0;
179 EAPI int ECORE_CON_EVENT_SERVER_DATA = 0;
180 EAPI int ECORE_CON_EVENT_CLIENT_WRITE = 0;
181 EAPI int ECORE_CON_EVENT_SERVER_WRITE = 0;
182 EAPI int ECORE_CON_EVENT_CLIENT_ERROR = 0;
183 EAPI int ECORE_CON_EVENT_SERVER_ERROR = 0;
184 EAPI int ECORE_CON_EVENT_PROXY_BIND = 0;
186 static Eina_List *servers = NULL;
187 static int _ecore_con_init_count = 0;
188 static int _ecore_con_event_count = 0;
189 int _ecore_con_log_dom = -1;
190 Ecore_Con_Socks *_ecore_con_proxy_once = NULL;
191 Ecore_Con_Socks *_ecore_con_proxy_global = NULL;
196 if (++_ecore_con_init_count != 1)
197 return _ecore_con_init_count;
201 return --_ecore_con_init_count;
206 return --_ecore_con_init_count;
208 _ecore_con_log_dom = eina_log_domain_register
209 ("ecore_con", ECORE_CON_DEFAULT_LOG_COLOR);
210 if (_ecore_con_log_dom < 0)
212 EINA_LOG_ERR("Impossible to create a log domain for Ecore Con.");
214 return --_ecore_con_init_count;
217 ecore_con_mempool_init();
219 ECORE_CON_EVENT_CLIENT_ADD = ecore_event_type_new();
220 ECORE_CON_EVENT_CLIENT_DEL = ecore_event_type_new();
221 ECORE_CON_EVENT_SERVER_ADD = ecore_event_type_new();
222 ECORE_CON_EVENT_SERVER_DEL = ecore_event_type_new();
223 ECORE_CON_EVENT_CLIENT_DATA = ecore_event_type_new();
224 ECORE_CON_EVENT_SERVER_DATA = ecore_event_type_new();
225 ECORE_CON_EVENT_CLIENT_WRITE = ecore_event_type_new();
226 ECORE_CON_EVENT_SERVER_WRITE = ecore_event_type_new();
227 ECORE_CON_EVENT_CLIENT_ERROR = ecore_event_type_new();
228 ECORE_CON_EVENT_SERVER_ERROR = ecore_event_type_new();
229 ECORE_CON_EVENT_PROXY_BIND = ecore_event_type_new();
232 eina_magic_string_set(ECORE_MAGIC_CON_SERVER, "Ecore_Con_Server");
233 eina_magic_string_set(ECORE_MAGIC_CON_CLIENT, "Ecore_Con_Client");
234 eina_magic_string_set(ECORE_MAGIC_CON_URL, "Ecore_Con_Url");
236 /* TODO Remember return value, if it fails, use gethostbyname() */
237 ecore_con_socks_init();
238 ecore_con_ssl_init();
239 ecore_con_info_init();
241 return _ecore_con_init_count;
245 ecore_con_shutdown(void)
248 Ecore_Con_Server *svr;
250 if (--_ecore_con_init_count != 0)
251 return _ecore_con_init_count;
253 EINA_LIST_FOREACH_SAFE(servers, l, l2, svr)
255 Ecore_Con_Event_Server_Add *ev;
257 svr->delete_me = EINA_TRUE;
258 INF("svr %p is dead", svr);
259 /* some pointer hacks here to prevent double frees if people are being stupid */
260 EINA_LIST_FREE(svr->event_count, ev)
262 _ecore_con_server_free(svr);
265 ecore_con_socks_shutdown();
266 if (!_ecore_con_event_count) ecore_con_mempool_shutdown();
268 ecore_con_info_shutdown();
269 ecore_con_ssl_shutdown();
270 eina_log_domain_unregister(_ecore_con_log_dom);
271 _ecore_con_log_dom = -1;
277 return _ecore_con_init_count;
281 ecore_con_lookup(const char *name,
282 Ecore_Con_Dns_Cb done_cb,
285 Ecore_Con_Server *svr;
286 Ecore_Con_Lookup *lk;
287 struct addrinfo hints;
289 if (!name || !done_cb)
292 svr = calloc(1, sizeof(Ecore_Con_Server));
296 lk = malloc(sizeof (Ecore_Con_Lookup));
303 lk->done_cb = done_cb;
306 svr->name = strdup(name);
310 svr->type = ECORE_CON_REMOTE_TCP;
313 svr->created = EINA_TRUE;
314 svr->reject_excess_clients = EINA_FALSE;
315 svr->client_limit = -1;
317 svr->ppid = getpid();
319 memset(&hints, 0, sizeof(struct addrinfo));
320 hints.ai_family = AF_UNSPEC;
321 hints.ai_socktype = SOCK_STREAM;
322 hints.ai_flags = AI_CANONNAME;
323 hints.ai_protocol = IPPROTO_TCP;
324 hints.ai_canonname = NULL;
325 hints.ai_next = NULL;
326 hints.ai_addr = NULL;
328 if (ecore_con_info_get(svr, _ecore_con_lookup_done, svr,
340 * @addtogroup Ecore_Con_Server_Group Ecore Connection Server Functions
342 * Functions that operate on Ecore server objects.
348 * @example ecore_con_server_example.c
349 * Shows how to write a simple server using the Ecore_Con library.
352 EAPI Ecore_Con_Server *
353 ecore_con_server_add(Ecore_Con_Type compl_type,
358 Ecore_Con_Server *svr;
361 if (port < 0 || !name)
362 return NULL; /* local user socket: FILE: ~/.ecore/[name]/[port] */
364 /* local system socket: FILE: /tmp/.ecore_service|[name]|[port] */
365 /* remote system socket: TCP/IP: [name]:[port] */
366 svr = calloc(1, sizeof(Ecore_Con_Server));
370 svr->name = strdup(name);
374 svr->type = compl_type;
376 svr->data = (void *)data;
377 svr->created = EINA_TRUE;
378 svr->use_cert = (compl_type & ECORE_CON_SSL & ECORE_CON_LOAD_CERT) == ECORE_CON_LOAD_CERT;
379 svr->reject_excess_clients = EINA_FALSE;
380 svr->client_limit = -1;
382 svr->ppid = getpid();
383 if (ecore_con_ssl_server_prepare(svr, compl_type & ECORE_CON_SSL))
386 type = compl_type & ECORE_CON_TYPE;
388 if ((type == ECORE_CON_LOCAL_USER) ||
389 (type == ECORE_CON_LOCAL_SYSTEM) ||
390 (type == ECORE_CON_LOCAL_ABSTRACT))
393 if (!ecore_con_local_listen(svr))
396 if (!ecore_con_local_listen(svr, _ecore_con_svr_tcp_handler, svr))
400 if ((type == ECORE_CON_REMOTE_TCP) ||
401 (type == ECORE_CON_REMOTE_NODELAY) ||
402 (type == ECORE_CON_REMOTE_CORK))
405 if (!ecore_con_info_tcp_listen(svr, _ecore_con_cb_tcp_listen,
409 else if ((type == ECORE_CON_REMOTE_MCAST) ||
410 (type == ECORE_CON_REMOTE_UDP))
412 if (!ecore_con_info_udp_listen(svr, _ecore_con_cb_udp_listen,
416 servers = eina_list_append(servers, svr);
417 ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER);
430 ecore_main_fd_handler_del(svr->fd_handler);
436 eina_binbuf_free(svr->buf);
439 eina_stringshare_del(svr->ip);
441 ecore_con_ssl_server_shutdown(svr);
446 EAPI Ecore_Con_Server *
447 ecore_con_server_connect(Ecore_Con_Type compl_type,
452 Ecore_Con_Server *svr;
455 if ((!name) || (!name[0]))
457 /* local user socket: FILE: ~/.ecore/[name]/[port] */
458 /* local system socket: FILE: /tmp/.ecore_service|[name]|[port] */
459 /* remote system socket: TCP/IP: [name]:[port] */
460 svr = calloc(1, sizeof(Ecore_Con_Server));
464 svr->name = strdup(name);
468 svr->type = compl_type;
470 svr->data = (void *)data;
471 svr->created = EINA_FALSE;
472 svr->use_cert = (compl_type & ECORE_CON_SSL & ECORE_CON_LOAD_CERT) == ECORE_CON_LOAD_CERT;
473 svr->disable_proxy = (compl_type & ECORE_CON_SUPER_SSL & ECORE_CON_NO_PROXY) == ECORE_CON_NO_PROXY;
474 svr->reject_excess_clients = EINA_FALSE;
476 svr->client_limit = -1;
478 type = compl_type & ECORE_CON_TYPE;
480 if ((!svr->disable_proxy) && (type > ECORE_CON_LOCAL_ABSTRACT))
482 /* never use proxies on local connections */
483 if (_ecore_con_proxy_once)
484 svr->ecs = _ecore_con_proxy_once;
485 else if (_ecore_con_proxy_global)
486 svr->ecs = _ecore_con_proxy_global;
487 _ecore_con_proxy_once = NULL;
490 if ((!svr->ecs->lookup) &&
491 (!ecore_con_lookup(svr->name, (Ecore_Con_Dns_Cb)ecore_con_socks_dns_cb, svr)))
493 if (svr->ecs->lookup)
494 svr->ecs_state = ECORE_CON_PROXY_STATE_RESOLVED;
497 EINA_SAFETY_ON_TRUE_GOTO(ecore_con_ssl_server_prepare(svr, compl_type & ECORE_CON_SSL), error);
499 EINA_SAFETY_ON_TRUE_GOTO(((type == ECORE_CON_REMOTE_TCP) ||
500 (type == ECORE_CON_REMOTE_NODELAY) ||
501 (type == ECORE_CON_REMOTE_CORK) ||
502 (type == ECORE_CON_REMOTE_UDP) ||
503 (type == ECORE_CON_REMOTE_BROADCAST)) &&
506 if ((type == ECORE_CON_LOCAL_USER) ||
507 (type == ECORE_CON_LOCAL_SYSTEM) ||
508 (type == ECORE_CON_LOCAL_ABSTRACT))
511 EINA_SAFETY_ON_FALSE_GOTO(ecore_con_local_connect(svr, _ecore_con_cl_handler), error);
513 EINA_SAFETY_ON_FALSE_GOTO(ecore_con_local_connect(svr, _ecore_con_cl_handler, svr), error);
516 if ((type == ECORE_CON_REMOTE_TCP) ||
517 (type == ECORE_CON_REMOTE_NODELAY) ||
518 (type == ECORE_CON_REMOTE_CORK))
521 EINA_SAFETY_ON_FALSE_GOTO(ecore_con_info_tcp_connect(svr, _ecore_con_cb_tcp_connect, svr), error);
523 else if ((type == ECORE_CON_REMOTE_UDP) || (type == ECORE_CON_REMOTE_BROADCAST))
525 EINA_SAFETY_ON_FALSE_GOTO(ecore_con_info_udp_connect(svr, _ecore_con_cb_udp_connect, svr), error);
527 servers = eina_list_append(servers, svr);
528 ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER);
540 ecore_main_fd_handler_del(svr->fd_handler);
545 ecore_con_ssl_server_shutdown(svr);
551 ecore_con_server_timeout_set(Ecore_Con_Server *svr,
554 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
556 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_timeout_set");
561 svr->client_disconnect_time = timeout;
563 svr->disconnect_time = timeout;
567 ecore_con_server_timeout_get(Ecore_Con_Server *svr)
569 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
571 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_timeout_get");
575 return svr->created ? svr->client_disconnect_time : svr->disconnect_time;
579 ecore_con_server_del(Ecore_Con_Server *svr)
581 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
583 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_del");
590 _ecore_con_server_kill(svr);
595 ecore_con_server_data_get(Ecore_Con_Server *svr)
597 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
599 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_data_get");
607 ecore_con_server_data_set(Ecore_Con_Server *svr,
612 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
614 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_data_get");
624 ecore_con_server_connected_get(Ecore_Con_Server *svr)
626 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
628 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_connected_get");
638 EAPI const Eina_List *
639 ecore_con_server_clients_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_clients_get");
652 ecore_con_server_name_get(Ecore_Con_Server *svr)
654 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
656 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
657 "ecore_con_server_name_get");
665 ecore_con_server_port_get(Ecore_Con_Server *svr)
667 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
669 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
670 "ecore_con_server_port_get");
677 ecore_con_server_send(Ecore_Con_Server *svr,
681 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
683 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_send");
687 EINA_SAFETY_ON_TRUE_RETURN_VAL(svr->delete_me, 0);
689 EINA_SAFETY_ON_NULL_RETURN_VAL(data, 0);
691 EINA_SAFETY_ON_TRUE_RETURN_VAL(size < 1, 0);
694 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE);
698 svr->buf = eina_binbuf_new();
699 EINA_SAFETY_ON_NULL_RETURN_VAL(svr->buf, 0);
701 if ((svr->fd >= 0) && ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK))
704 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
705 /* realistically this isn't anything serious so we can just log and continue */
706 ERR("corking failed! %s", strerror(errno));
710 eina_binbuf_append_length(svr->buf, data, size);
716 ecore_con_server_client_limit_set(Ecore_Con_Server *svr,
718 char reject_excess_clients)
720 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
722 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
723 "ecore_con_server_client_limit_set");
727 svr->client_limit = client_limit;
728 svr->reject_excess_clients = reject_excess_clients;
732 ecore_con_server_ip_get(Ecore_Con_Server *svr)
734 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
736 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_ip_get");
744 ecore_con_server_uptime_get(Ecore_Con_Server *svr)
746 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
748 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_uptime_get");
752 return ecore_time_get() - svr->start_time;
756 ecore_con_server_flush(Ecore_Con_Server *svr)
758 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
760 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_flush");
764 _ecore_con_server_flush(svr);
772 * @addtogroup Ecore_Con_Client_Group Ecore Connection Client Functions
774 * Functions that operate on Ecore connection client objects.
780 * @example ecore_con_client_example.c
781 * Shows how to write a simple client that connects to the example server.
785 ecore_con_client_send(Ecore_Con_Client *cl,
789 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
791 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_send");
795 EINA_SAFETY_ON_TRUE_RETURN_VAL(cl->delete_me, 0);
797 EINA_SAFETY_ON_NULL_RETURN_VAL(data, 0);
799 EINA_SAFETY_ON_TRUE_RETURN_VAL(size < 1, 0);
802 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE);
804 if (cl->host_server && ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP))
805 sendto(cl->host_server->fd, data, size, 0, (struct sockaddr *)cl->client_addr,
806 cl->client_addr_len);
809 cl->buf = eina_binbuf_new();
810 EINA_SAFETY_ON_NULL_RETURN_VAL(cl->buf, 0);
812 if ((cl->fd >= 0) && ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK))
815 if (setsockopt(cl->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
816 /* realistically this isn't anything serious so we can just log and continue */
817 ERR("corking failed! %s", strerror(errno));
821 eina_binbuf_append_length(cl->buf, data, size);
826 EAPI Ecore_Con_Server *
827 ecore_con_client_server_get(Ecore_Con_Client *cl)
829 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
831 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
832 "ecore_con_client_server_get");
836 return cl->host_server;
840 ecore_con_client_connected_get(Ecore_Con_Client *cl)
842 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
844 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
845 "ecore_con_client_connected_get");
849 return !cl->delete_me;
853 ecore_con_client_timeout_set(Ecore_Con_Client *cl,
856 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
858 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
859 "ecore_con_client_timeout_set");
863 cl->disconnect_time = timeout;
865 _ecore_con_cl_timer_update(cl);
869 ecore_con_client_timeout_get(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_timeout_get");
877 return cl->disconnect_time;
881 ecore_con_client_del(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_del");
889 _ecore_con_client_kill(cl);
894 ecore_con_client_data_set(Ecore_Con_Client *cl,
897 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
899 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_data_set");
903 cl->data = (void *)data;
907 ecore_con_client_data_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_data_get");
919 ecore_con_client_ip_get(Ecore_Con_Client *cl)
921 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
923 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_ip_get");
927 cl->ip = _ecore_con_pretty_ip(cl->client_addr);
933 ecore_con_client_port_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_port_get");
940 if (cl->client_addr->sa_family == AF_INET)
941 return ((struct sockaddr_in*)cl->client_addr)->sin_port;
943 return ((struct sockaddr_in6*)cl->client_addr)->sin6_port;
950 ecore_con_client_uptime_get(Ecore_Con_Client *cl)
952 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
954 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_uptime_get");
958 return ecore_time_get() - cl->start_time;
962 ecore_con_client_flush(Ecore_Con_Client *cl)
964 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
966 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_flush");
970 _ecore_con_client_flush(cl);
974 ecore_con_server_fd_get(Ecore_Con_Server *svr)
976 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
978 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, __func__);
981 if (svr->created) return -1;
982 if (svr->delete_me) return -1;
983 return ecore_main_fd_handler_fd_get(svr->fd_handler);
987 ecore_con_client_fd_get(Ecore_Con_Client *cl)
989 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
991 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, __func__);
994 return ecore_main_fd_handler_fd_get(cl->fd_handler);
1002 ecore_con_event_proxy_bind(Ecore_Con_Server *svr)
1004 Ecore_Con_Event_Proxy_Bind *e;
1005 int ev = ECORE_CON_EVENT_PROXY_BIND;
1007 e = ecore_con_event_proxy_bind_alloc();
1008 EINA_SAFETY_ON_NULL_RETURN(e);
1010 svr->event_count = eina_list_append(svr->event_count, e);
1011 _ecore_con_server_timer_update(svr);
1013 e->ip = svr->proxyip;
1014 e->port = svr->proxyport;
1015 ecore_event_add(ev, e,
1016 _ecore_con_event_server_add_free, NULL);
1017 _ecore_con_event_count++;
1021 ecore_con_event_server_add(Ecore_Con_Server *svr)
1023 /* we got our server! */
1024 Ecore_Con_Event_Server_Add *e;
1025 int ev = ECORE_CON_EVENT_SERVER_ADD;
1027 e = ecore_con_event_server_add_alloc();
1028 EINA_SAFETY_ON_NULL_RETURN(e);
1030 svr->connecting = EINA_FALSE;
1031 svr->start_time = ecore_time_get();
1032 svr->event_count = eina_list_append(svr->event_count, e);
1033 _ecore_con_server_timer_update(svr);
1035 if (svr->upgrade) ev = ECORE_CON_EVENT_SERVER_UPGRADE;
1036 ecore_event_add(ev, e,
1037 _ecore_con_event_server_add_free, NULL);
1038 _ecore_con_event_count++;
1042 ecore_con_event_server_del(Ecore_Con_Server *svr)
1044 Ecore_Con_Event_Server_Del *e;
1046 svr->delete_me = EINA_TRUE;
1047 INF("svr %p is dead", svr);
1048 e = ecore_con_event_server_del_alloc();
1049 EINA_SAFETY_ON_NULL_RETURN(e);
1051 svr->event_count = eina_list_append(svr->event_count, e);
1052 _ecore_con_server_timer_update(svr);
1056 svr->ecs_state = svr->ecs->lookup ? ECORE_CON_PROXY_STATE_RESOLVED : ECORE_CON_PROXY_STATE_DONE;
1057 eina_stringshare_replace(&svr->proxyip, NULL);
1060 ecore_event_add(ECORE_CON_EVENT_SERVER_DEL, e,
1061 _ecore_con_event_server_del_free, NULL);
1062 _ecore_con_event_count++;
1066 ecore_con_event_server_write(Ecore_Con_Server *svr, int num)
1068 Ecore_Con_Event_Server_Write *e;
1070 e = ecore_con_event_server_write_alloc();
1071 EINA_SAFETY_ON_NULL_RETURN(e);
1073 INF("Wrote %d bytes", num);
1074 svr->event_count = eina_list_append(svr->event_count, e);
1077 ecore_event_add(ECORE_CON_EVENT_SERVER_WRITE, e,
1078 (Ecore_End_Cb)_ecore_con_event_server_write_free, NULL);
1079 _ecore_con_event_count++;
1083 ecore_con_event_server_data(Ecore_Con_Server *svr, unsigned char *buf, int num, Eina_Bool duplicate)
1085 Ecore_Con_Event_Server_Data *e;
1087 e = ecore_con_event_server_data_alloc();
1088 EINA_SAFETY_ON_NULL_RETURN(e);
1090 svr->event_count = eina_list_append(svr->event_count, e);
1091 _ecore_con_server_timer_update(svr);
1095 e->data = malloc(num);
1098 ERR("server data allocation failure !");
1099 _ecore_con_event_server_data_free(NULL, e);
1102 memcpy(e->data, buf, num);
1107 ecore_event_add(ECORE_CON_EVENT_SERVER_DATA, e,
1108 _ecore_con_event_server_data_free, NULL);
1109 _ecore_con_event_count++;
1113 ecore_con_event_client_add(Ecore_Con_Client *cl)
1115 Ecore_Con_Event_Client_Add *e;
1116 int ev = ECORE_CON_EVENT_CLIENT_ADD;
1118 e = ecore_con_event_client_add_alloc();
1119 EINA_SAFETY_ON_NULL_RETURN(e);
1121 cl->event_count = eina_list_append(cl->event_count, e);
1122 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1123 _ecore_con_cl_timer_update(cl);
1125 if (cl->upgrade) ev = ECORE_CON_EVENT_CLIENT_UPGRADE;
1126 ecore_event_add(ev, e,
1127 (Ecore_End_Cb)_ecore_con_event_client_add_free, cl->host_server);
1128 _ecore_con_event_count++;
1132 ecore_con_event_client_del(Ecore_Con_Client *cl)
1134 Ecore_Con_Event_Client_Del *e;
1137 cl->delete_me = EINA_TRUE;
1138 INF("cl %p is dead", cl);
1139 e = ecore_con_event_client_del_alloc();
1140 EINA_SAFETY_ON_NULL_RETURN(e);
1141 cl->event_count = eina_list_append(cl->event_count, e);
1143 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1144 _ecore_con_cl_timer_update(cl);
1146 ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
1147 (Ecore_End_Cb)_ecore_con_event_client_del_free, cl->host_server);
1148 _ecore_con_event_count++;
1152 ecore_con_event_client_write(Ecore_Con_Client *cl, int num)
1154 Ecore_Con_Event_Client_Write *e;
1156 e = ecore_con_event_client_write_alloc();
1157 EINA_SAFETY_ON_NULL_RETURN(e);
1159 cl->event_count = eina_list_append(cl->event_count, e);
1160 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1163 ecore_event_add(ECORE_CON_EVENT_CLIENT_WRITE, e,
1164 (Ecore_End_Cb)_ecore_con_event_client_write_free, cl->host_server);
1165 _ecore_con_event_count++;
1169 ecore_con_event_client_data(Ecore_Con_Client *cl, unsigned char *buf, int num, Eina_Bool duplicate)
1171 Ecore_Con_Event_Client_Data *e;
1173 e = ecore_con_event_client_data_alloc();
1174 EINA_SAFETY_ON_NULL_RETURN(e);
1176 cl->event_count = eina_list_append(cl->event_count, e);
1177 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1178 _ecore_con_cl_timer_update(cl);
1182 e->data = malloc(num);
1185 ERR("client data allocation failure !");
1186 _ecore_con_event_client_data_free(cl->host_server, e);
1189 memcpy(e->data, buf, num);
1194 ecore_event_add(ECORE_CON_EVENT_CLIENT_DATA, e,
1195 (Ecore_End_Cb)_ecore_con_event_client_data_free, cl->host_server);
1196 _ecore_con_event_count++;
1201 ecore_con_server_infos_del(Ecore_Con_Server *svr, void *info)
1203 svr->infos = eina_list_remove(svr->infos, info);
1207 _ecore_con_event_server_error(Ecore_Con_Server *svr, char *error, Eina_Bool duplicate)
1209 Ecore_Con_Event_Server_Error *e;
1211 e = ecore_con_event_server_error_alloc();
1212 EINA_SAFETY_ON_NULL_RETURN(e);
1215 e->error = duplicate ? strdup(error) : error;
1217 svr->event_count = eina_list_append(svr->event_count, e);
1218 ecore_event_add(ECORE_CON_EVENT_SERVER_ERROR, e, (Ecore_End_Cb)_ecore_con_event_server_error_free, NULL);
1219 _ecore_con_event_count++;
1223 ecore_con_event_client_error(Ecore_Con_Client *cl, const char *error)
1225 Ecore_Con_Event_Client_Error *e;
1227 e = ecore_con_event_client_error_alloc();
1228 EINA_SAFETY_ON_NULL_RETURN(e);
1231 e->error = strdup(error);
1233 cl->event_count = eina_list_append(cl->event_count, e);
1234 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1235 ecore_event_add(ECORE_CON_EVENT_CLIENT_ERROR, e, (Ecore_End_Cb)_ecore_con_event_client_error_free, cl->host_server);
1236 _ecore_con_event_count++;
1240 _ecore_con_server_free(Ecore_Con_Server *svr)
1242 Ecore_Con_Client *cl;
1245 if (svr->event_count) return;
1249 ecore_con_info_data_clear(svr->infos->data);
1250 svr->infos = eina_list_remove_list(svr->infos, svr->infos);
1253 t_start = ecore_time_get();
1254 while (svr->buf && (!svr->delete_me))
1256 _ecore_con_server_flush(svr);
1257 t = ecore_time_get();
1258 if ((t - t_start) > 0.5)
1260 WRN("ECORE_CON: EEK - stuck in _ecore_con_server_free() trying\n"
1261 " to flush data out from the server, and have been for\n"
1262 " %1.1f seconds. This is taking too long. Aborting flush.",
1269 ecore_con_local_win32_server_del(svr);
1271 if (svr->event_count) return;
1272 ECORE_MAGIC_SET(svr, ECORE_MAGIC_NONE);
1275 eina_binbuf_free(svr->buf);
1277 EINA_LIST_FREE(svr->clients, cl)
1279 Ecore_Con_Event_Server_Add *ev;
1281 /* some pointer hacks here to prevent double frees if people are being stupid */
1282 EINA_LIST_FREE(cl->event_count, ev)
1284 cl->delete_me = EINA_TRUE;
1285 INF("cl %p is dead", cl);
1286 _ecore_con_client_free(cl);
1288 if ((svr->created) && (svr->path) && (svr->ppid == getpid()))
1291 ecore_con_ssl_server_shutdown(svr);
1296 eina_stringshare_del(svr->ip);
1297 eina_stringshare_del(svr->verify_name);
1299 if (svr->ecs_buf) eina_binbuf_free(svr->ecs_buf);
1300 if (svr->ecs_recvbuf) eina_binbuf_free(svr->ecs_recvbuf);
1302 if (svr->fd_handler)
1303 ecore_main_fd_handler_del(svr->fd_handler);
1308 if (svr->until_deletion)
1309 ecore_timer_del(svr->until_deletion);
1311 servers = eina_list_remove(servers, svr);
1317 _ecore_con_client_free(Ecore_Con_Client *cl)
1321 if (cl->event_count) return;
1323 t_start = ecore_time_get();
1324 while ((cl->buf) && (!cl->delete_me))
1326 _ecore_con_client_flush(cl);
1327 t = ecore_time_get();
1328 if ((t - t_start) > 0.5)
1330 WRN("EEK - stuck in _ecore_con_client_free() trying\n"
1331 " to flush data out from the client, and have been for\n"
1332 " %1.1f seconds. This is taking too long. Aborting flush.",
1337 cl->host_server->clients = eina_list_remove(cl->host_server->clients, cl);
1340 ecore_con_local_win32_client_del(cl);
1343 if (cl->event_count) return;
1344 ECORE_MAGIC_SET(cl, ECORE_MAGIC_NONE);
1346 if (cl->buf) eina_binbuf_free(cl->buf);
1348 if (cl->host_server->type & ECORE_CON_SSL)
1349 ecore_con_ssl_client_shutdown(cl);
1352 ecore_main_fd_handler_del(cl->fd_handler);
1357 free(cl->client_addr);
1358 cl->client_addr = NULL;
1360 if (cl->until_deletion)
1361 ecore_timer_del(cl->until_deletion);
1363 eina_stringshare_del(cl->ip);
1370 _ecore_con_server_timer(Ecore_Con_Server *svr)
1372 ecore_con_server_del(svr);
1374 svr->until_deletion = NULL;
1375 return ECORE_CALLBACK_CANCEL;
1379 _ecore_con_server_timer_update(Ecore_Con_Server *svr)
1381 if (svr->disconnect_time)
1383 if (svr->disconnect_time > 0)
1385 if (svr->until_deletion)
1386 ecore_timer_interval_set(svr->until_deletion, svr->disconnect_time);
1388 svr->until_deletion = ecore_timer_add(svr->disconnect_time, (Ecore_Task_Cb)_ecore_con_server_timer, svr);
1390 else if (svr->until_deletion)
1392 ecore_timer_del(svr->until_deletion);
1393 svr->until_deletion = NULL;
1398 if (svr->until_deletion)
1400 ecore_timer_del(svr->until_deletion);
1401 svr->until_deletion = NULL;
1407 _ecore_con_client_timer(Ecore_Con_Client *cl)
1409 ecore_con_client_del(cl);
1411 cl->until_deletion = NULL;
1412 return ECORE_CALLBACK_CANCEL;
1416 _ecore_con_cl_timer_update(Ecore_Con_Client *cl)
1418 if (cl->disconnect_time)
1420 if (cl->disconnect_time > 0)
1422 if (cl->until_deletion)
1423 ecore_timer_interval_set(cl->until_deletion, cl->disconnect_time);
1425 cl->until_deletion = ecore_timer_add(cl->disconnect_time, (Ecore_Task_Cb)_ecore_con_client_timer, cl);
1427 else if (cl->until_deletion)
1429 ecore_timer_del(cl->until_deletion);
1430 cl->until_deletion = NULL;
1435 if (cl->host_server->client_disconnect_time > 0)
1437 if (cl->until_deletion)
1438 ecore_timer_interval_set(cl->until_deletion, cl->host_server->client_disconnect_time);
1440 cl->until_deletion = ecore_timer_add(cl->host_server->client_disconnect_time, (Ecore_Task_Cb)_ecore_con_client_timer, cl);
1442 else if (cl->until_deletion)
1444 ecore_timer_del(cl->until_deletion);
1445 cl->until_deletion = NULL;
1451 _ecore_con_cb_tcp_listen(void *data,
1452 Ecore_Con_Info *net_info)
1454 Ecore_Con_Server *svr;
1456 const char *memerr = NULL;
1461 if (!net_info) /* error message has already been handled */
1463 svr->delete_me = EINA_TRUE;
1467 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1468 net_info->info.ai_protocol);
1469 if (svr->fd < 0) goto error;
1470 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1471 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1475 if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, (const void *)&lin,
1476 sizeof(struct linger)) < 0)
1479 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY)
1481 #ifdef HAVE_NETINET_TCP_H
1484 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag,
1492 if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
1495 if (listen(svr->fd, 4096) < 0) goto error;
1497 svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
1498 _ecore_con_svr_tcp_handler, svr, NULL, NULL);
1499 if (!svr->fd_handler)
1501 memerr = "Memory allocation failure";
1508 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1509 ecore_con_ssl_server_shutdown(svr);
1510 _ecore_con_server_kill(svr);
1514 _ecore_con_cb_udp_listen(void *data,
1515 Ecore_Con_Info *net_info)
1517 Ecore_Con_Server *svr;
1518 Ecore_Con_Type type;
1519 struct ip_mreq mreq;
1521 struct ipv6_mreq mreq6;
1524 const char *memerr = NULL;
1528 type &= ECORE_CON_TYPE;
1531 if (!net_info) /* error message has already been handled */
1533 svr->delete_me = EINA_TRUE;
1537 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1538 net_info->info.ai_protocol);
1539 if (svr->fd < 0) goto error;
1541 if (type == ECORE_CON_REMOTE_MCAST)
1543 if (net_info->info.ai_family == AF_INET)
1545 if (!inet_pton(net_info->info.ai_family, net_info->ip,
1546 &mreq.imr_multiaddr))
1549 mreq.imr_interface.s_addr = htonl(INADDR_ANY);
1550 if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
1551 (const void *)&mreq, sizeof(mreq)) != 0)
1555 else if (net_info->info.ai_family == AF_INET6)
1557 if (!inet_pton(net_info->info.ai_family, net_info->ip,
1558 &mreq6.ipv6mr_multiaddr))
1560 mreq6.ipv6mr_interface = htonl(INADDR_ANY);
1561 if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
1562 (const void *)&mreq6, sizeof(mreq6)) != 0)
1568 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof(on)) != 0)
1570 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1571 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1573 if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
1577 ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
1578 _ecore_con_svr_udp_handler, svr, NULL, NULL);
1579 if (!svr->fd_handler)
1581 memerr = "Memory allocation failure";
1585 svr->ip = eina_stringshare_add(net_info->ip);
1590 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1591 ecore_con_ssl_server_shutdown(svr);
1592 _ecore_con_server_kill(svr);
1596 _ecore_con_cb_tcp_connect(void *data,
1597 Ecore_Con_Info *net_info)
1599 Ecore_Con_Server *svr;
1602 const char *memerr = NULL;
1607 if (!net_info) /* error message has already been handled */
1609 svr->delete_me = EINA_TRUE;
1613 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1614 net_info->info.ai_protocol);
1615 if (svr->fd < 0) goto error;
1617 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1618 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1620 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate, sizeof(curstate)) < 0)
1623 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY)
1625 #ifdef HAVE_NETINET_TCP_H
1628 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)) < 0)
1635 res = connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen);
1637 if (res == SOCKET_ERROR)
1639 if (WSAGetLastError() != WSAEINPROGRESS)
1642 err = evil_format_message(WSAGetLastError());
1643 _ecore_con_event_server_error(svr, err, EINA_FALSE);
1644 ecore_con_ssl_server_shutdown(svr);
1645 _ecore_con_server_kill(svr);
1652 if (errno != EINPROGRESS) goto error;
1654 svr->connecting = EINA_TRUE;
1656 ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE,
1657 _ecore_con_cl_handler, svr, NULL, NULL);
1660 svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
1661 _ecore_con_cl_handler, svr, NULL, NULL);
1663 if (svr->type & ECORE_CON_SSL)
1665 svr->handshaking = EINA_TRUE;
1666 svr->ssl_state = ECORE_CON_SSL_STATE_INIT;
1667 DBG("%s ssl handshake", svr->ecs_state ? "Queuing" : "Beginning");
1668 if ((!svr->ecs_state) && ecore_con_ssl_server_init(svr))
1672 if (!svr->fd_handler)
1674 memerr = "Memory allocation failure";
1678 if ((!svr->ecs) || (svr->ecs->lookup))
1679 svr->ip = eina_stringshare_add(net_info->ip);
1684 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1685 ecore_con_ssl_server_shutdown(svr);
1686 _ecore_con_server_kill(svr);
1690 _ecore_con_cb_udp_connect(void *data,
1691 Ecore_Con_Info *net_info)
1693 Ecore_Con_Server *svr;
1696 const char *memerr = NULL;
1700 if (!net_info) /* error message has already been handled */
1702 svr->delete_me = EINA_TRUE;
1706 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1707 net_info->info.ai_protocol);
1708 if (svr->fd < 0) goto error;
1709 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1710 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1711 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_BROADCAST)
1713 if (setsockopt(svr->fd, SOL_SOCKET, SO_BROADCAST,
1714 (const void *)&broadcast,
1715 sizeof(broadcast)) < 0)
1720 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR,
1721 (const void *)&curstate, sizeof(curstate)) < 0)
1724 if (connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
1727 svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE,
1728 _ecore_con_cl_udp_handler, svr, NULL, NULL);
1730 if (!svr->fd_handler)
1732 memerr = "Memory allocation failure";
1736 if ((!svr->ecs) || (svr->ecs->lookup))
1737 svr->ip = eina_stringshare_add(net_info->ip);
1742 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1743 ecore_con_ssl_server_shutdown(svr);
1744 _ecore_con_server_kill(svr);
1747 static Ecore_Con_State
1748 svr_try_connect_plain(Ecore_Con_Server *svr)
1752 socklen_t size = sizeof(int);
1754 res = getsockopt(svr->fd, SOL_SOCKET, SO_ERROR, (void *)&so_err, &size);
1756 if (res == SOCKET_ERROR)
1757 so_err = WSAGetLastError();
1759 if ((so_err == WSAEINPROGRESS) && !svr->delete_me)
1760 return ECORE_CON_INPROGRESS;
1766 if ((so_err == EINPROGRESS) && !svr->delete_me)
1767 return ECORE_CON_INPROGRESS;
1773 /* we lost our server! */
1774 ecore_con_event_server_error(svr, strerror(so_err));
1775 ERR("Connection lost: %s", strerror(so_err));
1776 _ecore_con_server_kill(svr);
1777 return ECORE_CON_DISCONNECTED;
1780 if ((!svr->delete_me) && (!svr->handshaking) && svr->connecting)
1784 if (ecore_con_socks_svr_init(svr))
1785 return ECORE_CON_INPROGRESS;
1788 ecore_con_event_server_add(svr);
1791 if (svr->fd_handler && (!svr->buf))
1792 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
1794 if (!svr->delete_me)
1795 return ECORE_CON_CONNECTED;
1797 return ECORE_CON_DISCONNECTED;
1801 _ecore_con_pretty_ip(struct sockaddr *client_addr)
1804 char ipbuf[INET_ADDRSTRLEN + 1];
1806 char ipbuf[INET6_ADDRSTRLEN + 1];
1808 int family = client_addr->sa_family;
1814 src = &(((struct sockaddr_in *)client_addr)->sin_addr);
1818 src = &(((struct sockaddr_in6 *)client_addr)->sin6_addr);
1820 if (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)src))
1823 src = (char*)src + 12;
1828 return eina_stringshare_add("0.0.0.0");
1831 if (!inet_ntop(family, src, ipbuf, sizeof(ipbuf)))
1832 return eina_stringshare_add("0.0.0.0");
1834 ipbuf[sizeof(ipbuf) - 1] = 0;
1835 return eina_stringshare_add(ipbuf);
1839 _ecore_con_svr_tcp_handler(void *data,
1840 Ecore_Fd_Handler *fd_handler __UNUSED__)
1842 Ecore_Con_Server *svr;
1843 Ecore_Con_Client *cl = NULL;
1844 unsigned char client_addr[256];
1845 unsigned int client_addr_len;
1846 const char *clerr = NULL;
1850 return ECORE_CALLBACK_RENEW;
1852 if ((svr->client_limit >= 0) && (!svr->reject_excess_clients) &&
1853 (svr->client_count >= (unsigned int)svr->client_limit))
1854 return ECORE_CALLBACK_RENEW;
1858 cl = calloc(1, sizeof(Ecore_Con_Client));
1861 ecore_con_event_server_error(svr, "Memory allocation failure when attempting to add a new client");
1862 return ECORE_CALLBACK_RENEW;
1864 cl->host_server = svr;
1866 client_addr_len = sizeof(client_addr);
1867 memset(&client_addr, 0, client_addr_len);
1868 cl->fd = accept(svr->fd, (struct sockaddr *)&client_addr, (socklen_t *)&client_addr_len);
1869 if (cl->fd < 0) goto error;
1870 if ((svr->client_limit >= 0) && (svr->reject_excess_clients) &&
1871 (svr->client_count >= (unsigned int)svr->client_limit))
1873 clerr = "Maximum client limit reached";
1877 if (fcntl(cl->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1878 if (fcntl(cl->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1879 cl->fd_handler = ecore_main_fd_handler_add(cl->fd, ECORE_FD_READ,
1880 _ecore_con_svr_cl_handler, cl, NULL, NULL);
1881 if (!cl->fd_handler) goto error;
1882 ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
1884 if ((!svr->upgrade) && (svr->type & ECORE_CON_SSL))
1886 cl->handshaking = EINA_TRUE;
1887 cl->ssl_state = ECORE_CON_SSL_STATE_INIT;
1888 if (ecore_con_ssl_client_init(cl))
1892 cl->client_addr = malloc(client_addr_len);
1893 if (!cl->client_addr)
1895 clerr = "Memory allocation failure when attempting to add a new client";
1898 cl->client_addr_len = client_addr_len;
1899 memcpy(cl->client_addr, &client_addr, client_addr_len);
1901 svr->clients = eina_list_append(svr->clients, cl);
1902 svr->client_count++;
1904 if ((!cl->delete_me) && (!cl->handshaking))
1905 ecore_con_event_client_add(cl);
1907 return ECORE_CALLBACK_RENEW;
1910 if (cl->fd_handler) ecore_main_fd_handler_del(cl->fd_handler);
1911 if (cl->fd >= 0) close(cl->fd);
1915 EINA_LIST_FREE(cl->event_count, ev)
1917 svr->event_count = eina_list_remove(svr->event_count, ev);
1918 ecore_event_del(ev);
1922 if (clerr || errno) ecore_con_event_server_error(svr, clerr ?: strerror(errno));
1923 return ECORE_CALLBACK_RENEW;
1927 _ecore_con_cl_read(Ecore_Con_Server *svr)
1930 Eina_Bool lost_server = EINA_TRUE;
1931 unsigned char buf[READBUFSIZ];
1935 /* only possible with non-ssl connections */
1936 if (svr->connecting && (svr_try_connect_plain(svr) != ECORE_CON_CONNECTED))
1939 if (svr->handshaking && (!svr->ecs_state))
1941 DBG("Continuing ssl handshake");
1942 if (!ecore_con_ssl_server_init(svr))
1943 lost_server = EINA_FALSE;
1944 _ecore_con_server_timer_update(svr);
1947 if (svr->ecs_state || !(svr->type & ECORE_CON_SSL))
1950 num = read(svr->fd, buf, sizeof(buf));
1951 /* 0 is not a valid return value for a tcp socket */
1952 if ((num > 0) || ((num < 0) && (errno == EAGAIN)))
1953 lost_server = EINA_FALSE;
1955 ecore_con_event_server_error(svr, strerror(errno));
1959 num = ecore_con_ssl_server_read(svr, buf, sizeof(buf));
1960 /* this is not an actual 0 return, 0 here just means non-fatal error such as EAGAIN */
1962 lost_server = EINA_FALSE;
1965 if ((!svr->delete_me) && (num > 0))
1968 ecore_con_socks_read(svr, buf, num);
1970 ecore_con_event_server_data(svr, buf, num, EINA_TRUE);
1974 _ecore_con_server_kill(svr);
1978 _ecore_con_cl_handler(void *data,
1979 Ecore_Fd_Handler *fd_handler)
1981 Ecore_Con_Server *svr;
1982 Eina_Bool want_read, want_write;
1986 return ECORE_CALLBACK_RENEW;
1989 return ECORE_CALLBACK_RENEW;
1991 want_read = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ);
1992 want_write = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE);
1994 if ((!svr->ecs_state) && svr->handshaking && (want_read || want_write))
1996 DBG("Continuing ssl handshake: preparing to %s...", want_read ? "read" : "write");
2000 char buf[READBUFSIZ];
2002 len = recv(svr->fd, buf, sizeof(buf), MSG_DONTWAIT | MSG_PEEK);
2003 DBG("%zu bytes in buffer", len);
2006 if (ecore_con_ssl_server_init(svr))
2008 ERR("ssl handshaking failed!");
2009 svr->handshaking = EINA_FALSE;
2011 else if (!svr->ssl_state)
2012 ecore_con_event_server_add(svr);
2013 return ECORE_CALLBACK_RENEW;
2015 if (svr->ecs && svr->ecs_state && (svr->ecs_state < ECORE_CON_PROXY_STATE_READ) && (!svr->ecs_buf))
2017 if (svr->ecs_state < ECORE_CON_PROXY_STATE_INIT)
2019 INF("PROXY STATE++");
2022 if (ecore_con_socks_svr_init(svr)) return ECORE_CALLBACK_RENEW;
2025 _ecore_con_cl_read(svr);
2026 else if (want_write) /* only possible with non-ssl connections */
2028 if (svr->connecting && (!svr_try_connect_plain(svr)) && (!svr->ecs_state))
2029 return ECORE_CALLBACK_RENEW;
2031 _ecore_con_server_flush(svr);
2034 return ECORE_CALLBACK_RENEW;
2038 _ecore_con_cl_udp_handler(void *data,
2039 Ecore_Fd_Handler *fd_handler)
2041 unsigned char buf[READBUFSIZ];
2043 Ecore_Con_Server *svr;
2044 Eina_Bool want_read, want_write;
2046 want_read = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ);
2047 want_write = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE);
2050 if (svr->delete_me || svr->delete_me || ((!want_read) && (!want_write)))
2051 return ECORE_CALLBACK_RENEW;
2055 _ecore_con_server_flush(svr);
2056 return ECORE_CALLBACK_RENEW;
2059 num = read(svr->fd, buf, READBUFSIZ);
2061 if ((!svr->delete_me) && (num > 0))
2062 ecore_con_event_server_data(svr, buf, num, EINA_TRUE);
2064 if (num < 0 && (errno != EAGAIN) && (errno != EINTR))
2066 ecore_con_event_server_error(svr, strerror(errno));
2067 _ecore_con_server_kill(svr);
2070 return ECORE_CALLBACK_RENEW;
2074 _ecore_con_svr_udp_handler(void *data,
2075 Ecore_Fd_Handler *fd_handler)
2077 unsigned char buf[READBUFSIZ];
2078 unsigned char client_addr[256];
2079 socklen_t client_addr_len = sizeof(client_addr);
2081 Ecore_Con_Server *svr;
2082 Ecore_Con_Client *cl = NULL;
2087 return ECORE_CALLBACK_RENEW;
2089 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
2091 _ecore_con_client_flush(cl);
2092 return ECORE_CALLBACK_RENEW;
2095 if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
2096 return ECORE_CALLBACK_RENEW;
2099 num = fcntl(svr->fd, F_SETFL, O_NONBLOCK);
2101 num = recvfrom(svr->fd, (char *)buf, sizeof(buf), 0,
2102 (struct sockaddr *)&client_addr,
2106 num = recvfrom(svr->fd, buf, sizeof(buf), MSG_DONTWAIT,
2107 (struct sockaddr *)&client_addr,
2111 if (num < 0 && (errno != EAGAIN) && (errno != EINTR))
2113 ecore_con_event_server_error(svr, strerror(errno));
2114 if (!svr->delete_me)
2115 ecore_con_event_client_del(NULL);
2116 _ecore_con_server_kill(svr);
2117 return ECORE_CALLBACK_CANCEL;
2121 /* Create a new client for use in the client data event */
2122 cl = calloc(1, sizeof(Ecore_Con_Client));
2123 EINA_SAFETY_ON_NULL_RETURN_VAL(cl, ECORE_CALLBACK_RENEW);
2125 cl->host_server = svr;
2126 cl->client_addr = malloc(client_addr_len);
2127 if (!cl->client_addr)
2130 return ECORE_CALLBACK_RENEW;
2132 cl->client_addr_len = client_addr_len;
2134 memcpy(cl->client_addr, &client_addr, client_addr_len);
2135 ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
2136 svr->clients = eina_list_append(svr->clients, cl);
2137 svr->client_count++;
2139 ecore_con_event_client_add(cl);
2140 ecore_con_event_client_data(cl, buf, num, EINA_TRUE);
2142 return ECORE_CALLBACK_RENEW;
2146 _ecore_con_svr_cl_read(Ecore_Con_Client *cl)
2149 Eina_Bool lost_client = EINA_TRUE;
2150 unsigned char buf[READBUFSIZ];
2154 if (cl->handshaking)
2156 /* add an extra handshake attempt just before read, even though
2157 * read also attempts to handshake, to try to finish sooner
2159 if (ecore_con_ssl_client_init(cl))
2160 lost_client = EINA_FALSE;
2162 _ecore_con_cl_timer_update(cl);
2165 if (!(cl->host_server->type & ECORE_CON_SSL) && (!cl->upgrade))
2167 num = read(cl->fd, buf, sizeof(buf));
2168 /* 0 is not a valid return value for a tcp socket */
2169 if ((num > 0) || ((num < 0) && ((errno == EAGAIN) || (errno == EINTR))))
2170 lost_client = EINA_FALSE;
2172 ecore_con_event_client_error(cl, strerror(errno));
2176 num = ecore_con_ssl_client_read(cl, buf, sizeof(buf));
2177 /* this is not an actual 0 return, 0 here just means non-fatal error such as EAGAIN */
2179 lost_client = EINA_FALSE;
2182 if ((!cl->delete_me) && (num > 0))
2183 ecore_con_event_client_data(cl, buf, num, EINA_TRUE);
2185 if (lost_client) _ecore_con_client_kill(cl);
2189 _ecore_con_svr_cl_handler(void *data,
2190 Ecore_Fd_Handler *fd_handler)
2192 Ecore_Con_Client *cl;
2196 return ECORE_CALLBACK_RENEW;
2198 if (cl->handshaking && ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ | ECORE_FD_WRITE))
2200 if (ecore_con_ssl_client_init(cl))
2202 ERR("ssl handshaking failed!");
2203 _ecore_con_client_kill(cl);
2204 return ECORE_CALLBACK_RENEW;
2206 else if (!cl->ssl_state)
2207 ecore_con_event_client_add(cl);
2209 else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
2210 _ecore_con_svr_cl_read(cl);
2212 else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
2213 _ecore_con_client_flush(cl);
2215 return ECORE_CALLBACK_RENEW;
2219 _ecore_con_server_flush(Ecore_Con_Server *svr)
2222 size_t buf_len, buf_offset;
2225 DBG("(svr=%p,buf=%p)", svr, svr->buf);
2227 if (ecore_con_local_win32_server_flush(svr))
2231 if ((!svr->buf) && (!svr->ecs_buf) && svr->fd_handler)
2233 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
2237 buf = svr->buf ? eina_binbuf_string_get(svr->buf) : eina_binbuf_string_get(svr->ecs_buf);
2238 buf_len = svr->buf ? eina_binbuf_length_get(svr->buf) : eina_binbuf_length_get(svr->ecs_buf);
2239 buf_offset = svr->buf ? svr->write_buf_offset : svr->ecs_buf_offset;
2240 num = buf_len - buf_offset;
2242 /* check whether we need to write anything at all.
2243 * we must not write zero bytes with SSL_write() since it
2244 * causes undefined behaviour
2246 /* we thank Tommy[D] for needing to check negative buffer sizes
2247 * here because his system is amazing.
2249 if (num <= 0) return;
2251 if ((!svr->ecs_state) && svr->handshaking)
2253 DBG("Continuing ssl handshake");
2254 if (ecore_con_ssl_server_init(svr))
2255 _ecore_con_server_kill(svr);
2256 _ecore_con_server_timer_update(svr);
2260 if (svr->ecs_state || (!(svr->type & ECORE_CON_SSL)))
2261 count = write(svr->fd, buf + buf_offset, num);
2263 count = ecore_con_ssl_server_write(svr, buf + buf_offset, num);
2267 if ((errno != EAGAIN) && (errno != EINTR))
2269 ecore_con_event_server_error(svr, strerror(errno));
2270 _ecore_con_server_kill(svr);
2275 if (count && (!svr->ecs_state)) ecore_con_event_server_write(svr, count);
2277 buf_offset = svr->ecs_buf_offset += count;
2279 buf_offset = svr->write_buf_offset += count;
2280 if (buf_offset >= buf_len)
2284 svr->ecs_buf_offset = 0;
2285 eina_binbuf_free(svr->ecs_buf);
2286 svr->ecs_buf = NULL;
2287 INF("PROXY STATE++");
2292 svr->write_buf_offset = 0;
2293 eina_binbuf_free(svr->buf);
2296 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK)
2299 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
2300 /* realistically this isn't anything serious so we can just log and continue */
2301 ERR("uncorking failed! %s", strerror(errno));
2305 if (svr->fd_handler)
2306 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
2308 else if ((count < num) && svr->fd_handler)
2309 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE);
2313 _ecore_con_client_flush(Ecore_Con_Client *cl)
2315 int num = 0, count = 0;
2318 if (ecore_con_local_win32_client_flush(cl))
2322 if (!cl->buf && cl->fd_handler)
2324 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ);
2328 if (cl->handshaking)
2330 if (ecore_con_ssl_client_init(cl))
2333 _ecore_con_cl_timer_update(cl);
2338 if (!cl->buf) return;
2339 num = eina_binbuf_length_get(cl->buf) - cl->buf_offset;
2340 if (num <= 0) return;
2341 if (!(cl->host_server->type & ECORE_CON_SSL) && (!cl->upgrade))
2342 count = write(cl->fd, eina_binbuf_string_get(cl->buf) + cl->buf_offset, num);
2344 count = ecore_con_ssl_client_write(cl, eina_binbuf_string_get(cl->buf) + cl->buf_offset, num);
2349 if ((errno != EAGAIN) && (errno != EINTR) && (!cl->delete_me))
2351 ecore_con_event_client_error(cl, strerror(errno));
2352 _ecore_con_client_kill(cl);
2358 if (count) ecore_con_event_client_write(cl, count);
2359 cl->buf_offset += count, num -= count;
2360 if (cl->buf_offset >= eina_binbuf_length_get(cl->buf))
2363 eina_binbuf_free(cl->buf);
2366 if ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK)
2369 if (setsockopt(cl->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
2370 /* realistically this isn't anything serious so we can just log and continue */
2371 ERR("uncorking failed! %s", strerror(errno));
2375 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ);
2377 else if (cl->fd_handler && (num >= 0))
2378 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_WRITE);
2382 _ecore_con_event_client_add_free(Ecore_Con_Server *svr,
2385 Ecore_Con_Event_Client_Add *e;
2390 Eina_Bool svrfreed = EINA_FALSE;
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, ev);
2396 if ((!svr->event_count) && (svr->delete_me))
2398 _ecore_con_server_free(svr);
2399 svrfreed = EINA_TRUE;
2404 if ((!e->client->event_count) && (e->client->delete_me))
2405 ecore_con_client_del(e->client);
2409 ecore_con_event_client_add_free(e);
2410 _ecore_con_event_count--;
2411 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2412 ecore_con_mempool_shutdown();
2416 _ecore_con_event_client_del_free(Ecore_Con_Server *svr,
2419 Ecore_Con_Event_Client_Del *e;
2424 Eina_Bool svrfreed = EINA_FALSE;
2426 e->client->event_count = eina_list_remove(e->client->event_count, e);
2427 if (e->client->host_server)
2429 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, ev);
2430 if ((!svr->event_count) && (svr->delete_me))
2432 _ecore_con_server_free(svr);
2433 svrfreed = EINA_TRUE;
2438 if (!e->client->event_count)
2439 _ecore_con_client_free(e->client);
2442 ecore_con_event_client_del_free(e);
2443 _ecore_con_event_count--;
2444 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2445 ecore_con_mempool_shutdown();
2449 _ecore_con_event_client_write_free(Ecore_Con_Server *svr,
2450 Ecore_Con_Event_Client_Write *e)
2454 Eina_Bool svrfreed = EINA_FALSE;
2456 e->client->event_count = eina_list_remove(e->client->event_count, e);
2457 if (e->client->host_server)
2459 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, e);
2460 if ((!svr->event_count) && (svr->delete_me))
2462 _ecore_con_server_free(svr);
2463 svrfreed = EINA_TRUE;
2468 if (((!e->client->event_count) && (e->client->delete_me)) ||
2469 ((e->client->host_server &&
2470 ((e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP ||
2471 (e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_MCAST))))
2472 ecore_con_client_del(e->client);
2475 ecore_con_event_client_write_free(e);
2476 _ecore_con_event_count--;
2477 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2478 ecore_con_mempool_shutdown();
2482 _ecore_con_event_client_data_free(Ecore_Con_Server *svr,
2485 Ecore_Con_Event_Client_Data *e;
2490 Eina_Bool svrfreed = EINA_FALSE;
2492 e->client->event_count = eina_list_remove(e->client->event_count, e);
2493 if (e->client->host_server)
2495 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, ev);
2497 if ((!svr->event_count) && (svr->delete_me))
2499 _ecore_con_server_free(svr);
2500 svrfreed = EINA_TRUE;
2504 if (((!e->client->event_count) && (e->client->delete_me)) ||
2505 ((e->client->host_server &&
2506 ((e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP ||
2507 (e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_MCAST))))
2508 ecore_con_client_del(e->client);
2512 ecore_con_event_client_data_free(e);
2513 _ecore_con_event_count--;
2514 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2515 ecore_con_mempool_shutdown();
2519 _ecore_con_event_server_add_free(void *data __UNUSED__,
2522 Ecore_Con_Event_Server_Add *e;
2527 e->server->event_count = eina_list_remove(e->server->event_count, ev);
2528 if ((!e->server->event_count) && (e->server->delete_me))
2529 _ecore_con_server_free(e->server);
2531 ecore_con_event_server_add_free(e);
2532 _ecore_con_event_count--;
2533 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2534 ecore_con_mempool_shutdown();
2538 _ecore_con_event_server_del_free(void *data __UNUSED__,
2541 Ecore_Con_Event_Server_Del *e;
2546 e->server->event_count = eina_list_remove(e->server->event_count, ev);
2547 if (!e->server->event_count)
2548 _ecore_con_server_free(e->server);
2550 ecore_con_event_server_del_free(e);
2551 _ecore_con_event_count--;
2552 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2553 ecore_con_mempool_shutdown();
2557 _ecore_con_event_server_write_free(void *data __UNUSED__,
2558 Ecore_Con_Event_Server_Write *e)
2562 e->server->event_count = eina_list_remove(e->server->event_count, e);
2563 if ((!e->server->event_count) && (e->server->delete_me))
2564 _ecore_con_server_free(e->server);
2567 ecore_con_event_server_write_free(e);
2568 _ecore_con_event_count--;
2569 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2570 ecore_con_mempool_shutdown();
2574 _ecore_con_event_server_data_free(void *data __UNUSED__,
2577 Ecore_Con_Event_Server_Data *e;
2582 e->server->event_count = eina_list_remove(e->server->event_count, ev);
2583 if ((!e->server->event_count) && (e->server->delete_me))
2584 _ecore_con_server_free(e->server);
2588 ecore_con_event_server_data_free(e);
2589 _ecore_con_event_count--;
2590 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2591 ecore_con_mempool_shutdown();
2596 _ecore_con_event_server_error_free(void *data __UNUSED__, Ecore_Con_Event_Server_Error *e)
2600 e->server->event_count = eina_list_remove(e->server->event_count, e);
2601 if ((!e->server->event_count) && (e->server->delete_me))
2602 _ecore_con_server_free(e->server);
2605 ecore_con_event_server_error_free(e);
2606 _ecore_con_event_count--;
2607 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2608 ecore_con_mempool_shutdown();
2612 _ecore_con_event_client_error_free(Ecore_Con_Server *svr, Ecore_Con_Event_Client_Error *e)
2616 Eina_Bool svrfreed = EINA_FALSE;
2618 if (eina_list_data_find(svr->clients, e->client))
2620 e->client->event_count = eina_list_remove(e->client->event_count, e);
2621 if ((!e->client->event_count) && (e->client->delete_me))
2623 _ecore_con_client_free(e->client);
2624 svrfreed = EINA_TRUE;
2627 svr->event_count = eina_list_remove(svr->event_count, e);
2630 if ((!svr->event_count) && (svr->delete_me))
2631 _ecore_con_server_free(svr);
2635 ecore_con_event_client_error_free(e);
2636 _ecore_con_event_count--;
2637 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2638 ecore_con_mempool_shutdown();
2642 _ecore_con_lookup_done(void *data,
2643 Ecore_Con_Info *infos)
2645 Ecore_Con_Server *svr;
2646 Ecore_Con_Lookup *lk;
2652 lk->done_cb(infos->info.ai_canonname, infos->ip,
2653 infos->info.ai_addr, infos->info.ai_addrlen,
2656 lk->done_cb(NULL, NULL, NULL, 0, (void *)lk->data);