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->start_time = ecore_time_get();
375 svr->type = compl_type;
377 svr->data = (void *)data;
378 svr->created = EINA_TRUE;
379 svr->use_cert = (compl_type & ECORE_CON_SSL & ECORE_CON_LOAD_CERT) == ECORE_CON_LOAD_CERT;
380 svr->reject_excess_clients = EINA_FALSE;
381 svr->client_limit = -1;
383 svr->ppid = getpid();
384 if (ecore_con_ssl_server_prepare(svr, compl_type & ECORE_CON_SSL))
387 type = compl_type & ECORE_CON_TYPE;
389 if ((type == ECORE_CON_LOCAL_USER) ||
390 (type == ECORE_CON_LOCAL_SYSTEM) ||
391 (type == ECORE_CON_LOCAL_ABSTRACT))
394 if (!ecore_con_local_listen(svr))
397 if (!ecore_con_local_listen(svr, _ecore_con_svr_tcp_handler, svr))
401 if ((type == ECORE_CON_REMOTE_TCP) ||
402 (type == ECORE_CON_REMOTE_NODELAY) ||
403 (type == ECORE_CON_REMOTE_CORK))
406 if (!ecore_con_info_tcp_listen(svr, _ecore_con_cb_tcp_listen,
410 else if ((type == ECORE_CON_REMOTE_MCAST) ||
411 (type == ECORE_CON_REMOTE_UDP))
413 if (!ecore_con_info_udp_listen(svr, _ecore_con_cb_udp_listen,
417 servers = eina_list_append(servers, svr);
418 ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER);
431 ecore_main_fd_handler_del(svr->fd_handler);
437 eina_binbuf_free(svr->buf);
440 eina_stringshare_del(svr->ip);
442 ecore_con_ssl_server_shutdown(svr);
447 EAPI Ecore_Con_Server *
448 ecore_con_server_connect(Ecore_Con_Type compl_type,
453 Ecore_Con_Server *svr;
456 if ((!name) || (!name[0]))
458 /* local user socket: FILE: ~/.ecore/[name]/[port] */
459 /* local system socket: FILE: /tmp/.ecore_service|[name]|[port] */
460 /* remote system socket: TCP/IP: [name]:[port] */
461 svr = calloc(1, sizeof(Ecore_Con_Server));
465 svr->name = strdup(name);
469 svr->type = compl_type;
471 svr->data = (void *)data;
472 svr->created = EINA_FALSE;
473 svr->use_cert = (compl_type & ECORE_CON_SSL & ECORE_CON_LOAD_CERT) == ECORE_CON_LOAD_CERT;
474 svr->disable_proxy = (compl_type & ECORE_CON_SUPER_SSL & ECORE_CON_NO_PROXY) == ECORE_CON_NO_PROXY;
475 svr->reject_excess_clients = EINA_FALSE;
477 svr->client_limit = -1;
479 type = compl_type & ECORE_CON_TYPE;
481 if ((!svr->disable_proxy) && (type > ECORE_CON_LOCAL_ABSTRACT))
483 /* never use proxies on local connections */
484 if (_ecore_con_proxy_once)
485 svr->ecs = _ecore_con_proxy_once;
486 else if (_ecore_con_proxy_global)
487 svr->ecs = _ecore_con_proxy_global;
488 _ecore_con_proxy_once = NULL;
491 if ((!svr->ecs->lookup) &&
492 (!ecore_con_lookup(svr->name, (Ecore_Con_Dns_Cb)ecore_con_socks_dns_cb, svr)))
494 if (svr->ecs->lookup)
495 svr->ecs_state = ECORE_CON_PROXY_STATE_RESOLVED;
498 EINA_SAFETY_ON_TRUE_GOTO(ecore_con_ssl_server_prepare(svr, compl_type & ECORE_CON_SSL), error);
500 EINA_SAFETY_ON_TRUE_GOTO(((type == ECORE_CON_REMOTE_TCP) ||
501 (type == ECORE_CON_REMOTE_NODELAY) ||
502 (type == ECORE_CON_REMOTE_CORK) ||
503 (type == ECORE_CON_REMOTE_UDP) ||
504 (type == ECORE_CON_REMOTE_BROADCAST)) &&
507 if ((type == ECORE_CON_LOCAL_USER) ||
508 (type == ECORE_CON_LOCAL_SYSTEM) ||
509 (type == ECORE_CON_LOCAL_ABSTRACT))
512 EINA_SAFETY_ON_FALSE_GOTO(ecore_con_local_connect(svr, _ecore_con_cl_handler), error);
514 EINA_SAFETY_ON_FALSE_GOTO(ecore_con_local_connect(svr, _ecore_con_cl_handler, svr), error);
517 if ((type == ECORE_CON_REMOTE_TCP) ||
518 (type == ECORE_CON_REMOTE_NODELAY) ||
519 (type == ECORE_CON_REMOTE_CORK))
522 EINA_SAFETY_ON_FALSE_GOTO(ecore_con_info_tcp_connect(svr, _ecore_con_cb_tcp_connect, svr), error);
524 else if ((type == ECORE_CON_REMOTE_UDP) || (type == ECORE_CON_REMOTE_BROADCAST))
526 EINA_SAFETY_ON_FALSE_GOTO(ecore_con_info_udp_connect(svr, _ecore_con_cb_udp_connect, svr), error);
528 servers = eina_list_append(servers, svr);
529 ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER);
541 ecore_main_fd_handler_del(svr->fd_handler);
546 ecore_con_ssl_server_shutdown(svr);
552 ecore_con_server_timeout_set(Ecore_Con_Server *svr,
555 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
557 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_timeout_set");
562 svr->client_disconnect_time = timeout;
564 svr->disconnect_time = timeout;
566 _ecore_con_server_timer_update(svr);
570 ecore_con_server_timeout_get(Ecore_Con_Server *svr)
572 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
574 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_timeout_get");
578 return svr->created ? svr->client_disconnect_time : svr->disconnect_time;
582 ecore_con_server_del(Ecore_Con_Server *svr)
584 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
586 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_del");
593 _ecore_con_server_kill(svr);
598 ecore_con_server_data_get(Ecore_Con_Server *svr)
600 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
602 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_data_get");
610 ecore_con_server_data_set(Ecore_Con_Server *svr,
615 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
617 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_data_get");
627 ecore_con_server_connected_get(Ecore_Con_Server *svr)
629 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
631 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_connected_get");
641 EAPI const Eina_List *
642 ecore_con_server_clients_get(Ecore_Con_Server *svr)
644 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
646 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
647 "ecore_con_server_clients_get");
655 ecore_con_server_name_get(Ecore_Con_Server *svr)
657 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
659 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
660 "ecore_con_server_name_get");
668 ecore_con_server_port_get(Ecore_Con_Server *svr)
670 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
672 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
673 "ecore_con_server_port_get");
680 ecore_con_server_send(Ecore_Con_Server *svr,
684 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
686 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_send");
690 EINA_SAFETY_ON_TRUE_RETURN_VAL(svr->delete_me, 0);
692 EINA_SAFETY_ON_NULL_RETURN_VAL(data, 0);
694 EINA_SAFETY_ON_TRUE_RETURN_VAL(size < 1, 0);
697 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE);
701 svr->buf = eina_binbuf_new();
702 EINA_SAFETY_ON_NULL_RETURN_VAL(svr->buf, 0);
704 if ((svr->fd >= 0) && ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK))
707 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
708 /* realistically this isn't anything serious so we can just log and continue */
709 ERR("corking failed! %s", strerror(errno));
713 eina_binbuf_append_length(svr->buf, data, size);
719 ecore_con_server_client_limit_set(Ecore_Con_Server *svr,
721 char reject_excess_clients)
723 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
725 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
726 "ecore_con_server_client_limit_set");
730 svr->client_limit = client_limit;
731 svr->reject_excess_clients = reject_excess_clients;
735 ecore_con_server_ip_get(Ecore_Con_Server *svr)
737 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
739 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_ip_get");
747 ecore_con_server_uptime_get(Ecore_Con_Server *svr)
749 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
751 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_uptime_get");
755 return ecore_time_get() - svr->start_time;
759 ecore_con_server_flush(Ecore_Con_Server *svr)
761 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
763 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_flush");
767 _ecore_con_server_flush(svr);
775 * @addtogroup Ecore_Con_Client_Group Ecore Connection Client Functions
777 * Functions that operate on Ecore connection client objects.
783 * @example ecore_con_client_example.c
784 * Shows how to write a simple client that connects to the example server.
788 ecore_con_client_send(Ecore_Con_Client *cl,
792 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
794 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_send");
798 EINA_SAFETY_ON_TRUE_RETURN_VAL(cl->delete_me, 0);
800 EINA_SAFETY_ON_NULL_RETURN_VAL(data, 0);
802 EINA_SAFETY_ON_TRUE_RETURN_VAL(size < 1, 0);
805 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE);
807 if (cl->host_server && ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP))
808 sendto(cl->host_server->fd, data, size, 0, (struct sockaddr *)cl->client_addr,
809 cl->client_addr_len);
812 cl->buf = eina_binbuf_new();
813 EINA_SAFETY_ON_NULL_RETURN_VAL(cl->buf, 0);
815 if ((cl->fd >= 0) && ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK))
818 if (setsockopt(cl->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
819 /* realistically this isn't anything serious so we can just log and continue */
820 ERR("corking failed! %s", strerror(errno));
824 eina_binbuf_append_length(cl->buf, data, size);
829 EAPI Ecore_Con_Server *
830 ecore_con_client_server_get(Ecore_Con_Client *cl)
832 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
834 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
835 "ecore_con_client_server_get");
839 return cl->host_server;
843 ecore_con_client_connected_get(Ecore_Con_Client *cl)
845 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
847 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
848 "ecore_con_client_connected_get");
852 return !cl->delete_me;
856 ecore_con_client_timeout_set(Ecore_Con_Client *cl,
859 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
861 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
862 "ecore_con_client_timeout_set");
866 cl->disconnect_time = timeout;
868 _ecore_con_cl_timer_update(cl);
872 ecore_con_client_timeout_get(Ecore_Con_Client *cl)
874 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
876 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_timeout_get");
880 return cl->disconnect_time;
884 ecore_con_client_del(Ecore_Con_Client *cl)
886 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
888 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_del");
892 _ecore_con_client_kill(cl);
897 ecore_con_client_data_set(Ecore_Con_Client *cl,
900 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
902 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_data_set");
906 cl->data = (void *)data;
910 ecore_con_client_data_get(Ecore_Con_Client *cl)
912 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
914 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_data_get");
922 ecore_con_client_ip_get(Ecore_Con_Client *cl)
924 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
926 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_ip_get");
930 cl->ip = _ecore_con_pretty_ip(cl->client_addr);
936 ecore_con_client_port_get(Ecore_Con_Client *cl)
938 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
940 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_port_get");
943 if (cl->client_addr->sa_family == AF_INET)
944 return ((struct sockaddr_in*)cl->client_addr)->sin_port;
946 return ((struct sockaddr_in6*)cl->client_addr)->sin6_port;
953 ecore_con_client_uptime_get(Ecore_Con_Client *cl)
955 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
957 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_uptime_get");
961 return ecore_time_get() - cl->start_time;
965 ecore_con_client_flush(Ecore_Con_Client *cl)
967 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
969 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_flush");
973 _ecore_con_client_flush(cl);
977 ecore_con_server_fd_get(Ecore_Con_Server *svr)
979 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
981 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, __func__);
984 if (svr->created) return -1;
985 if (svr->delete_me) return -1;
986 return ecore_main_fd_handler_fd_get(svr->fd_handler);
990 ecore_con_client_fd_get(Ecore_Con_Client *cl)
992 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
994 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, __func__);
997 return ecore_main_fd_handler_fd_get(cl->fd_handler);
1005 ecore_con_event_proxy_bind(Ecore_Con_Server *svr)
1007 Ecore_Con_Event_Proxy_Bind *e;
1008 int ev = ECORE_CON_EVENT_PROXY_BIND;
1010 e = ecore_con_event_proxy_bind_alloc();
1011 EINA_SAFETY_ON_NULL_RETURN(e);
1013 svr->event_count = eina_list_append(svr->event_count, e);
1014 _ecore_con_server_timer_update(svr);
1016 e->ip = svr->proxyip;
1017 e->port = svr->proxyport;
1018 ecore_event_add(ev, e,
1019 _ecore_con_event_server_add_free, NULL);
1020 _ecore_con_event_count++;
1024 ecore_con_event_server_add(Ecore_Con_Server *svr)
1026 /* we got our server! */
1027 Ecore_Con_Event_Server_Add *e;
1028 int ev = ECORE_CON_EVENT_SERVER_ADD;
1030 e = ecore_con_event_server_add_alloc();
1031 EINA_SAFETY_ON_NULL_RETURN(e);
1033 svr->connecting = EINA_FALSE;
1034 svr->start_time = ecore_time_get();
1035 svr->event_count = eina_list_append(svr->event_count, e);
1036 _ecore_con_server_timer_update(svr);
1038 if (svr->upgrade) ev = ECORE_CON_EVENT_SERVER_UPGRADE;
1039 ecore_event_add(ev, e,
1040 _ecore_con_event_server_add_free, NULL);
1041 _ecore_con_event_count++;
1045 ecore_con_event_server_del(Ecore_Con_Server *svr)
1047 Ecore_Con_Event_Server_Del *e;
1049 svr->delete_me = EINA_TRUE;
1050 INF("svr %p is dead", svr);
1051 e = ecore_con_event_server_del_alloc();
1052 EINA_SAFETY_ON_NULL_RETURN(e);
1054 svr->event_count = eina_list_append(svr->event_count, e);
1055 _ecore_con_server_timer_update(svr);
1059 svr->ecs_state = svr->ecs->lookup ? ECORE_CON_PROXY_STATE_RESOLVED : ECORE_CON_PROXY_STATE_DONE;
1060 eina_stringshare_replace(&svr->proxyip, NULL);
1063 ecore_event_add(ECORE_CON_EVENT_SERVER_DEL, e,
1064 _ecore_con_event_server_del_free, NULL);
1065 _ecore_con_event_count++;
1069 ecore_con_event_server_write(Ecore_Con_Server *svr, int num)
1071 Ecore_Con_Event_Server_Write *e;
1073 e = ecore_con_event_server_write_alloc();
1074 EINA_SAFETY_ON_NULL_RETURN(e);
1076 INF("Wrote %d bytes", num);
1077 svr->event_count = eina_list_append(svr->event_count, e);
1080 ecore_event_add(ECORE_CON_EVENT_SERVER_WRITE, e,
1081 (Ecore_End_Cb)_ecore_con_event_server_write_free, NULL);
1082 _ecore_con_event_count++;
1086 ecore_con_event_server_data(Ecore_Con_Server *svr, unsigned char *buf, int num, Eina_Bool duplicate)
1088 Ecore_Con_Event_Server_Data *e;
1090 e = ecore_con_event_server_data_alloc();
1091 EINA_SAFETY_ON_NULL_RETURN(e);
1093 svr->event_count = eina_list_append(svr->event_count, e);
1094 _ecore_con_server_timer_update(svr);
1098 e->data = malloc(num);
1101 ERR("server data allocation failure !");
1102 _ecore_con_event_server_data_free(NULL, e);
1105 memcpy(e->data, buf, num);
1110 ecore_event_add(ECORE_CON_EVENT_SERVER_DATA, e,
1111 _ecore_con_event_server_data_free, NULL);
1112 _ecore_con_event_count++;
1116 ecore_con_event_client_add(Ecore_Con_Client *cl)
1118 Ecore_Con_Event_Client_Add *e;
1119 int ev = ECORE_CON_EVENT_CLIENT_ADD;
1121 e = ecore_con_event_client_add_alloc();
1122 EINA_SAFETY_ON_NULL_RETURN(e);
1124 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);
1127 cl->start_time = ecore_time_get();
1129 if (cl->upgrade) ev = ECORE_CON_EVENT_CLIENT_UPGRADE;
1130 ecore_event_add(ev, e,
1131 (Ecore_End_Cb)_ecore_con_event_client_add_free, cl->host_server);
1132 _ecore_con_event_count++;
1136 ecore_con_event_client_del(Ecore_Con_Client *cl)
1138 Ecore_Con_Event_Client_Del *e;
1141 cl->delete_me = EINA_TRUE;
1142 INF("cl %p is dead", cl);
1143 e = ecore_con_event_client_del_alloc();
1144 EINA_SAFETY_ON_NULL_RETURN(e);
1145 cl->event_count = eina_list_append(cl->event_count, e);
1147 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1148 _ecore_con_cl_timer_update(cl);
1150 ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
1151 (Ecore_End_Cb)_ecore_con_event_client_del_free, cl->host_server);
1152 _ecore_con_event_count++;
1156 ecore_con_event_client_write(Ecore_Con_Client *cl, int num)
1158 Ecore_Con_Event_Client_Write *e;
1160 e = ecore_con_event_client_write_alloc();
1161 EINA_SAFETY_ON_NULL_RETURN(e);
1163 cl->event_count = eina_list_append(cl->event_count, e);
1164 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1167 ecore_event_add(ECORE_CON_EVENT_CLIENT_WRITE, e,
1168 (Ecore_End_Cb)_ecore_con_event_client_write_free, cl->host_server);
1169 _ecore_con_event_count++;
1173 ecore_con_event_client_data(Ecore_Con_Client *cl, unsigned char *buf, int num, Eina_Bool duplicate)
1175 Ecore_Con_Event_Client_Data *e;
1177 e = ecore_con_event_client_data_alloc();
1178 EINA_SAFETY_ON_NULL_RETURN(e);
1180 cl->event_count = eina_list_append(cl->event_count, e);
1181 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1182 _ecore_con_cl_timer_update(cl);
1186 e->data = malloc(num);
1189 ERR("client data allocation failure !");
1190 _ecore_con_event_client_data_free(cl->host_server, e);
1193 memcpy(e->data, buf, num);
1198 ecore_event_add(ECORE_CON_EVENT_CLIENT_DATA, e,
1199 (Ecore_End_Cb)_ecore_con_event_client_data_free, cl->host_server);
1200 _ecore_con_event_count++;
1205 ecore_con_server_infos_del(Ecore_Con_Server *svr, void *info)
1207 svr->infos = eina_list_remove(svr->infos, info);
1211 _ecore_con_event_server_error(Ecore_Con_Server *svr, char *error, Eina_Bool duplicate)
1213 Ecore_Con_Event_Server_Error *e;
1215 e = ecore_con_event_server_error_alloc();
1216 EINA_SAFETY_ON_NULL_RETURN(e);
1219 e->error = duplicate ? strdup(error) : error;
1221 svr->event_count = eina_list_append(svr->event_count, e);
1222 ecore_event_add(ECORE_CON_EVENT_SERVER_ERROR, e, (Ecore_End_Cb)_ecore_con_event_server_error_free, NULL);
1223 _ecore_con_event_count++;
1227 ecore_con_event_client_error(Ecore_Con_Client *cl, const char *error)
1229 Ecore_Con_Event_Client_Error *e;
1231 e = ecore_con_event_client_error_alloc();
1232 EINA_SAFETY_ON_NULL_RETURN(e);
1235 e->error = strdup(error);
1237 cl->event_count = eina_list_append(cl->event_count, e);
1238 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1239 ecore_event_add(ECORE_CON_EVENT_CLIENT_ERROR, e, (Ecore_End_Cb)_ecore_con_event_client_error_free, cl->host_server);
1240 _ecore_con_event_count++;
1244 _ecore_con_server_free(Ecore_Con_Server *svr)
1246 Ecore_Con_Client *cl;
1249 if (svr->event_count) return;
1253 ecore_con_info_data_clear(svr->infos->data);
1254 svr->infos = eina_list_remove_list(svr->infos, svr->infos);
1257 t_start = ecore_time_get();
1258 while (svr->buf && (!svr->delete_me))
1260 _ecore_con_server_flush(svr);
1261 t = ecore_time_get();
1262 if ((t - t_start) > 0.5)
1264 WRN("ECORE_CON: EEK - stuck in _ecore_con_server_free() trying\n"
1265 " to flush data out from the server, and have been for\n"
1266 " %1.1f seconds. This is taking too long. Aborting flush.",
1273 ecore_con_local_win32_server_del(svr);
1275 if (svr->event_count) return;
1276 ECORE_MAGIC_SET(svr, ECORE_MAGIC_NONE);
1279 eina_binbuf_free(svr->buf);
1281 EINA_LIST_FREE(svr->clients, cl)
1283 Ecore_Con_Event_Server_Add *ev;
1285 /* some pointer hacks here to prevent double frees if people are being stupid */
1286 EINA_LIST_FREE(cl->event_count, ev)
1288 cl->delete_me = EINA_TRUE;
1289 INF("cl %p is dead", cl);
1290 _ecore_con_client_free(cl);
1292 if ((svr->created) && (svr->path) && (svr->ppid == getpid()))
1295 ecore_con_ssl_server_shutdown(svr);
1300 eina_stringshare_del(svr->ip);
1301 eina_stringshare_del(svr->verify_name);
1303 if (svr->ecs_buf) eina_binbuf_free(svr->ecs_buf);
1304 if (svr->ecs_recvbuf) eina_binbuf_free(svr->ecs_recvbuf);
1306 if (svr->fd_handler)
1307 ecore_main_fd_handler_del(svr->fd_handler);
1312 if (svr->until_deletion)
1313 ecore_timer_del(svr->until_deletion);
1315 servers = eina_list_remove(servers, svr);
1321 _ecore_con_client_free(Ecore_Con_Client *cl)
1325 if (cl->event_count) return;
1327 t_start = ecore_time_get();
1328 while ((cl->buf) && (!cl->delete_me))
1330 _ecore_con_client_flush(cl);
1331 t = ecore_time_get();
1332 if ((t - t_start) > 0.5)
1334 WRN("EEK - stuck in _ecore_con_client_free() trying\n"
1335 " to flush data out from the client, and have been for\n"
1336 " %1.1f seconds. This is taking too long. Aborting flush.",
1341 cl->host_server->clients = eina_list_remove(cl->host_server->clients, cl);
1342 --cl->host_server->client_count;
1345 ecore_con_local_win32_client_del(cl);
1348 if (cl->event_count) return;
1349 ECORE_MAGIC_SET(cl, ECORE_MAGIC_NONE);
1351 if (cl->buf) eina_binbuf_free(cl->buf);
1353 if (cl->host_server->type & ECORE_CON_SSL)
1354 ecore_con_ssl_client_shutdown(cl);
1357 ecore_main_fd_handler_del(cl->fd_handler);
1362 free(cl->client_addr);
1363 cl->client_addr = NULL;
1365 if (cl->until_deletion)
1366 ecore_timer_del(cl->until_deletion);
1368 eina_stringshare_del(cl->ip);
1375 _ecore_con_server_timer(Ecore_Con_Server *svr)
1377 ecore_con_server_del(svr);
1379 svr->until_deletion = NULL;
1380 return ECORE_CALLBACK_CANCEL;
1384 _ecore_con_server_timer_update(Ecore_Con_Server *svr)
1386 if (svr->disconnect_time)
1388 if (svr->disconnect_time > 0)
1390 if (svr->until_deletion)
1392 ecore_timer_interval_set(svr->until_deletion, svr->disconnect_time);
1393 ecore_timer_reset(svr->until_deletion);
1396 svr->until_deletion = ecore_timer_add(svr->disconnect_time, (Ecore_Task_Cb)_ecore_con_server_timer, svr);
1398 else if (svr->until_deletion)
1400 ecore_timer_del(svr->until_deletion);
1401 svr->until_deletion = NULL;
1406 if (svr->until_deletion)
1408 ecore_timer_del(svr->until_deletion);
1409 svr->until_deletion = NULL;
1415 _ecore_con_client_timer(Ecore_Con_Client *cl)
1417 ecore_con_client_del(cl);
1419 cl->until_deletion = NULL;
1420 return ECORE_CALLBACK_CANCEL;
1424 _ecore_con_cl_timer_update(Ecore_Con_Client *cl)
1426 if (cl->disconnect_time)
1428 if (cl->disconnect_time > 0)
1430 if (cl->until_deletion)
1432 ecore_timer_interval_set(cl->until_deletion, cl->disconnect_time);
1433 ecore_timer_reset(cl->until_deletion);
1436 cl->until_deletion = ecore_timer_add(cl->disconnect_time, (Ecore_Task_Cb)_ecore_con_client_timer, cl);
1438 else if (cl->until_deletion)
1440 ecore_timer_del(cl->until_deletion);
1441 cl->until_deletion = NULL;
1446 if (cl->host_server->client_disconnect_time > 0)
1448 if (cl->until_deletion)
1450 ecore_timer_interval_set(cl->until_deletion, cl->host_server->client_disconnect_time);
1451 ecore_timer_reset(cl->until_deletion);
1454 cl->until_deletion = ecore_timer_add(cl->host_server->client_disconnect_time, (Ecore_Task_Cb)_ecore_con_client_timer, cl);
1456 else if (cl->until_deletion)
1458 ecore_timer_del(cl->until_deletion);
1459 cl->until_deletion = NULL;
1465 _ecore_con_cb_tcp_listen(void *data,
1466 Ecore_Con_Info *net_info)
1468 Ecore_Con_Server *svr;
1470 const char *memerr = NULL;
1475 if (!net_info) /* error message has already been handled */
1477 svr->delete_me = EINA_TRUE;
1481 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1482 net_info->info.ai_protocol);
1483 if (svr->fd < 0) goto error;
1484 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1485 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1489 if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, (const void *)&lin,
1490 sizeof(struct linger)) < 0)
1493 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY)
1495 #ifdef HAVE_NETINET_TCP_H
1498 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag,
1506 if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
1509 if (listen(svr->fd, 4096) < 0) goto error;
1511 svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
1512 _ecore_con_svr_tcp_handler, svr, NULL, NULL);
1513 if (!svr->fd_handler)
1515 memerr = "Memory allocation failure";
1522 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1523 ecore_con_ssl_server_shutdown(svr);
1524 _ecore_con_server_kill(svr);
1528 _ecore_con_cb_udp_listen(void *data,
1529 Ecore_Con_Info *net_info)
1531 Ecore_Con_Server *svr;
1532 Ecore_Con_Type type;
1533 struct ip_mreq mreq;
1535 struct ipv6_mreq mreq6;
1538 const char *memerr = NULL;
1542 type &= ECORE_CON_TYPE;
1545 if (!net_info) /* error message has already been handled */
1547 svr->delete_me = EINA_TRUE;
1551 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1552 net_info->info.ai_protocol);
1553 if (svr->fd < 0) goto error;
1555 if (type == ECORE_CON_REMOTE_MCAST)
1557 if (net_info->info.ai_family == AF_INET)
1559 if (!inet_pton(net_info->info.ai_family, net_info->ip,
1560 &mreq.imr_multiaddr))
1563 mreq.imr_interface.s_addr = htonl(INADDR_ANY);
1564 if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
1565 (const void *)&mreq, sizeof(mreq)) != 0)
1569 else if (net_info->info.ai_family == AF_INET6)
1571 if (!inet_pton(net_info->info.ai_family, net_info->ip,
1572 &mreq6.ipv6mr_multiaddr))
1574 mreq6.ipv6mr_interface = htonl(INADDR_ANY);
1575 if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
1576 (const void *)&mreq6, sizeof(mreq6)) != 0)
1582 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof(on)) != 0)
1584 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1585 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1587 if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
1591 ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
1592 _ecore_con_svr_udp_handler, svr, NULL, NULL);
1593 if (!svr->fd_handler)
1595 memerr = "Memory allocation failure";
1599 svr->ip = eina_stringshare_add(net_info->ip);
1604 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1605 ecore_con_ssl_server_shutdown(svr);
1606 _ecore_con_server_kill(svr);
1610 _ecore_con_cb_tcp_connect(void *data,
1611 Ecore_Con_Info *net_info)
1613 Ecore_Con_Server *svr;
1616 const char *memerr = NULL;
1621 if (!net_info) /* error message has already been handled */
1623 svr->delete_me = EINA_TRUE;
1627 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1628 net_info->info.ai_protocol);
1629 if (svr->fd < 0) goto error;
1631 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1632 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1634 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate, sizeof(curstate)) < 0)
1637 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY)
1639 #ifdef HAVE_NETINET_TCP_H
1642 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)) < 0)
1649 res = connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen);
1651 if (res == SOCKET_ERROR)
1653 if (WSAGetLastError() != WSAEINPROGRESS)
1656 err = evil_format_message(WSAGetLastError());
1657 _ecore_con_event_server_error(svr, err, EINA_FALSE);
1658 ecore_con_ssl_server_shutdown(svr);
1659 _ecore_con_server_kill(svr);
1666 if (errno != EINPROGRESS) goto error;
1668 svr->connecting = EINA_TRUE;
1670 ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE,
1671 _ecore_con_cl_handler, svr, NULL, NULL);
1674 svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
1675 _ecore_con_cl_handler, svr, NULL, NULL);
1677 if (svr->type & ECORE_CON_SSL)
1679 svr->handshaking = EINA_TRUE;
1680 svr->ssl_state = ECORE_CON_SSL_STATE_INIT;
1681 DBG("%s ssl handshake", svr->ecs_state ? "Queuing" : "Beginning");
1682 if ((!svr->ecs_state) && ecore_con_ssl_server_init(svr))
1686 if (!svr->fd_handler)
1688 memerr = "Memory allocation failure";
1692 if ((!svr->ecs) || (svr->ecs->lookup))
1693 svr->ip = eina_stringshare_add(net_info->ip);
1698 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1699 ecore_con_ssl_server_shutdown(svr);
1700 _ecore_con_server_kill(svr);
1704 _ecore_con_cb_udp_connect(void *data,
1705 Ecore_Con_Info *net_info)
1707 Ecore_Con_Server *svr;
1710 const char *memerr = NULL;
1714 if (!net_info) /* error message has already been handled */
1716 svr->delete_me = EINA_TRUE;
1720 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1721 net_info->info.ai_protocol);
1722 if (svr->fd < 0) goto error;
1723 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1724 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1725 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_BROADCAST)
1727 if (setsockopt(svr->fd, SOL_SOCKET, SO_BROADCAST,
1728 (const void *)&broadcast,
1729 sizeof(broadcast)) < 0)
1734 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR,
1735 (const void *)&curstate, sizeof(curstate)) < 0)
1738 if (connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
1741 svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE,
1742 _ecore_con_cl_udp_handler, svr, NULL, NULL);
1744 if (!svr->fd_handler)
1746 memerr = "Memory allocation failure";
1750 if ((!svr->ecs) || (svr->ecs->lookup))
1751 svr->ip = eina_stringshare_add(net_info->ip);
1756 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1757 ecore_con_ssl_server_shutdown(svr);
1758 _ecore_con_server_kill(svr);
1761 static Ecore_Con_State
1762 svr_try_connect_plain(Ecore_Con_Server *svr)
1766 socklen_t size = sizeof(int);
1768 res = getsockopt(svr->fd, SOL_SOCKET, SO_ERROR, (void *)&so_err, &size);
1770 if (res == SOCKET_ERROR)
1771 so_err = WSAGetLastError();
1773 if ((so_err == WSAEINPROGRESS) && !svr->delete_me)
1774 return ECORE_CON_INPROGRESS;
1780 if ((so_err == EINPROGRESS) && !svr->delete_me)
1781 return ECORE_CON_INPROGRESS;
1787 /* we lost our server! */
1788 ecore_con_event_server_error(svr, strerror(so_err));
1789 ERR("Connection lost: %s", strerror(so_err));
1790 _ecore_con_server_kill(svr);
1791 return ECORE_CON_DISCONNECTED;
1794 if ((!svr->delete_me) && (!svr->handshaking) && svr->connecting)
1798 if (ecore_con_socks_svr_init(svr))
1799 return ECORE_CON_INPROGRESS;
1802 ecore_con_event_server_add(svr);
1805 if (svr->fd_handler)
1808 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE);
1810 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
1813 if (!svr->delete_me)
1814 return ECORE_CON_CONNECTED;
1816 return ECORE_CON_DISCONNECTED;
1820 _ecore_con_pretty_ip(struct sockaddr *client_addr)
1823 char ipbuf[INET_ADDRSTRLEN + 1];
1825 char ipbuf[INET6_ADDRSTRLEN + 1];
1827 int family = client_addr->sa_family;
1833 src = &(((struct sockaddr_in *)client_addr)->sin_addr);
1837 src = &(((struct sockaddr_in6 *)client_addr)->sin6_addr);
1839 if (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)src))
1842 src = (char*)src + 12;
1847 return eina_stringshare_add("0.0.0.0");
1850 if (!inet_ntop(family, src, ipbuf, sizeof(ipbuf)))
1851 return eina_stringshare_add("0.0.0.0");
1853 ipbuf[sizeof(ipbuf) - 1] = 0;
1854 return eina_stringshare_add(ipbuf);
1858 _ecore_con_svr_tcp_handler(void *data,
1859 Ecore_Fd_Handler *fd_handler __UNUSED__)
1861 Ecore_Con_Server *svr;
1862 Ecore_Con_Client *cl = NULL;
1863 unsigned char client_addr[256];
1864 unsigned int client_addr_len;
1865 const char *clerr = NULL;
1869 return ECORE_CALLBACK_RENEW;
1871 if ((svr->client_limit >= 0) && (!svr->reject_excess_clients) &&
1872 (svr->client_count >= (unsigned int)svr->client_limit))
1873 return ECORE_CALLBACK_RENEW;
1877 cl = calloc(1, sizeof(Ecore_Con_Client));
1880 ecore_con_event_server_error(svr, "Memory allocation failure when attempting to add a new client");
1881 return ECORE_CALLBACK_RENEW;
1883 cl->host_server = svr;
1885 client_addr_len = sizeof(client_addr);
1886 memset(&client_addr, 0, client_addr_len);
1887 cl->fd = accept(svr->fd, (struct sockaddr *)&client_addr, (socklen_t *)&client_addr_len);
1888 if (cl->fd < 0) goto error;
1889 if ((svr->client_limit >= 0) && (svr->reject_excess_clients) &&
1890 (svr->client_count >= (unsigned int)svr->client_limit))
1892 clerr = "Maximum client limit reached";
1896 if (fcntl(cl->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1897 if (fcntl(cl->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1898 cl->fd_handler = ecore_main_fd_handler_add(cl->fd, ECORE_FD_READ,
1899 _ecore_con_svr_cl_handler, cl, NULL, NULL);
1900 if (!cl->fd_handler) goto error;
1901 ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
1903 if ((!svr->upgrade) && (svr->type & ECORE_CON_SSL))
1905 cl->handshaking = EINA_TRUE;
1906 cl->ssl_state = ECORE_CON_SSL_STATE_INIT;
1907 if (ecore_con_ssl_client_init(cl))
1911 cl->client_addr = malloc(client_addr_len);
1912 if (!cl->client_addr)
1914 clerr = "Memory allocation failure when attempting to add a new client";
1917 cl->client_addr_len = client_addr_len;
1918 memcpy(cl->client_addr, &client_addr, client_addr_len);
1920 svr->clients = eina_list_append(svr->clients, cl);
1921 svr->client_count++;
1923 if ((!cl->delete_me) && (!cl->handshaking))
1924 ecore_con_event_client_add(cl);
1926 return ECORE_CALLBACK_RENEW;
1929 if (cl->fd_handler) ecore_main_fd_handler_del(cl->fd_handler);
1930 if (cl->fd >= 0) close(cl->fd);
1934 EINA_LIST_FREE(cl->event_count, ev)
1936 svr->event_count = eina_list_remove(svr->event_count, ev);
1937 ecore_event_del(ev);
1941 if (clerr || errno) ecore_con_event_server_error(svr, clerr ?: strerror(errno));
1942 return ECORE_CALLBACK_RENEW;
1946 _ecore_con_cl_read(Ecore_Con_Server *svr)
1949 Eina_Bool lost_server = EINA_TRUE;
1950 unsigned char buf[READBUFSIZ];
1954 /* only possible with non-ssl connections */
1955 if (svr->connecting && (svr_try_connect_plain(svr) != ECORE_CON_CONNECTED))
1958 if (svr->handshaking && (!svr->ecs_state))
1960 DBG("Continuing ssl handshake");
1961 if (!ecore_con_ssl_server_init(svr))
1962 lost_server = EINA_FALSE;
1963 _ecore_con_server_timer_update(svr);
1966 if (svr->ecs_state || !(svr->type & ECORE_CON_SSL))
1969 num = read(svr->fd, buf, sizeof(buf));
1970 /* 0 is not a valid return value for a tcp socket */
1971 if ((num > 0) || ((num < 0) && (errno == EAGAIN)))
1972 lost_server = EINA_FALSE;
1974 ecore_con_event_server_error(svr, strerror(errno));
1978 num = ecore_con_ssl_server_read(svr, buf, sizeof(buf));
1979 /* this is not an actual 0 return, 0 here just means non-fatal error such as EAGAIN */
1981 lost_server = EINA_FALSE;
1984 if ((!svr->delete_me) && (num > 0))
1987 ecore_con_socks_read(svr, buf, num);
1989 ecore_con_event_server_data(svr, buf, num, EINA_TRUE);
1993 _ecore_con_server_kill(svr);
1997 _ecore_con_cl_handler(void *data,
1998 Ecore_Fd_Handler *fd_handler)
2000 Ecore_Con_Server *svr;
2001 Eina_Bool want_read, want_write;
2005 return ECORE_CALLBACK_RENEW;
2008 return ECORE_CALLBACK_RENEW;
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);
2013 if ((!svr->ecs_state) && svr->handshaking && (want_read || want_write))
2015 DBG("Continuing ssl handshake: preparing to %s...", want_read ? "read" : "write");
2019 char buf[READBUFSIZ];
2021 len = recv(svr->fd, buf, sizeof(buf), MSG_DONTWAIT | MSG_PEEK);
2022 DBG("%zu bytes in buffer", len);
2025 if (ecore_con_ssl_server_init(svr))
2027 ERR("ssl handshaking failed!");
2028 svr->handshaking = EINA_FALSE;
2030 else if (!svr->ssl_state)
2031 ecore_con_event_server_add(svr);
2032 return ECORE_CALLBACK_RENEW;
2034 if (svr->ecs && svr->ecs_state && (svr->ecs_state < ECORE_CON_PROXY_STATE_READ) && (!svr->ecs_buf))
2036 if (svr->ecs_state < ECORE_CON_PROXY_STATE_INIT)
2038 INF("PROXY STATE++");
2041 if (ecore_con_socks_svr_init(svr)) return ECORE_CALLBACK_RENEW;
2044 _ecore_con_cl_read(svr);
2045 else if (want_write) /* only possible with non-ssl connections */
2047 if (svr->connecting && (!svr_try_connect_plain(svr)) && (!svr->ecs_state))
2048 return ECORE_CALLBACK_RENEW;
2050 _ecore_con_server_flush(svr);
2053 return ECORE_CALLBACK_RENEW;
2057 _ecore_con_cl_udp_handler(void *data,
2058 Ecore_Fd_Handler *fd_handler)
2060 unsigned char buf[READBUFSIZ];
2062 Ecore_Con_Server *svr;
2063 Eina_Bool want_read, want_write;
2065 want_read = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ);
2066 want_write = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE);
2069 if (svr->delete_me || svr->delete_me || ((!want_read) && (!want_write)))
2070 return ECORE_CALLBACK_RENEW;
2074 _ecore_con_server_flush(svr);
2075 return ECORE_CALLBACK_RENEW;
2078 num = read(svr->fd, buf, READBUFSIZ);
2080 if ((!svr->delete_me) && (num > 0))
2081 ecore_con_event_server_data(svr, buf, num, EINA_TRUE);
2083 if (num < 0 && (errno != EAGAIN) && (errno != EINTR))
2085 ecore_con_event_server_error(svr, strerror(errno));
2086 _ecore_con_server_kill(svr);
2089 return ECORE_CALLBACK_RENEW;
2093 _ecore_con_svr_udp_handler(void *data,
2094 Ecore_Fd_Handler *fd_handler)
2096 unsigned char buf[READBUFSIZ];
2097 unsigned char client_addr[256];
2098 socklen_t client_addr_len = sizeof(client_addr);
2100 Ecore_Con_Server *svr;
2101 Ecore_Con_Client *cl = NULL;
2106 return ECORE_CALLBACK_RENEW;
2108 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
2110 _ecore_con_client_flush(cl);
2111 return ECORE_CALLBACK_RENEW;
2114 if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
2115 return ECORE_CALLBACK_RENEW;
2118 num = fcntl(svr->fd, F_SETFL, O_NONBLOCK);
2120 num = recvfrom(svr->fd, (char *)buf, sizeof(buf), 0,
2121 (struct sockaddr *)&client_addr,
2125 num = recvfrom(svr->fd, buf, sizeof(buf), MSG_DONTWAIT,
2126 (struct sockaddr *)&client_addr,
2130 if (num < 0 && (errno != EAGAIN) && (errno != EINTR))
2132 ecore_con_event_server_error(svr, strerror(errno));
2133 if (!svr->delete_me)
2134 ecore_con_event_client_del(NULL);
2135 _ecore_con_server_kill(svr);
2136 return ECORE_CALLBACK_CANCEL;
2140 /* Create a new client for use in the client data event */
2141 cl = calloc(1, sizeof(Ecore_Con_Client));
2142 EINA_SAFETY_ON_NULL_RETURN_VAL(cl, ECORE_CALLBACK_RENEW);
2144 cl->host_server = svr;
2145 cl->client_addr = malloc(client_addr_len);
2146 if (!cl->client_addr)
2149 return ECORE_CALLBACK_RENEW;
2151 cl->client_addr_len = client_addr_len;
2153 memcpy(cl->client_addr, &client_addr, client_addr_len);
2154 ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
2155 svr->clients = eina_list_append(svr->clients, cl);
2156 svr->client_count++;
2158 ecore_con_event_client_add(cl);
2159 ecore_con_event_client_data(cl, buf, num, EINA_TRUE);
2161 return ECORE_CALLBACK_RENEW;
2165 _ecore_con_svr_cl_read(Ecore_Con_Client *cl)
2168 Eina_Bool lost_client = EINA_TRUE;
2169 unsigned char buf[READBUFSIZ];
2173 if (cl->handshaking)
2175 /* add an extra handshake attempt just before read, even though
2176 * read also attempts to handshake, to try to finish sooner
2178 if (ecore_con_ssl_client_init(cl))
2179 lost_client = EINA_FALSE;
2181 _ecore_con_cl_timer_update(cl);
2184 if (!(cl->host_server->type & ECORE_CON_SSL) && (!cl->upgrade))
2186 num = read(cl->fd, buf, sizeof(buf));
2187 /* 0 is not a valid return value for a tcp socket */
2188 if ((num > 0) || ((num < 0) && ((errno == EAGAIN) || (errno == EINTR))))
2189 lost_client = EINA_FALSE;
2191 ecore_con_event_client_error(cl, strerror(errno));
2195 num = ecore_con_ssl_client_read(cl, buf, sizeof(buf));
2196 /* this is not an actual 0 return, 0 here just means non-fatal error such as EAGAIN */
2198 lost_client = EINA_FALSE;
2201 if ((!cl->delete_me) && (num > 0))
2202 ecore_con_event_client_data(cl, buf, num, EINA_TRUE);
2204 if (lost_client) _ecore_con_client_kill(cl);
2208 _ecore_con_svr_cl_handler(void *data,
2209 Ecore_Fd_Handler *fd_handler)
2211 Ecore_Con_Client *cl;
2215 return ECORE_CALLBACK_RENEW;
2217 if (cl->handshaking && ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ | ECORE_FD_WRITE))
2219 if (ecore_con_ssl_client_init(cl))
2221 ERR("ssl handshaking failed!");
2222 _ecore_con_client_kill(cl);
2223 return ECORE_CALLBACK_RENEW;
2225 else if (!cl->ssl_state)
2226 ecore_con_event_client_add(cl);
2228 else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
2229 _ecore_con_svr_cl_read(cl);
2231 else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
2232 _ecore_con_client_flush(cl);
2234 return ECORE_CALLBACK_RENEW;
2238 _ecore_con_server_flush(Ecore_Con_Server *svr)
2242 unsigned int *buf_offset;
2243 const unsigned char *buf;
2246 DBG("(svr=%p,buf=%p)", svr, svr->buf);
2247 if (!svr->fd_handler) return;
2249 if (ecore_con_local_win32_server_flush(svr))
2253 if ((!svr->buf) && (!svr->ecs_buf))
2255 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
2262 buf_offset = &(svr->write_buf_offset);
2266 buf_p = svr->ecs_buf;
2267 buf_offset = &(svr->ecs_buf_offset);
2269 buf = eina_binbuf_string_get(buf_p);
2270 buf_len = eina_binbuf_length_get(buf_p);
2271 num = buf_len - *buf_offset;
2273 /* check whether we need to write anything at all.
2274 * we must not write zero bytes with SSL_write() since it
2275 * causes undefined behaviour
2277 /* we thank Tommy[D] for needing to check negative buffer sizes
2278 * here because his system is amazing.
2280 if (num <= 0) return;
2282 if ((!svr->ecs_state) && svr->handshaking)
2284 DBG("Continuing ssl handshake");
2285 if (ecore_con_ssl_server_init(svr))
2286 _ecore_con_server_kill(svr);
2287 _ecore_con_server_timer_update(svr);
2291 if (svr->ecs_state || (!(svr->type & ECORE_CON_SSL)))
2292 count = write(svr->fd, buf + *buf_offset, num);
2294 count = ecore_con_ssl_server_write(svr, buf + *buf_offset, num);
2298 if ((errno != EAGAIN) && (errno != EINTR))
2300 ecore_con_event_server_error(svr, strerror(errno));
2301 _ecore_con_server_kill(svr);
2306 if (count && (!svr->ecs_state)) ecore_con_event_server_write(svr, count);
2308 if (!eina_binbuf_remove(buf_p, 0, count))
2309 *buf_offset += count;
2315 if (*buf_offset >= buf_len)
2318 eina_binbuf_free(buf_p);
2322 svr->ecs_buf = NULL;
2323 INF("PROXY STATE++");
2330 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK)
2333 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
2334 /* realistically this isn't anything serious so we can just log and continue */
2335 ERR("uncorking failed! %s", strerror(errno));
2339 if (svr->fd_handler)
2340 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
2342 else if ((count < num) && svr->fd_handler)
2343 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE);
2347 _ecore_con_client_flush(Ecore_Con_Client *cl)
2349 int num = 0, count = 0;
2351 if (!cl->fd_handler) return;
2353 if (ecore_con_local_win32_client_flush(cl))
2359 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ);
2363 if (cl->handshaking)
2365 if (ecore_con_ssl_client_init(cl))
2368 _ecore_con_cl_timer_update(cl);
2373 if (!cl->buf) return;
2374 num = eina_binbuf_length_get(cl->buf) - cl->buf_offset;
2375 if (num <= 0) return;
2376 if (!(cl->host_server->type & ECORE_CON_SSL) && (!cl->upgrade))
2377 count = write(cl->fd, eina_binbuf_string_get(cl->buf) + cl->buf_offset, num);
2379 count = ecore_con_ssl_client_write(cl, eina_binbuf_string_get(cl->buf) + cl->buf_offset, num);
2384 if ((errno != EAGAIN) && (errno != EINTR) && (!cl->delete_me))
2386 ecore_con_event_client_error(cl, strerror(errno));
2387 _ecore_con_client_kill(cl);
2393 if (count) ecore_con_event_client_write(cl, count);
2394 cl->buf_offset += count, num -= count;
2395 if (cl->buf_offset >= eina_binbuf_length_get(cl->buf))
2398 eina_binbuf_free(cl->buf);
2401 if ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK)
2404 if (setsockopt(cl->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
2405 /* realistically this isn't anything serious so we can just log and continue */
2406 ERR("uncorking failed! %s", strerror(errno));
2410 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ);
2412 else if (cl->fd_handler && (num >= 0))
2413 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_WRITE);
2417 _ecore_con_event_client_add_free(Ecore_Con_Server *svr,
2420 Ecore_Con_Event_Client_Add *e;
2425 Eina_Bool svrfreed = EINA_FALSE;
2427 e->client->event_count = eina_list_remove(e->client->event_count, e);
2428 if (e->client->host_server)
2430 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, ev);
2431 if ((!svr->event_count) && (svr->delete_me))
2433 _ecore_con_server_free(svr);
2434 svrfreed = EINA_TRUE;
2439 if ((!e->client->event_count) && (e->client->delete_me))
2440 ecore_con_client_del(e->client);
2444 ecore_con_event_client_add_free(e);
2445 _ecore_con_event_count--;
2446 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2447 ecore_con_mempool_shutdown();
2451 _ecore_con_event_client_del_free(Ecore_Con_Server *svr,
2454 Ecore_Con_Event_Client_Del *e;
2459 Eina_Bool svrfreed = EINA_FALSE;
2461 e->client->event_count = eina_list_remove(e->client->event_count, e);
2462 if (e->client->host_server)
2464 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, ev);
2465 if ((!svr->event_count) && (svr->delete_me))
2467 _ecore_con_server_free(svr);
2468 svrfreed = EINA_TRUE;
2473 if (!e->client->event_count)
2474 _ecore_con_client_free(e->client);
2477 ecore_con_event_client_del_free(e);
2478 _ecore_con_event_count--;
2479 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2480 ecore_con_mempool_shutdown();
2484 _ecore_con_event_client_write_free(Ecore_Con_Server *svr,
2485 Ecore_Con_Event_Client_Write *e)
2489 Eina_Bool svrfreed = EINA_FALSE;
2491 e->client->event_count = eina_list_remove(e->client->event_count, e);
2492 if (e->client->host_server)
2494 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, e);
2495 if ((!svr->event_count) && (svr->delete_me))
2497 _ecore_con_server_free(svr);
2498 svrfreed = EINA_TRUE;
2503 if (((!e->client->event_count) && (e->client->delete_me)) ||
2504 ((e->client->host_server &&
2505 ((e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP ||
2506 (e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_MCAST))))
2507 ecore_con_client_del(e->client);
2510 ecore_con_event_client_write_free(e);
2511 _ecore_con_event_count--;
2512 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2513 ecore_con_mempool_shutdown();
2517 _ecore_con_event_client_data_free(Ecore_Con_Server *svr,
2520 Ecore_Con_Event_Client_Data *e;
2525 Eina_Bool svrfreed = EINA_FALSE;
2527 e->client->event_count = eina_list_remove(e->client->event_count, e);
2528 if (e->client->host_server)
2530 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, ev);
2532 if ((!svr->event_count) && (svr->delete_me))
2534 _ecore_con_server_free(svr);
2535 svrfreed = EINA_TRUE;
2539 if (((!e->client->event_count) && (e->client->delete_me)) ||
2540 ((e->client->host_server &&
2541 ((e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP ||
2542 (e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_MCAST))))
2543 ecore_con_client_del(e->client);
2547 ecore_con_event_client_data_free(e);
2548 _ecore_con_event_count--;
2549 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2550 ecore_con_mempool_shutdown();
2554 _ecore_con_event_server_add_free(void *data __UNUSED__,
2557 Ecore_Con_Event_Server_Add *e;
2562 e->server->event_count = eina_list_remove(e->server->event_count, ev);
2563 if ((!e->server->event_count) && (e->server->delete_me))
2564 _ecore_con_server_free(e->server);
2566 ecore_con_event_server_add_free(e);
2567 _ecore_con_event_count--;
2568 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2569 ecore_con_mempool_shutdown();
2573 _ecore_con_event_server_del_free(void *data __UNUSED__,
2576 Ecore_Con_Event_Server_Del *e;
2581 e->server->event_count = eina_list_remove(e->server->event_count, ev);
2582 if (!e->server->event_count)
2583 _ecore_con_server_free(e->server);
2585 ecore_con_event_server_del_free(e);
2586 _ecore_con_event_count--;
2587 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2588 ecore_con_mempool_shutdown();
2592 _ecore_con_event_server_write_free(void *data __UNUSED__,
2593 Ecore_Con_Event_Server_Write *e)
2597 e->server->event_count = eina_list_remove(e->server->event_count, e);
2598 if ((!e->server->event_count) && (e->server->delete_me))
2599 _ecore_con_server_free(e->server);
2602 ecore_con_event_server_write_free(e);
2603 _ecore_con_event_count--;
2604 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2605 ecore_con_mempool_shutdown();
2609 _ecore_con_event_server_data_free(void *data __UNUSED__,
2612 Ecore_Con_Event_Server_Data *e;
2617 e->server->event_count = eina_list_remove(e->server->event_count, ev);
2618 if ((!e->server->event_count) && (e->server->delete_me))
2619 _ecore_con_server_free(e->server);
2623 ecore_con_event_server_data_free(e);
2624 _ecore_con_event_count--;
2625 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2626 ecore_con_mempool_shutdown();
2631 _ecore_con_event_server_error_free(void *data __UNUSED__, Ecore_Con_Event_Server_Error *e)
2635 e->server->event_count = eina_list_remove(e->server->event_count, e);
2636 if ((!e->server->event_count) && (e->server->delete_me))
2637 _ecore_con_server_free(e->server);
2640 ecore_con_event_server_error_free(e);
2641 _ecore_con_event_count--;
2642 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2643 ecore_con_mempool_shutdown();
2647 _ecore_con_event_client_error_free(Ecore_Con_Server *svr, Ecore_Con_Event_Client_Error *e)
2651 Eina_Bool svrfreed = EINA_FALSE;
2653 if (eina_list_data_find(svr->clients, e->client))
2655 e->client->event_count = eina_list_remove(e->client->event_count, e);
2656 if ((!e->client->event_count) && (e->client->delete_me))
2658 _ecore_con_client_free(e->client);
2659 svrfreed = EINA_TRUE;
2662 svr->event_count = eina_list_remove(svr->event_count, e);
2665 if ((!svr->event_count) && (svr->delete_me))
2666 _ecore_con_server_free(svr);
2670 ecore_con_event_client_error_free(e);
2671 _ecore_con_event_count--;
2672 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2673 ecore_con_mempool_shutdown();
2677 _ecore_con_lookup_done(void *data,
2678 Ecore_Con_Info *infos)
2680 Ecore_Con_Server *svr;
2681 Ecore_Con_Lookup *lk;
2687 lk->done_cb(infos->info.ai_canonname, infos->ip,
2688 infos->info.ai_addr, infos->info.ai_addrlen,
2691 lk->done_cb(NULL, NULL, NULL, 0, (void *)lk->data);