13 #ifdef HAVE_NETINET_TCP_H
14 # include <netinet/tcp.h>
17 #ifdef HAVE_NETINET_IN_H
18 # include <netinet/in.h>
21 #ifdef HAVE_ARPA_INET_H
22 # include <arpa/inet.h>
25 #ifdef HAVE_SYS_SOCKET_H
26 # include <sys/socket.h>
33 #ifdef HAVE_WS2TCPIP_H
34 # include <ws2tcpip.h>
42 #include "ecore_private.h"
43 #include "Ecore_Con.h"
44 #include "ecore_con_private.h"
46 static Eina_Bool _ecore_con_client_timer(Ecore_Con_Client *cl);
47 static void _ecore_con_cl_timer_update(Ecore_Con_Client *cl);
48 static Eina_Bool _ecore_con_server_timer(Ecore_Con_Server *svr);
49 static void _ecore_con_server_timer_update(Ecore_Con_Server *svr);
51 static void _ecore_con_cb_tcp_connect(void *data,
52 Ecore_Con_Info *info);
53 static void _ecore_con_cb_udp_connect(void *data,
54 Ecore_Con_Info *info);
55 static void _ecore_con_cb_tcp_listen(void *data,
56 Ecore_Con_Info *info);
57 static void _ecore_con_cb_udp_listen(void *data,
58 Ecore_Con_Info *info);
60 static void _ecore_con_server_free(Ecore_Con_Server *svr);
61 static void _ecore_con_client_free(Ecore_Con_Client *cl);
63 static void _ecore_con_cl_read(Ecore_Con_Server *svr);
64 static Eina_Bool _ecore_con_svr_tcp_handler(void *data,
65 Ecore_Fd_Handler *fd_handler);
66 static Eina_Bool _ecore_con_cl_handler(void *data,
67 Ecore_Fd_Handler *fd_handler);
68 static Eina_Bool _ecore_con_cl_udp_handler(void *data,
69 Ecore_Fd_Handler *fd_handler);
70 static Eina_Bool _ecore_con_svr_udp_handler(void *data,
71 Ecore_Fd_Handler *fd_handler);
73 static void _ecore_con_svr_cl_read(Ecore_Con_Client *cl);
74 static Eina_Bool _ecore_con_svr_cl_handler(void *data,
75 Ecore_Fd_Handler *fd_handler);
77 static void _ecore_con_server_flush(Ecore_Con_Server *svr);
78 static void _ecore_con_client_flush(Ecore_Con_Client *cl);
80 static void _ecore_con_event_client_add_free(Ecore_Con_Server *svr,
82 static void _ecore_con_event_client_del_free(Ecore_Con_Server *svr,
84 static void _ecore_con_event_client_data_free(Ecore_Con_Server *svr,
86 static void _ecore_con_event_server_add_free(void *data,
88 static void _ecore_con_event_server_del_free(void *data,
90 static void _ecore_con_event_server_data_free(void *data,
92 static void _ecore_con_event_server_error_free(void *data,
93 Ecore_Con_Event_Server_Error *e);
94 static void _ecore_con_event_client_error_free(Ecore_Con_Server *svr,
95 Ecore_Con_Event_Client_Error *e);
96 static void _ecore_con_event_server_write_free(void *data,
97 Ecore_Con_Event_Server_Write *e);
98 static void _ecore_con_event_client_write_free(Ecore_Con_Server *svr,
99 Ecore_Con_Event_Client_Write *e);
101 static void _ecore_con_lookup_done(void *data,
102 Ecore_Con_Info *infos);
104 static const char * _ecore_con_pretty_ip(struct sockaddr *client_addr);
108 _ecore_con_client_kill(Ecore_Con_Client *cl)
111 DBG("Multi kill request for client %p", cl);
114 ecore_con_event_client_del(cl);
117 INF("Lost client %s", (cl->ip) ? cl->ip : "");
120 ecore_main_fd_handler_del(cl->fd_handler);
121 cl->fd_handler = NULL;
124 _ecore_con_client_free(cl);
128 _ecore_con_server_kill(Ecore_Con_Server *svr)
131 DBG("Multi kill request for svr %p", svr);
133 ecore_con_event_server_del(svr);
137 ecore_main_fd_handler_del(svr->fd_handler);
138 svr->fd_handler = NULL;
142 #define _ecore_con_server_kill(svr) do { \
143 DBG("KILL %p", (svr)); \
144 _ecore_con_server_kill((svr)); \
147 #define _ecore_con_client_kill(cl) do { \
148 DBG("KILL %p", (cl)); \
149 _ecore_con_client_kill((cl)); \
152 EAPI int ECORE_CON_EVENT_CLIENT_ADD = 0;
153 EAPI int ECORE_CON_EVENT_CLIENT_DEL = 0;
154 EAPI int ECORE_CON_EVENT_SERVER_ADD = 0;
155 EAPI int ECORE_CON_EVENT_SERVER_DEL = 0;
156 EAPI int ECORE_CON_EVENT_CLIENT_DATA = 0;
157 EAPI int ECORE_CON_EVENT_SERVER_DATA = 0;
158 EAPI int ECORE_CON_EVENT_CLIENT_WRITE = 0;
159 EAPI int ECORE_CON_EVENT_SERVER_WRITE = 0;
160 EAPI int ECORE_CON_EVENT_CLIENT_ERROR = 0;
161 EAPI int ECORE_CON_EVENT_SERVER_ERROR = 0;
162 EAPI int ECORE_CON_EVENT_PROXY_BIND = 0;
164 static Eina_List *servers = NULL;
165 static int _ecore_con_init_count = 0;
166 static int _ecore_con_event_count = 0;
167 int _ecore_con_log_dom = -1;
168 Ecore_Con_Socks *_ecore_con_proxy_once = NULL;
169 Ecore_Con_Socks *_ecore_con_proxy_global = NULL;
174 if (++_ecore_con_init_count != 1)
175 return _ecore_con_init_count;
179 return --_ecore_con_init_count;
184 return --_ecore_con_init_count;
186 _ecore_con_log_dom = eina_log_domain_register
187 ("ecore_con", ECORE_CON_DEFAULT_LOG_COLOR);
188 if (_ecore_con_log_dom < 0)
190 EINA_LOG_ERR("Impossible to create a log domain for Ecore Con.");
192 return --_ecore_con_init_count;
195 ecore_con_mempool_init();
197 ECORE_CON_EVENT_CLIENT_ADD = ecore_event_type_new();
198 ECORE_CON_EVENT_CLIENT_DEL = ecore_event_type_new();
199 ECORE_CON_EVENT_SERVER_ADD = ecore_event_type_new();
200 ECORE_CON_EVENT_SERVER_DEL = ecore_event_type_new();
201 ECORE_CON_EVENT_CLIENT_DATA = ecore_event_type_new();
202 ECORE_CON_EVENT_SERVER_DATA = ecore_event_type_new();
203 ECORE_CON_EVENT_CLIENT_WRITE = ecore_event_type_new();
204 ECORE_CON_EVENT_SERVER_WRITE = ecore_event_type_new();
205 ECORE_CON_EVENT_CLIENT_ERROR = ecore_event_type_new();
206 ECORE_CON_EVENT_SERVER_ERROR = ecore_event_type_new();
207 ECORE_CON_EVENT_PROXY_BIND = ecore_event_type_new();
210 eina_magic_string_set(ECORE_MAGIC_CON_SERVER, "Ecore_Con_Server");
211 eina_magic_string_set(ECORE_MAGIC_CON_CLIENT, "Ecore_Con_Server");
212 eina_magic_string_set(ECORE_MAGIC_CON_URL, "Ecore_Con_Url");
214 /* TODO Remember return value, if it fails, use gethostbyname() */
215 ecore_con_socks_init();
216 ecore_con_ssl_init();
217 ecore_con_info_init();
219 return _ecore_con_init_count;
223 ecore_con_shutdown(void)
226 Ecore_Con_Server *svr;
228 if (--_ecore_con_init_count != 0)
229 return _ecore_con_init_count;
231 EINA_LIST_FOREACH_SAFE(servers, l, l2, svr)
233 Ecore_Con_Event_Server_Add *ev;
235 svr->delete_me = EINA_TRUE;
236 INF("svr %p is dead", svr);
237 /* some pointer hacks here to prevent double frees if people are being stupid */
238 EINA_LIST_FREE(svr->event_count, ev)
240 _ecore_con_server_free(svr);
243 ecore_con_socks_shutdown();
244 if (!_ecore_con_event_count) ecore_con_mempool_shutdown();
246 ecore_con_info_shutdown();
247 ecore_con_ssl_shutdown();
248 eina_log_domain_unregister(_ecore_con_log_dom);
249 _ecore_con_log_dom = -1;
255 return _ecore_con_init_count;
259 ecore_con_lookup(const char *name,
260 Ecore_Con_Dns_Cb done_cb,
263 Ecore_Con_Server *svr;
264 Ecore_Con_Lookup *lk;
265 struct addrinfo hints;
267 if (!name || !done_cb)
270 svr = calloc(1, sizeof(Ecore_Con_Server));
274 lk = malloc(sizeof (Ecore_Con_Lookup));
281 lk->done_cb = done_cb;
284 svr->name = strdup(name);
288 svr->type = ECORE_CON_REMOTE_TCP;
291 svr->created = EINA_TRUE;
292 svr->reject_excess_clients = EINA_FALSE;
293 svr->client_limit = -1;
295 svr->ppid = getpid();
297 memset(&hints, 0, sizeof(struct addrinfo));
298 hints.ai_family = AF_UNSPEC;
299 hints.ai_socktype = SOCK_STREAM;
300 hints.ai_flags = AI_CANONNAME;
301 hints.ai_protocol = IPPROTO_TCP;
302 hints.ai_canonname = NULL;
303 hints.ai_next = NULL;
304 hints.ai_addr = NULL;
306 if (ecore_con_info_get(svr, _ecore_con_lookup_done, svr,
318 * @addtogroup Ecore_Con_Server_Group Ecore Connection Server Functions
320 * Functions that operate on Ecore server objects.
326 * @example ecore_con_server_example.c
327 * Shows how to write a simple server using the Ecore_Con library.
330 EAPI Ecore_Con_Server *
331 ecore_con_server_add(Ecore_Con_Type compl_type,
336 Ecore_Con_Server *svr;
339 if (port < 0 || !name)
340 return NULL; /* local user socket: FILE: ~/.ecore/[name]/[port] */
342 /* local system socket: FILE: /tmp/.ecore_service|[name]|[port] */
343 /* remote system socket: TCP/IP: [name]:[port] */
344 svr = calloc(1, sizeof(Ecore_Con_Server));
348 svr->name = strdup(name);
352 svr->type = compl_type;
354 svr->data = (void *)data;
355 svr->created = EINA_TRUE;
356 svr->use_cert = (compl_type & ECORE_CON_SSL & ECORE_CON_LOAD_CERT) == ECORE_CON_LOAD_CERT;
357 svr->reject_excess_clients = EINA_FALSE;
358 svr->client_limit = -1;
360 svr->ppid = getpid();
361 if (ecore_con_ssl_server_prepare(svr, compl_type & ECORE_CON_SSL))
364 type = compl_type & ECORE_CON_TYPE;
366 if ((type == ECORE_CON_LOCAL_USER) ||
367 (type == ECORE_CON_LOCAL_SYSTEM) ||
368 (type == ECORE_CON_LOCAL_ABSTRACT))
371 if (!ecore_con_local_listen(svr))
374 if (!ecore_con_local_listen(svr, _ecore_con_svr_tcp_handler, svr))
378 if ((type == ECORE_CON_REMOTE_TCP) ||
379 (type == ECORE_CON_REMOTE_NODELAY) ||
380 (type == ECORE_CON_REMOTE_CORK))
383 if (!ecore_con_info_tcp_listen(svr, _ecore_con_cb_tcp_listen,
387 else if ((type == ECORE_CON_REMOTE_MCAST) ||
388 (type == ECORE_CON_REMOTE_UDP))
390 if (!ecore_con_info_udp_listen(svr, _ecore_con_cb_udp_listen,
394 servers = eina_list_append(servers, svr);
395 ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER);
408 ecore_main_fd_handler_del(svr->fd_handler);
414 eina_binbuf_free(svr->buf);
417 eina_stringshare_del(svr->ip);
419 ecore_con_ssl_server_shutdown(svr);
424 EAPI Ecore_Con_Server *
425 ecore_con_server_connect(Ecore_Con_Type compl_type,
430 Ecore_Con_Server *svr;
433 if ((!name) || (!name[0]))
435 /* local user socket: FILE: ~/.ecore/[name]/[port] */
436 /* local system socket: FILE: /tmp/.ecore_service|[name]|[port] */
437 /* remote system socket: TCP/IP: [name]:[port] */
438 svr = calloc(1, sizeof(Ecore_Con_Server));
442 svr->name = strdup(name);
446 svr->type = compl_type;
448 svr->data = (void *)data;
449 svr->created = EINA_FALSE;
450 svr->use_cert = (compl_type & ECORE_CON_SSL & ECORE_CON_LOAD_CERT) == ECORE_CON_LOAD_CERT;
451 svr->reject_excess_clients = EINA_FALSE;
453 svr->client_limit = -1;
455 type = compl_type & ECORE_CON_TYPE;
457 if (type > ECORE_CON_LOCAL_ABSTRACT)
459 /* never use proxies on local connections */
460 if (_ecore_con_proxy_once)
461 svr->ecs = _ecore_con_proxy_once;
462 else if (_ecore_con_proxy_global)
463 svr->ecs = _ecore_con_proxy_global;
464 _ecore_con_proxy_once = NULL;
467 if ((!svr->ecs->lookup) &&
468 (!ecore_con_lookup(svr->name, (Ecore_Con_Dns_Cb)ecore_con_socks_dns_cb, svr)))
470 if (svr->ecs->lookup)
471 svr->ecs_state = ECORE_CON_PROXY_STATE_RESOLVED;
474 if (ecore_con_ssl_server_prepare(svr, compl_type & ECORE_CON_SSL))
477 if (((type == ECORE_CON_REMOTE_TCP) ||
478 (type == ECORE_CON_REMOTE_NODELAY) ||
479 (type == ECORE_CON_REMOTE_CORK) ||
480 (type == ECORE_CON_REMOTE_UDP) ||
481 (type == ECORE_CON_REMOTE_BROADCAST)) &&
485 if ((type == ECORE_CON_LOCAL_USER) ||
486 (type == ECORE_CON_LOCAL_SYSTEM) ||
487 (type == ECORE_CON_LOCAL_ABSTRACT))
490 if (!ecore_con_local_connect(svr, _ecore_con_cl_handler))
493 if (!ecore_con_local_connect(svr, _ecore_con_cl_handler, svr))
497 if ((type == ECORE_CON_REMOTE_TCP) ||
498 (type == ECORE_CON_REMOTE_NODELAY) ||
499 (type == ECORE_CON_REMOTE_CORK))
502 if (!ecore_con_info_tcp_connect(svr, _ecore_con_cb_tcp_connect,
506 else if ((type == ECORE_CON_REMOTE_UDP) ||
507 (type == ECORE_CON_REMOTE_BROADCAST))
509 if (!ecore_con_info_udp_connect(svr, _ecore_con_cb_udp_connect,
513 servers = eina_list_append(servers, svr);
514 ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER);
526 ecore_main_fd_handler_del(svr->fd_handler);
531 ecore_con_ssl_server_shutdown(svr);
537 ecore_con_server_timeout_set(Ecore_Con_Server *svr,
540 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
542 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_timeout_set");
547 svr->client_disconnect_time = timeout;
549 svr->disconnect_time = timeout;
553 ecore_con_server_timeout_get(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_get");
561 return svr->created ? svr->client_disconnect_time : svr->disconnect_time;
565 ecore_con_server_del(Ecore_Con_Server *svr)
567 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
569 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_del");
576 _ecore_con_server_kill(svr);
581 ecore_con_server_data_get(Ecore_Con_Server *svr)
583 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
585 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_data_get");
593 ecore_con_server_data_set(Ecore_Con_Server *svr,
598 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
600 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_data_get");
610 ecore_con_server_connected_get(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_connected_get");
624 EAPI const Eina_List *
625 ecore_con_server_clients_get(Ecore_Con_Server *svr)
627 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
629 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
630 "ecore_con_server_clients_get");
638 ecore_con_server_name_get(Ecore_Con_Server *svr)
640 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
642 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
643 "ecore_con_server_name_get");
651 ecore_con_server_port_get(Ecore_Con_Server *svr)
653 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
655 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
656 "ecore_con_server_port_get");
663 ecore_con_server_send(Ecore_Con_Server *svr,
667 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
669 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_send");
673 EINA_SAFETY_ON_TRUE_RETURN_VAL(svr->delete_me, 0);
675 EINA_SAFETY_ON_NULL_RETURN_VAL(data, 0);
677 EINA_SAFETY_ON_TRUE_RETURN_VAL(size < 1, 0);
680 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE);
684 svr->buf = eina_binbuf_new();
685 EINA_SAFETY_ON_NULL_RETURN_VAL(svr->buf, 0);
687 if ((svr->fd >= 0) && ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK))
690 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
691 /* realistically this isn't anything serious so we can just log and continue */
692 ERR("corking failed! %s", strerror(errno));
696 eina_binbuf_append_length(svr->buf, data, size);
702 ecore_con_server_client_limit_set(Ecore_Con_Server *svr,
704 char reject_excess_clients)
706 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
708 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
709 "ecore_con_server_client_limit_set");
713 svr->client_limit = client_limit;
714 svr->reject_excess_clients = reject_excess_clients;
718 ecore_con_server_ip_get(Ecore_Con_Server *svr)
720 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
722 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_ip_get");
730 ecore_con_server_uptime_get(Ecore_Con_Server *svr)
732 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
734 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_uptime_get");
738 return ecore_time_get() - svr->start_time;
742 ecore_con_server_flush(Ecore_Con_Server *svr)
744 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
746 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_flush");
750 _ecore_con_server_flush(svr);
758 * @addtogroup Ecore_Con_Client_Group Ecore Connection Client Functions
760 * Functions that operate on Ecore connection client objects.
766 * @example ecore_con_client_example.c
767 * Shows how to write a simple client that connects to the example server.
771 ecore_con_client_send(Ecore_Con_Client *cl,
775 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
777 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_send");
781 EINA_SAFETY_ON_TRUE_RETURN_VAL(cl->delete_me, 0);
783 EINA_SAFETY_ON_NULL_RETURN_VAL(data, 0);
785 EINA_SAFETY_ON_TRUE_RETURN_VAL(size < 1, 0);
788 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE);
790 if (cl->host_server && ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP))
791 sendto(cl->host_server->fd, data, size, 0, (struct sockaddr *)cl->client_addr,
792 cl->client_addr_len);
795 cl->buf = eina_binbuf_new();
796 EINA_SAFETY_ON_NULL_RETURN_VAL(cl->buf, 0);
798 if ((cl->fd >= 0) && ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK))
801 if (setsockopt(cl->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
802 /* realistically this isn't anything serious so we can just log and continue */
803 ERR("corking failed! %s", strerror(errno));
807 eina_binbuf_append_length(cl->buf, data, size);
812 EAPI Ecore_Con_Server *
813 ecore_con_client_server_get(Ecore_Con_Client *cl)
815 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
817 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
818 "ecore_con_client_server_get");
822 return cl->host_server;
826 ecore_con_client_connected_get(Ecore_Con_Client *cl)
828 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
830 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
831 "ecore_con_client_connected_get");
835 return !cl->delete_me;
839 ecore_con_client_timeout_set(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_timeout_set");
849 cl->disconnect_time = timeout;
851 _ecore_con_cl_timer_update(cl);
855 ecore_con_client_timeout_get(Ecore_Con_Client *cl)
857 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
859 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_timeout_get");
863 return cl->disconnect_time;
867 ecore_con_client_del(Ecore_Con_Client *cl)
869 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
871 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_del");
874 ecore_con_client_unref(cl);
879 ecore_con_client_ref(Ecore_Con_Client *cl)
881 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
883 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_ref");
890 ecore_con_client_unref(Ecore_Con_Client *cl)
892 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
894 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_unref");
899 _ecore_con_client_kill(cl);
903 ecore_con_client_data_set(Ecore_Con_Client *cl,
906 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
908 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_data_set");
912 cl->data = (void *)data;
916 ecore_con_client_data_get(Ecore_Con_Client *cl)
918 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
920 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_data_get");
928 ecore_con_client_ip_get(Ecore_Con_Client *cl)
930 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
932 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_ip_get");
936 cl->ip = _ecore_con_pretty_ip(cl->client_addr);
942 ecore_con_client_port_get(Ecore_Con_Client *cl)
944 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
946 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_port_get");
949 if (cl->client_addr->sa_family == AF_INET)
950 return ((struct sockaddr_in*)cl->client_addr)->sin_port;
952 return ((struct sockaddr_in6*)cl->client_addr)->sin6_port;
959 ecore_con_client_uptime_get(Ecore_Con_Client *cl)
961 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
963 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_uptime_get");
967 return ecore_time_get() - cl->start_time;
971 ecore_con_client_flush(Ecore_Con_Client *cl)
973 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
975 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_flush");
979 _ecore_con_client_flush(cl);
983 ecore_con_server_fd_get(Ecore_Con_Server *svr)
985 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
987 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, __func__);
990 if (svr->created) return -1;
991 return ecore_main_fd_handler_fd_get(svr->fd_handler);
995 ecore_con_client_fd_get(Ecore_Con_Client *cl)
997 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
999 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, __func__);
1002 return ecore_main_fd_handler_fd_get(cl->fd_handler);
1010 ecore_con_event_proxy_bind(Ecore_Con_Server *svr)
1012 Ecore_Con_Event_Proxy_Bind *e;
1013 int ev = ECORE_CON_EVENT_PROXY_BIND;
1015 e = ecore_con_event_proxy_bind_alloc();
1016 EINA_SAFETY_ON_NULL_RETURN(e);
1018 svr->event_count = eina_list_append(svr->event_count, e);
1019 _ecore_con_server_timer_update(svr);
1021 e->ip = svr->proxyip;
1022 e->port = svr->proxyport;
1023 ecore_event_add(ev, e,
1024 _ecore_con_event_server_add_free, NULL);
1025 _ecore_con_event_count++;
1029 ecore_con_event_server_add(Ecore_Con_Server *svr)
1031 /* we got our server! */
1032 Ecore_Con_Event_Server_Add *e;
1033 int ev = ECORE_CON_EVENT_SERVER_ADD;
1035 e = ecore_con_event_server_add_alloc();
1036 EINA_SAFETY_ON_NULL_RETURN(e);
1038 svr->connecting = EINA_FALSE;
1039 svr->start_time = ecore_time_get();
1040 svr->event_count = eina_list_append(svr->event_count, e);
1041 _ecore_con_server_timer_update(svr);
1043 if (svr->upgrade) ev = ECORE_CON_EVENT_SERVER_UPGRADE;
1044 ecore_event_add(ev, e,
1045 _ecore_con_event_server_add_free, NULL);
1046 _ecore_con_event_count++;
1050 ecore_con_event_server_del(Ecore_Con_Server *svr)
1052 Ecore_Con_Event_Server_Del *e;
1054 svr->delete_me = EINA_TRUE;
1055 INF("svr %p is dead", svr);
1056 e = ecore_con_event_server_del_alloc();
1057 EINA_SAFETY_ON_NULL_RETURN(e);
1059 svr->event_count = eina_list_append(svr->event_count, e);
1060 _ecore_con_server_timer_update(svr);
1064 svr->ecs_state = svr->ecs->lookup ? ECORE_CON_PROXY_STATE_RESOLVED : ECORE_CON_PROXY_STATE_DONE;
1065 eina_stringshare_replace(&svr->proxyip, NULL);
1068 ecore_event_add(ECORE_CON_EVENT_SERVER_DEL, e,
1069 _ecore_con_event_server_del_free, NULL);
1070 _ecore_con_event_count++;
1074 ecore_con_event_server_write(Ecore_Con_Server *svr, int num)
1076 Ecore_Con_Event_Server_Write *e;
1078 e = ecore_con_event_server_write_alloc();
1079 EINA_SAFETY_ON_NULL_RETURN(e);
1081 INF("Wrote %d bytes", num);
1082 svr->event_count = eina_list_append(svr->event_count, e);
1085 ecore_event_add(ECORE_CON_EVENT_SERVER_WRITE, e,
1086 (Ecore_End_Cb)_ecore_con_event_server_write_free, NULL);
1087 _ecore_con_event_count++;
1091 ecore_con_event_server_data(Ecore_Con_Server *svr, unsigned char *buf, int num, Eina_Bool duplicate)
1093 Ecore_Con_Event_Server_Data *e;
1095 e = ecore_con_event_server_data_alloc();
1096 EINA_SAFETY_ON_NULL_RETURN(e);
1098 svr->event_count = eina_list_append(svr->event_count, e);
1099 _ecore_con_server_timer_update(svr);
1103 e->data = malloc(num);
1106 ERR("server data allocation failure !");
1107 _ecore_con_event_server_data_free(NULL, e);
1110 memcpy(e->data, buf, num);
1115 ecore_event_add(ECORE_CON_EVENT_SERVER_DATA, e,
1116 _ecore_con_event_server_data_free, NULL);
1117 _ecore_con_event_count++;
1121 ecore_con_event_client_add(Ecore_Con_Client *cl)
1123 Ecore_Con_Event_Client_Add *e;
1124 int ev = ECORE_CON_EVENT_CLIENT_ADD;
1126 e = ecore_con_event_client_add_alloc();
1127 EINA_SAFETY_ON_NULL_RETURN(e);
1129 cl->event_count = eina_list_append(cl->event_count, e);
1130 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1131 _ecore_con_cl_timer_update(cl);
1133 if (cl->upgrade) ev = ECORE_CON_EVENT_CLIENT_UPGRADE;
1134 ecore_event_add(ev, e,
1135 (Ecore_End_Cb)_ecore_con_event_client_add_free, cl->host_server);
1136 _ecore_con_event_count++;
1140 ecore_con_event_client_del(Ecore_Con_Client *cl)
1142 Ecore_Con_Event_Client_Del *e;
1145 cl->delete_me = EINA_TRUE;
1146 INF("cl %p is dead", cl);
1147 e = ecore_con_event_client_del_alloc();
1148 EINA_SAFETY_ON_NULL_RETURN(e);
1149 cl->event_count = eina_list_append(cl->event_count, e);
1151 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1152 _ecore_con_cl_timer_update(cl);
1154 ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
1155 (Ecore_End_Cb)_ecore_con_event_client_del_free, cl->host_server);
1156 _ecore_con_event_count++;
1160 ecore_con_event_client_write(Ecore_Con_Client *cl, int num)
1162 Ecore_Con_Event_Client_Write *e;
1164 e = ecore_con_event_client_write_alloc();
1165 EINA_SAFETY_ON_NULL_RETURN(e);
1167 cl->event_count = eina_list_append(cl->event_count, e);
1168 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1171 ecore_event_add(ECORE_CON_EVENT_CLIENT_WRITE, e,
1172 (Ecore_End_Cb)_ecore_con_event_client_write_free, cl->host_server);
1173 _ecore_con_event_count++;
1177 ecore_con_event_client_data(Ecore_Con_Client *cl, unsigned char *buf, int num, Eina_Bool duplicate)
1179 Ecore_Con_Event_Client_Data *e;
1181 e = ecore_con_event_client_data_alloc();
1182 EINA_SAFETY_ON_NULL_RETURN(e);
1184 cl->event_count = eina_list_append(cl->event_count, e);
1185 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1186 _ecore_con_cl_timer_update(cl);
1190 e->data = malloc(num);
1193 ERR("client data allocation failure !");
1194 _ecore_con_event_client_data_free(cl->host_server, e);
1197 memcpy(e->data, buf, num);
1202 ecore_event_add(ECORE_CON_EVENT_CLIENT_DATA, e,
1203 (Ecore_End_Cb)_ecore_con_event_client_data_free, cl->host_server);
1204 _ecore_con_event_count++;
1209 ecore_con_server_infos_del(Ecore_Con_Server *svr, void *info)
1211 svr->infos = eina_list_remove(svr->infos, info);
1215 _ecore_con_event_server_error(Ecore_Con_Server *svr, char *error, Eina_Bool duplicate)
1217 Ecore_Con_Event_Server_Error *e;
1219 e = ecore_con_event_server_error_alloc();
1220 EINA_SAFETY_ON_NULL_RETURN(e);
1223 e->error = duplicate ? strdup(error) : error;
1225 svr->event_count = eina_list_append(svr->event_count, e);
1226 ecore_event_add(ECORE_CON_EVENT_SERVER_ERROR, e, (Ecore_End_Cb)_ecore_con_event_server_error_free, NULL);
1227 _ecore_con_event_count++;
1231 ecore_con_event_client_error(Ecore_Con_Client *cl, const char *error)
1233 Ecore_Con_Event_Client_Error *e;
1235 e = ecore_con_event_client_error_alloc();
1236 EINA_SAFETY_ON_NULL_RETURN(e);
1239 e->error = strdup(error);
1241 cl->event_count = eina_list_append(cl->event_count, e);
1242 cl->host_server->event_count = eina_list_append(cl->host_server->event_count, e);
1243 ecore_event_add(ECORE_CON_EVENT_CLIENT_ERROR, e, (Ecore_End_Cb)_ecore_con_event_client_error_free, cl->host_server);
1244 _ecore_con_event_count++;
1248 _ecore_con_server_free(Ecore_Con_Server *svr)
1250 Ecore_Con_Client *cl;
1253 if (svr->event_count) return;
1257 ecore_con_info_data_clear(svr->infos->data);
1258 svr->infos = eina_list_remove_list(svr->infos, svr->infos);
1261 t_start = ecore_time_get();
1262 while (svr->buf && (!svr->delete_me))
1264 _ecore_con_server_flush(svr);
1265 t = ecore_time_get();
1266 if ((t - t_start) > 0.5)
1268 WRN("ECORE_CON: EEK - stuck in _ecore_con_server_free() trying\n"
1269 " to flush data out from the server, and have been for\n"
1270 " %1.1f seconds. This is taking too long. Aborting flush.",
1277 ecore_con_local_win32_server_del(svr);
1279 if (svr->event_count) return;
1280 ECORE_MAGIC_SET(svr, ECORE_MAGIC_NONE);
1283 eina_binbuf_free(svr->buf);
1285 EINA_LIST_FREE(svr->clients, cl)
1287 Ecore_Con_Event_Server_Add *ev;
1289 /* some pointer hacks here to prevent double frees if people are being stupid */
1290 EINA_LIST_FREE(cl->event_count, ev)
1292 cl->delete_me = EINA_TRUE;
1293 INF("cl %p is dead", cl);
1294 _ecore_con_client_free(cl);
1296 if ((svr->created) && (svr->path) && (svr->ppid == getpid()))
1299 ecore_con_ssl_server_shutdown(svr);
1304 eina_stringshare_del(svr->ip);
1305 eina_stringshare_del(svr->verify_name);
1307 if (svr->ecs_buf) eina_binbuf_free(svr->ecs_buf);
1308 if (svr->ecs_recvbuf) eina_binbuf_free(svr->ecs_recvbuf);
1310 if (svr->fd_handler)
1311 ecore_main_fd_handler_del(svr->fd_handler);
1316 if (svr->until_deletion)
1317 ecore_timer_del(svr->until_deletion);
1319 servers = eina_list_remove(servers, svr);
1325 _ecore_con_client_free(Ecore_Con_Client *cl)
1329 if (cl->event_count) return;
1331 t_start = ecore_time_get();
1332 while ((cl->buf) && (!cl->delete_me))
1334 _ecore_con_client_flush(cl);
1335 t = ecore_time_get();
1336 if ((t - t_start) > 0.5)
1338 WRN("EEK - stuck in _ecore_con_client_free() trying\n"
1339 " to flush data out from the client, and have been for\n"
1340 " %1.1f seconds. This is taking too long. Aborting flush.",
1345 cl->host_server->clients = eina_list_remove(cl->host_server->clients, cl);
1348 ecore_con_local_win32_client_del(cl);
1351 if (cl->event_count) return;
1352 ECORE_MAGIC_SET(cl, ECORE_MAGIC_NONE);
1354 if (cl->buf) eina_binbuf_free(cl->buf);
1356 if (cl->host_server->type & ECORE_CON_SSL)
1357 ecore_con_ssl_client_shutdown(cl);
1360 ecore_main_fd_handler_del(cl->fd_handler);
1365 free(cl->client_addr);
1366 cl->client_addr = NULL;
1368 if (cl->until_deletion)
1369 ecore_timer_del(cl->until_deletion);
1371 eina_stringshare_del(cl->ip);
1378 _ecore_con_server_timer(Ecore_Con_Server *svr)
1380 ecore_con_server_del(svr);
1382 svr->until_deletion = NULL;
1383 return ECORE_CALLBACK_CANCEL;
1387 _ecore_con_server_timer_update(Ecore_Con_Server *svr)
1389 if (svr->disconnect_time)
1391 if (svr->disconnect_time > 0)
1393 if (svr->until_deletion)
1394 ecore_timer_interval_set(svr->until_deletion, svr->disconnect_time);
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)
1431 ecore_timer_interval_set(cl->until_deletion, cl->disconnect_time);
1433 cl->until_deletion = ecore_timer_add(cl->disconnect_time, (Ecore_Task_Cb)_ecore_con_client_timer, cl);
1435 else if (cl->until_deletion)
1437 ecore_timer_del(cl->until_deletion);
1438 cl->until_deletion = NULL;
1443 if (cl->host_server->client_disconnect_time > 0)
1445 if (cl->until_deletion)
1446 ecore_timer_interval_set(cl->until_deletion, cl->host_server->client_disconnect_time);
1448 cl->until_deletion = ecore_timer_add(cl->host_server->client_disconnect_time, (Ecore_Task_Cb)_ecore_con_client_timer, cl);
1450 else if (cl->until_deletion)
1452 ecore_timer_del(cl->until_deletion);
1453 cl->until_deletion = NULL;
1459 _ecore_con_cb_tcp_listen(void *data,
1460 Ecore_Con_Info *net_info)
1462 Ecore_Con_Server *svr;
1464 const char *memerr = NULL;
1469 if (!net_info) /* error message has already been handled */
1472 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1473 net_info->info.ai_protocol);
1474 if (svr->fd < 0) goto error;
1475 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1476 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1480 if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, (const void *)&lin,
1481 sizeof(struct linger)) < 0)
1484 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY)
1486 #ifdef HAVE_NETINET_TCP_H
1489 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag,
1497 if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
1500 if (listen(svr->fd, 4096) < 0) goto error;
1502 svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
1503 _ecore_con_svr_tcp_handler, svr, NULL, NULL);
1504 if (!svr->fd_handler)
1506 memerr = "Memory allocation failure";
1513 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1514 ecore_con_ssl_server_shutdown(svr);
1515 _ecore_con_server_kill(svr);
1519 _ecore_con_cb_udp_listen(void *data,
1520 Ecore_Con_Info *net_info)
1522 Ecore_Con_Server *svr;
1523 Ecore_Con_Type type;
1524 struct ip_mreq mreq;
1526 struct ipv6_mreq mreq6;
1529 const char *memerr = NULL;
1533 type &= ECORE_CON_TYPE;
1536 if (!net_info) /* error message has already been handled */
1539 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1540 net_info->info.ai_protocol);
1541 if (svr->fd < 0) goto error;
1543 if (type == ECORE_CON_REMOTE_MCAST)
1545 if (net_info->info.ai_family == AF_INET)
1547 if (!inet_pton(net_info->info.ai_family, net_info->ip,
1548 &mreq.imr_multiaddr))
1551 mreq.imr_interface.s_addr = htonl(INADDR_ANY);
1552 if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
1553 (const void *)&mreq, sizeof(mreq)) != 0)
1557 else if (net_info->info.ai_family == AF_INET6)
1559 if (!inet_pton(net_info->info.ai_family, net_info->ip,
1560 &mreq6.ipv6mr_multiaddr))
1562 mreq6.ipv6mr_interface = htonl(INADDR_ANY);
1563 if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
1564 (const void *)&mreq6, sizeof(mreq6)) != 0)
1570 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof(on)) != 0)
1572 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1573 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1575 if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
1579 ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
1580 _ecore_con_svr_udp_handler, svr, NULL, NULL);
1581 if (!svr->fd_handler)
1583 memerr = "Memory allocation failure";
1587 svr->ip = eina_stringshare_add(net_info->ip);
1592 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1593 ecore_con_ssl_server_shutdown(svr);
1594 _ecore_con_server_kill(svr);
1598 _ecore_con_cb_tcp_connect(void *data,
1599 Ecore_Con_Info *net_info)
1601 Ecore_Con_Server *svr;
1604 const char *memerr = NULL;
1609 if (!net_info) /* error message has already been handled */
1612 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1613 net_info->info.ai_protocol);
1614 if (svr->fd < 0) goto error;
1616 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1617 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1619 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate, sizeof(curstate)) < 0)
1622 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY)
1624 #ifdef HAVE_NETINET_TCP_H
1627 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)) < 0)
1634 res = connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen);
1636 if (res == SOCKET_ERROR)
1638 if (WSAGetLastError() != WSAEINPROGRESS)
1641 err = evil_format_message(WSAGetLastError());
1642 _ecore_con_event_server_error(svr, err, EINA_FALSE);
1643 ecore_con_ssl_server_shutdown(svr);
1644 _ecore_con_server_kill(svr);
1651 if (errno != EINPROGRESS) goto error;
1653 svr->connecting = EINA_TRUE;
1655 ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE,
1656 _ecore_con_cl_handler, svr, NULL, NULL);
1659 svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
1660 _ecore_con_cl_handler, svr, NULL, NULL);
1662 if (svr->type & ECORE_CON_SSL)
1664 svr->handshaking = EINA_TRUE;
1665 svr->ssl_state = ECORE_CON_SSL_STATE_INIT;
1666 DBG("%s ssl handshake", svr->ecs_state ? "Queuing" : "Beginning");
1667 if ((!svr->ecs_state) && ecore_con_ssl_server_init(svr))
1671 if (!svr->fd_handler)
1673 memerr = "Memory allocation failure";
1677 if ((!svr->ecs) || (svr->ecs->lookup))
1678 svr->ip = eina_stringshare_add(net_info->ip);
1683 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1684 ecore_con_ssl_server_shutdown(svr);
1685 _ecore_con_server_kill(svr);
1689 _ecore_con_cb_udp_connect(void *data,
1690 Ecore_Con_Info *net_info)
1692 Ecore_Con_Server *svr;
1695 const char *memerr = NULL;
1699 if (!net_info) /* error message has already been handled */
1702 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
1703 net_info->info.ai_protocol);
1704 if (svr->fd < 0) goto error;
1705 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1706 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1707 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_BROADCAST)
1709 if (setsockopt(svr->fd, SOL_SOCKET, SO_BROADCAST,
1710 (const void *)&broadcast,
1711 sizeof(broadcast)) < 0)
1716 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR,
1717 (const void *)&curstate, sizeof(curstate)) < 0)
1720 if (connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
1723 svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE,
1724 _ecore_con_cl_udp_handler, svr, NULL, NULL);
1726 if (!svr->fd_handler)
1728 memerr = "Memory allocation failure";
1732 if ((!svr->ecs) || (svr->ecs->lookup))
1733 svr->ip = eina_stringshare_add(net_info->ip);
1738 if (errno || memerr) ecore_con_event_server_error(svr, memerr ?: strerror(errno));
1739 ecore_con_ssl_server_shutdown(svr);
1740 _ecore_con_server_kill(svr);
1743 static Ecore_Con_State
1744 svr_try_connect_plain(Ecore_Con_Server *svr)
1748 socklen_t size = sizeof(int);
1750 res = getsockopt(svr->fd, SOL_SOCKET, SO_ERROR, (void *)&so_err, &size);
1752 if (res == SOCKET_ERROR)
1753 so_err = WSAGetLastError();
1755 if ((so_err == WSAEINPROGRESS) && !svr->delete_me)
1756 return ECORE_CON_INPROGRESS;
1762 if ((so_err == EINPROGRESS) && !svr->delete_me)
1763 return ECORE_CON_INPROGRESS;
1769 /* we lost our server! */
1770 ecore_con_event_server_error(svr, strerror(so_err));
1771 ERR("Connection lost: %s", strerror(so_err));
1772 _ecore_con_server_kill(svr);
1773 return ECORE_CON_DISCONNECTED;
1776 if ((!svr->delete_me) && (!svr->handshaking) && svr->connecting)
1780 if (ecore_con_socks_svr_init(svr))
1781 return ECORE_CON_INPROGRESS;
1784 ecore_con_event_server_add(svr);
1787 if (svr->fd_handler && (!svr->buf))
1788 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
1790 if (!svr->delete_me)
1791 return ECORE_CON_CONNECTED;
1793 return ECORE_CON_DISCONNECTED;
1797 _ecore_con_pretty_ip(struct sockaddr *client_addr)
1800 char ipbuf[INET_ADDRSTRLEN + 1];
1802 char ipbuf[INET6_ADDRSTRLEN + 1];
1804 int family = client_addr->sa_family;
1810 src = &(((struct sockaddr_in *)client_addr)->sin_addr);
1814 src = &(((struct sockaddr_in6 *)client_addr)->sin6_addr);
1816 if (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)src))
1819 src = (char*)src + 12;
1824 return eina_stringshare_add("0.0.0.0");
1827 if (!inet_ntop(family, src, ipbuf, sizeof(ipbuf)))
1828 return eina_stringshare_add("0.0.0.0");
1830 ipbuf[sizeof(ipbuf) - 1] = 0;
1831 return eina_stringshare_add(ipbuf);
1835 _ecore_con_svr_tcp_handler(void *data,
1836 Ecore_Fd_Handler *fd_handler __UNUSED__)
1838 Ecore_Con_Server *svr;
1839 Ecore_Con_Client *cl = NULL;
1840 unsigned char client_addr[256];
1841 unsigned int client_addr_len;
1842 const char *clerr = NULL;
1846 return ECORE_CALLBACK_RENEW;
1849 return ECORE_CALLBACK_RENEW;
1851 if ((svr->client_limit >= 0) && (!svr->reject_excess_clients) &&
1852 (svr->client_count >= (unsigned int)svr->client_limit))
1853 return ECORE_CALLBACK_RENEW;
1857 cl = calloc(1, sizeof(Ecore_Con_Client));
1860 ecore_con_event_server_error(svr, "Memory allocation failure when attempting to add a new client");
1861 return ECORE_CALLBACK_RENEW;
1863 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);
1913 if (clerr || errno) ecore_con_event_server_error(svr, clerr ?: strerror(errno));
1914 return ECORE_CALLBACK_RENEW;
1918 _ecore_con_cl_read(Ecore_Con_Server *svr)
1921 Eina_Bool lost_server = EINA_TRUE;
1922 unsigned char buf[READBUFSIZ];
1926 /* only possible with non-ssl connections */
1927 if (svr->connecting && (svr_try_connect_plain(svr) != ECORE_CON_CONNECTED))
1930 if (svr->handshaking && (!svr->ecs_state))
1932 DBG("Continuing ssl handshake");
1933 if (!ecore_con_ssl_server_init(svr))
1934 lost_server = EINA_FALSE;
1935 _ecore_con_server_timer_update(svr);
1938 if (svr->ecs_state || !(svr->type & ECORE_CON_SSL))
1941 num = read(svr->fd, buf, sizeof(buf));
1942 /* 0 is not a valid return value for a tcp socket */
1943 if ((num > 0) || ((num < 0) && (errno == EAGAIN)))
1944 lost_server = EINA_FALSE;
1946 ecore_con_event_server_error(svr, strerror(errno));
1950 num = ecore_con_ssl_server_read(svr, buf, sizeof(buf));
1951 /* this is not an actual 0 return, 0 here just means non-fatal error such as EAGAIN */
1953 lost_server = EINA_FALSE;
1956 if ((!svr->delete_me) && (num > 0))
1959 ecore_con_socks_read(svr, buf, num);
1961 ecore_con_event_server_data(svr, buf, num, EINA_TRUE);
1965 _ecore_con_server_kill(svr);
1969 _ecore_con_cl_handler(void *data,
1970 Ecore_Fd_Handler *fd_handler)
1972 Ecore_Con_Server *svr;
1973 Eina_Bool want_read, want_write;
1977 return ECORE_CALLBACK_RENEW;
1980 return ECORE_CALLBACK_RENEW;
1982 want_read = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ);
1983 want_write = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE);
1985 if ((!svr->ecs_state) && svr->handshaking && (want_read || want_write))
1987 DBG("Continuing ssl handshake: preparing to %s...", want_read ? "read" : "write");
1991 char buf[READBUFSIZ];
1993 len = recv(svr->fd, buf, sizeof(buf), MSG_DONTWAIT | MSG_PEEK);
1994 DBG("%zu bytes in buffer", len);
1997 if (ecore_con_ssl_server_init(svr))
1999 ERR("ssl handshaking failed!");
2000 svr->handshaking = EINA_FALSE;
2002 else if (!svr->ssl_state)
2003 ecore_con_event_server_add(svr);
2004 return ECORE_CALLBACK_RENEW;
2006 if (svr->ecs && svr->ecs_state && (svr->ecs_state < ECORE_CON_PROXY_STATE_READ) && (!svr->ecs_buf))
2008 if (svr->ecs_state < ECORE_CON_PROXY_STATE_INIT)
2010 INF("PROXY STATE++");
2013 if (ecore_con_socks_svr_init(svr)) return ECORE_CALLBACK_RENEW;
2016 _ecore_con_cl_read(svr);
2017 else if (want_write) /* only possible with non-ssl connections */
2019 if (svr->connecting && (!svr_try_connect_plain(svr)) && (!svr->ecs_state))
2020 return ECORE_CALLBACK_RENEW;
2022 _ecore_con_server_flush(svr);
2025 return ECORE_CALLBACK_RENEW;
2029 _ecore_con_cl_udp_handler(void *data,
2030 Ecore_Fd_Handler *fd_handler)
2032 unsigned char buf[READBUFSIZ];
2034 Ecore_Con_Server *svr;
2035 Eina_Bool want_read, want_write;
2037 want_read = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ);
2038 want_write = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE);
2041 if (svr->delete_me || svr->delete_me || ((!want_read) && (!want_write)))
2042 return ECORE_CALLBACK_RENEW;
2046 _ecore_con_server_flush(svr);
2047 return ECORE_CALLBACK_RENEW;
2050 num = read(svr->fd, buf, READBUFSIZ);
2052 if ((!svr->delete_me) && (num > 0))
2053 ecore_con_event_server_data(svr, buf, num, EINA_TRUE);
2055 if (num < 0 && (errno != EAGAIN) && (errno != EINTR))
2057 ecore_con_event_server_error(svr, strerror(errno));
2058 _ecore_con_server_kill(svr);
2061 return ECORE_CALLBACK_RENEW;
2065 _ecore_con_svr_udp_handler(void *data,
2066 Ecore_Fd_Handler *fd_handler)
2068 unsigned char buf[READBUFSIZ];
2069 unsigned char client_addr[256];
2070 socklen_t client_addr_len = sizeof(client_addr);
2072 Ecore_Con_Server *svr;
2073 Ecore_Con_Client *cl = NULL;
2078 return ECORE_CALLBACK_RENEW;
2080 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
2082 _ecore_con_client_flush(cl);
2083 return ECORE_CALLBACK_RENEW;
2086 if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
2087 return ECORE_CALLBACK_RENEW;
2090 num = fcntl(svr->fd, F_SETFL, O_NONBLOCK);
2092 num = recvfrom(svr->fd, (char *)buf, sizeof(buf), 0,
2093 (struct sockaddr *)&client_addr,
2097 num = recvfrom(svr->fd, buf, sizeof(buf), MSG_DONTWAIT,
2098 (struct sockaddr *)&client_addr,
2102 if (num < 0 && (errno != EAGAIN) && (errno != EINTR))
2104 ecore_con_event_server_error(svr, strerror(errno));
2105 if (!svr->delete_me)
2106 ecore_con_event_client_del(NULL);
2107 _ecore_con_server_kill(svr);
2108 return ECORE_CALLBACK_CANCEL;
2112 /* Create a new client for use in the client data event */
2113 cl = calloc(1, sizeof(Ecore_Con_Client));
2114 EINA_SAFETY_ON_NULL_RETURN_VAL(cl, ECORE_CALLBACK_RENEW);
2116 cl->host_server = svr;
2117 cl->client_addr = malloc(client_addr_len);
2118 if (!cl->client_addr)
2121 return ECORE_CALLBACK_RENEW;
2123 cl->client_addr_len = client_addr_len;
2125 memcpy(cl->client_addr, &client_addr, client_addr_len);
2126 ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
2127 svr->clients = eina_list_append(svr->clients, cl);
2128 svr->client_count++;
2130 ecore_con_event_client_add(cl);
2131 ecore_con_event_client_data(cl, buf, num, EINA_TRUE);
2133 return ECORE_CALLBACK_RENEW;
2137 _ecore_con_svr_cl_read(Ecore_Con_Client *cl)
2140 Eina_Bool lost_client = EINA_TRUE;
2141 unsigned char buf[READBUFSIZ];
2145 if (cl->handshaking)
2147 /* add an extra handshake attempt just before read, even though
2148 * read also attempts to handshake, to try to finish sooner
2150 if (ecore_con_ssl_client_init(cl))
2151 lost_client = EINA_FALSE;
2153 _ecore_con_cl_timer_update(cl);
2156 if (!(cl->host_server->type & ECORE_CON_SSL) || (!cl->upgrade))
2158 num = read(cl->fd, buf, sizeof(buf));
2159 /* 0 is not a valid return value for a tcp socket */
2160 if ((num > 0) || ((num < 0) && ((errno == EAGAIN) || (errno == EINTR))))
2161 lost_client = EINA_FALSE;
2163 ecore_con_event_client_error(cl, strerror(errno));
2167 num = ecore_con_ssl_client_read(cl, buf, sizeof(buf));
2168 /* this is not an actual 0 return, 0 here just means non-fatal error such as EAGAIN */
2170 lost_client = EINA_FALSE;
2173 if ((!cl->delete_me) && (num > 0))
2174 ecore_con_event_client_data(cl, buf, num, EINA_TRUE);
2176 if (lost_client) _ecore_con_client_kill(cl);
2180 _ecore_con_svr_cl_handler(void *data,
2181 Ecore_Fd_Handler *fd_handler)
2183 Ecore_Con_Client *cl;
2187 return ECORE_CALLBACK_RENEW;
2189 if (cl->handshaking && ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ | ECORE_FD_WRITE))
2191 if (ecore_con_ssl_client_init(cl))
2193 ERR("ssl handshaking failed!");
2194 _ecore_con_client_kill(cl);
2195 return ECORE_CALLBACK_RENEW;
2197 else if (!cl->ssl_state)
2198 ecore_con_event_client_add(cl);
2200 else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
2201 _ecore_con_svr_cl_read(cl);
2203 else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
2204 _ecore_con_client_flush(cl);
2206 return ECORE_CALLBACK_RENEW;
2210 _ecore_con_server_flush(Ecore_Con_Server *svr)
2213 size_t buf_len, buf_offset;
2216 DBG("(svr=%p,buf=%p)", svr, svr->buf);
2218 if (ecore_con_local_win32_server_flush(svr))
2222 if ((!svr->buf) && (!svr->ecs_buf) && svr->fd_handler)
2224 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
2228 buf = svr->buf ? eina_binbuf_string_get(svr->buf) : eina_binbuf_string_get(svr->ecs_buf);
2229 buf_len = svr->buf ? eina_binbuf_length_get(svr->buf) : eina_binbuf_length_get(svr->ecs_buf);
2230 buf_offset = svr->buf ? svr->write_buf_offset : svr->ecs_buf_offset;
2231 num = buf_len - buf_offset;
2233 /* check whether we need to write anything at all.
2234 * we must not write zero bytes with SSL_write() since it
2235 * causes undefined behaviour
2237 /* we thank Tommy[D] for needing to check negative buffer sizes
2238 * here because his system is amazing.
2240 if (num <= 0) return;
2242 if ((!svr->ecs_state) && svr->handshaking)
2244 DBG("Continuing ssl handshake");
2245 if (ecore_con_ssl_server_init(svr))
2246 _ecore_con_server_kill(svr);
2247 _ecore_con_server_timer_update(svr);
2251 if (svr->ecs_state || (!(svr->type & ECORE_CON_SSL)))
2252 count = write(svr->fd, buf + buf_offset, num);
2254 count = ecore_con_ssl_server_write(svr, buf + buf_offset, num);
2258 if ((errno != EAGAIN) && (errno != EINTR))
2260 ecore_con_event_server_error(svr, strerror(errno));
2261 _ecore_con_server_kill(svr);
2266 if (count && (!svr->ecs_state)) ecore_con_event_server_write(svr, count);
2268 buf_offset = svr->ecs_buf_offset += count;
2270 buf_offset = svr->write_buf_offset += count;
2271 if (buf_offset >= buf_len)
2275 svr->ecs_buf_offset = 0;
2276 eina_binbuf_free(svr->ecs_buf);
2277 svr->ecs_buf = NULL;
2278 INF("PROXY STATE++");
2283 svr->write_buf_offset = 0;
2284 eina_binbuf_free(svr->buf);
2287 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK)
2290 if (setsockopt(svr->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
2291 /* realistically this isn't anything serious so we can just log and continue */
2292 ERR("uncorking failed! %s", strerror(errno));
2296 if (svr->fd_handler)
2297 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
2299 else if ((count < num) && svr->fd_handler)
2300 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE);
2304 _ecore_con_client_flush(Ecore_Con_Client *cl)
2306 int num = 0, count = 0;
2309 if (ecore_con_local_win32_client_flush(cl))
2313 if (!cl->buf && cl->fd_handler)
2315 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ);
2319 if (cl->handshaking)
2321 if (ecore_con_ssl_client_init(cl))
2324 _ecore_con_cl_timer_update(cl);
2329 num = eina_binbuf_length_get(cl->buf) - cl->buf_offset;
2330 if (num <= 0) return;
2331 if (!(cl->host_server->type & ECORE_CON_SSL) || (!cl->upgrade))
2332 count = write(cl->fd, eina_binbuf_string_get(cl->buf) + cl->buf_offset, num);
2334 count = ecore_con_ssl_client_write(cl, eina_binbuf_string_get(cl->buf) + cl->buf_offset, num);
2339 if ((errno != EAGAIN) && (errno != EINTR) && (!cl->delete_me))
2341 ecore_con_event_client_error(cl, strerror(errno));
2342 _ecore_con_client_kill(cl);
2348 if (count) ecore_con_event_client_write(cl, count);
2349 cl->buf_offset += count, num -= count;
2350 if (cl->buf_offset >= eina_binbuf_length_get(cl->buf))
2353 eina_binbuf_free(cl->buf);
2356 if ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK)
2359 if (setsockopt(cl->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
2360 /* realistically this isn't anything serious so we can just log and continue */
2361 ERR("uncorking failed! %s", strerror(errno));
2365 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ);
2367 else if (cl->fd_handler && (num >= 0))
2368 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_WRITE);
2372 _ecore_con_event_client_add_free(Ecore_Con_Server *svr,
2375 Ecore_Con_Event_Client_Add *e;
2380 e->client->event_count = eina_list_remove(e->client->event_count, e);
2381 if (e->client->host_server)
2383 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, ev);
2384 if ((!svr->event_count) && (svr->delete_me))
2385 _ecore_con_server_free(svr);
2387 if ((!e->client->event_count) && (e->client->delete_me))
2388 ecore_con_client_del(e->client);
2391 ecore_con_event_client_add_free(e);
2392 _ecore_con_event_count--;
2393 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2394 ecore_con_mempool_shutdown();
2398 _ecore_con_event_client_del_free(Ecore_Con_Server *svr,
2401 Ecore_Con_Event_Client_Del *e;
2406 e->client->event_count = eina_list_remove(e->client->event_count, e);
2407 if (e->client->host_server)
2409 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, ev);
2410 if ((!svr->event_count) && (svr->delete_me))
2411 _ecore_con_server_free(svr);
2413 if (!e->client->event_count)
2414 ecore_con_client_del(e->client);
2416 ecore_con_event_client_del_free(e);
2417 _ecore_con_event_count--;
2418 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2419 ecore_con_mempool_shutdown();
2423 _ecore_con_event_client_write_free(Ecore_Con_Server *svr,
2424 Ecore_Con_Event_Client_Write *e)
2428 e->client->event_count = eina_list_remove(e->client->event_count, e);
2429 if (e->client->host_server)
2431 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, e);
2432 if ((!svr->event_count) && (svr->delete_me))
2433 _ecore_con_server_free(svr);
2435 if (((!e->client->event_count) && (e->client->delete_me)) ||
2436 ((e->client->host_server &&
2437 ((e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP ||
2438 (e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_MCAST))))
2439 ecore_con_client_del(e->client);
2441 ecore_con_event_client_write_free(e);
2442 _ecore_con_event_count--;
2443 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2444 ecore_con_mempool_shutdown();
2448 _ecore_con_event_client_data_free(Ecore_Con_Server *svr,
2451 Ecore_Con_Event_Client_Data *e;
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, ev);
2461 if ((!svr->event_count) && (svr->delete_me))
2462 _ecore_con_server_free(svr);
2463 if (((!e->client->event_count) && (e->client->delete_me)) ||
2464 ((e->client->host_server &&
2465 ((e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP ||
2466 (e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_MCAST))))
2467 ecore_con_client_del(e->client);
2470 ecore_con_event_client_data_free(e);
2471 _ecore_con_event_count--;
2472 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2473 ecore_con_mempool_shutdown();
2477 _ecore_con_event_server_add_free(void *data __UNUSED__,
2480 Ecore_Con_Event_Server_Add *e;
2485 e->server->event_count = eina_list_remove(e->server->event_count, ev);
2486 if ((!e->server->event_count) && (e->server->delete_me))
2487 _ecore_con_server_free(e->server);
2489 ecore_con_event_server_add_free(e);
2490 _ecore_con_event_count--;
2491 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2492 ecore_con_mempool_shutdown();
2496 _ecore_con_event_server_del_free(void *data __UNUSED__,
2499 Ecore_Con_Event_Server_Del *e;
2504 e->server->event_count = eina_list_remove(e->server->event_count, ev);
2505 if (!e->server->event_count)
2506 _ecore_con_server_free(e->server);
2508 ecore_con_event_server_del_free(e);
2509 _ecore_con_event_count--;
2510 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2511 ecore_con_mempool_shutdown();
2515 _ecore_con_event_server_write_free(void *data __UNUSED__,
2516 Ecore_Con_Event_Server_Write *e)
2520 e->server->event_count = eina_list_remove(e->server->event_count, e);
2521 if ((!e->server->event_count) && (e->server->delete_me))
2522 _ecore_con_server_free(e->server);
2525 ecore_con_event_server_write_free(e);
2526 _ecore_con_event_count--;
2527 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2528 ecore_con_mempool_shutdown();
2532 _ecore_con_event_server_data_free(void *data __UNUSED__,
2535 Ecore_Con_Event_Server_Data *e;
2540 e->server->event_count = eina_list_remove(e->server->event_count, ev);
2541 if ((!e->server->event_count) && (e->server->delete_me))
2542 _ecore_con_server_free(e->server);
2546 ecore_con_event_server_data_free(e);
2547 _ecore_con_event_count--;
2548 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2549 ecore_con_mempool_shutdown();
2554 _ecore_con_event_server_error_free(void *data __UNUSED__, Ecore_Con_Event_Server_Error *e)
2558 e->server->event_count = eina_list_remove(e->server->event_count, e);
2559 if ((!e->server->event_count) && (e->server->delete_me))
2560 _ecore_con_server_free(e->server);
2563 ecore_con_event_server_error_free(e);
2564 _ecore_con_event_count--;
2565 if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
2566 ecore_con_mempool_shutdown();
2570 _ecore_con_event_client_error_free(Ecore_Con_Server *svr, Ecore_Con_Event_Client_Error *e)
2574 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, e);
2575 if ((!e->client->event_count) && (e->client->delete_me))
2576 _ecore_con_client_free(e->client);
2577 if (e->client->host_server)
2579 e->client->host_server->event_count = eina_list_remove(e->client->host_server->event_count, e);
2580 if ((!svr->event_count) && (svr->delete_me))
2581 _ecore_con_server_free(svr);
2585 ecore_con_event_client_error_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_lookup_done(void *data,
2593 Ecore_Con_Info *infos)
2595 Ecore_Con_Server *svr;
2596 Ecore_Con_Lookup *lk;
2602 lk->done_cb(infos->info.ai_canonname, infos->ip,
2603 infos->info.ai_addr, infos->info.ai_addrlen,
2606 lk->done_cb(NULL, NULL, NULL, 0, (void *)lk->data);