2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
7 #include <sys/socket.h>
14 #include "ecore_private.h"
15 #include "Ecore_Con.h"
16 #include "ecore_con_private.h"
18 #ifdef HAVE_NETINET_IN_H
19 # include <netinet/in.h>
21 #ifdef HAVE_WINSOCK2_H
22 # include <winsock2.h>
25 static void _ecore_con_cb_tcp_connect(void *data, Ecore_Con_Info *info);
26 static void _ecore_con_cb_udp_connect(void *data, Ecore_Con_Info *info);
27 static void _ecore_con_cb_tcp_listen(void *data, Ecore_Con_Info *info);
28 static void _ecore_con_cb_udp_listen(void *data, Ecore_Con_Info *info);
30 static void _ecore_con_server_free(Ecore_Con_Server *svr);
31 static void _ecore_con_client_free(Ecore_Con_Client *cl);
33 static int _ecore_con_svr_handler(void *data, Ecore_Fd_Handler *fd_handler);
34 static int _ecore_con_cl_handler(void *data, Ecore_Fd_Handler *fd_handler);
35 static int _ecore_con_cl_udp_handler(void *data, Ecore_Fd_Handler *fd_handler);
36 static int _ecore_con_svr_udp_handler(void *data, Ecore_Fd_Handler *fd_handler);
37 static int _ecore_con_svr_cl_handler(void *data, Ecore_Fd_Handler *fd_handler);
39 static void _ecore_con_server_flush(Ecore_Con_Server *svr);
40 static void _ecore_con_client_flush(Ecore_Con_Client *cl);
42 static void _ecore_con_event_client_add_free(void *data, void *ev);
43 static void _ecore_con_event_client_del_free(void *data, void *ev);
44 static void _ecore_con_event_client_data_free(void *data, void *ev);
45 static void _ecore_con_event_server_add_free(void *data, void *ev);
46 static void _ecore_con_event_server_del_free(void *data, void *ev);
47 static void _ecore_con_event_server_data_free(void *data, void *ev);
49 EAPI int ECORE_CON_EVENT_CLIENT_ADD = 0;
50 EAPI int ECORE_CON_EVENT_CLIENT_DEL = 0;
51 EAPI int ECORE_CON_EVENT_SERVER_ADD = 0;
52 EAPI int ECORE_CON_EVENT_SERVER_DEL = 0;
53 EAPI int ECORE_CON_EVENT_CLIENT_DATA = 0;
54 EAPI int ECORE_CON_EVENT_SERVER_DATA = 0;
56 static Ecore_List *servers = NULL;
57 static int init_count = 0;
59 #define LENGTH_OF_SOCKADDR_UN(s) (strlen((s)->sun_path) + (size_t)(((struct sockaddr_un *)NULL)->sun_path))
60 #define LENGTH_OF_ABSTRACT_SOCKADDR_UN(s, path) (strlen(path) + 1 + (size_t)(((struct sockaddr_un *)NULL)->sun_path))
63 * @defgroup Ecore_Con_Lib_Group Ecore Connection Library Functions
65 * Utility functions that set up and shut down the Ecore Connection
70 * Initialises the Ecore_Con library.
71 * @return Number of times the library has been initialised without being
73 * @ingroup Ecore_Con_Lib_Group
78 if (++init_count != 1) return init_count;
81 ECORE_CON_EVENT_CLIENT_ADD = ecore_event_type_new();
82 ECORE_CON_EVENT_CLIENT_DEL = ecore_event_type_new();
83 ECORE_CON_EVENT_SERVER_ADD = ecore_event_type_new();
84 ECORE_CON_EVENT_SERVER_DEL = ecore_event_type_new();
85 ECORE_CON_EVENT_CLIENT_DATA = ecore_event_type_new();
86 ECORE_CON_EVENT_SERVER_DATA = ecore_event_type_new();
88 /* TODO Remember return value, if it fails, use gethostbyname() */
91 ecore_con_info_init();
93 servers = ecore_list_new();
99 * Shuts down the Ecore_Con library.
100 * @return Number of times the library has been initialised without being
102 * @ingroup Ecore_Con_Lib_Group
105 ecore_con_shutdown(void)
107 if (--init_count != 0) return init_count;
109 while (!ecore_list_empty_is(servers))
110 _ecore_con_server_free(ecore_list_first_remove(servers));
111 ecore_list_destroy(servers);
114 ecore_con_info_shutdown();
115 ecore_con_dns_shutdown();
116 ecore_con_ssl_shutdown();
124 * @defgroup Ecore_Con_Server_Group Ecore Connection Server Functions
126 * Functions that operate on Ecore server objects.
130 * Creates a server to listen for connections.
132 * The socket on which the server listens depends on the connection
134 * @li If @a compl_type is @c ECORE_CON_LOCAL_USER, the server will listen on
135 * the Unix socket "~/.ecore/[name]/[port]".
136 * @li If @a compl_type is @c ECORE_CON_LOCAL_SYSTEM, the server will listen
137 * on Unix socket "/tmp/.ecore_service|[name]|[port]".
138 * @li If @a compl_type is @c ECORE_CON_REMOTE_TCP, the server will listen
139 * on TCP port @c port.
141 * @param compl_type The connection type.
142 * @param name Name to associate with the socket. It is used when
143 * generating the socket name of a Unix socket. Though
144 * it is not used for the TCP socket, it still needs to
145 * be a valid character array. @c NULL will not be
147 * @param port Number to identify socket. When a Unix socket is used,
148 * it becomes part of the socket name. When a TCP socket
149 * is used, it is used as the TCP port.
150 * @param data Data to associate with the created Ecore_Con_Server
152 * @return A new Ecore_Con_Server.
153 * @ingroup Ecore_Con_Server_Group
155 EAPI Ecore_Con_Server *
156 ecore_con_server_add(Ecore_Con_Type compl_type, const char *name, int port,
159 Ecore_Con_Server *svr;
161 struct sockaddr_un socket_unix;
166 if (port < 0) return NULL;
167 /* local user socket: FILE: ~/.ecore/[name]/[port] */
168 /* local system socket: FILE: /tmp/.ecore_service|[name]|[port] */
169 /* remote system socket: TCP/IP: [name]:[port] */
170 svr = calloc(1, sizeof(Ecore_Con_Server));
171 if (!svr) return NULL;
173 svr->name = strdup(name);
174 if (!svr->name) goto error;
175 svr->type = compl_type;
177 svr->data = (void *)data;
179 svr->reject_excess_clients = 0;
180 svr->client_limit = -1;
182 svr->ppid = getpid();
183 ecore_con_ssl_server_prepare(svr);
185 type = compl_type & ECORE_CON_TYPE;
187 if ((type == ECORE_CON_LOCAL_USER) || (type == ECORE_CON_LOCAL_SYSTEM) ||
188 (type == ECORE_CON_LOCAL_ABSTRACT))
195 if (!name) goto error;
196 mask = S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH;
198 if (type == ECORE_CON_LOCAL_USER)
200 homedir = getenv("HOME");
201 if (!homedir) homedir = getenv("TMP");
202 if (!homedir) homedir = "/tmp";
203 mask = S_IRUSR | S_IWUSR | S_IXUSR;
204 snprintf(buf, sizeof(buf), "%s/.ecore", homedir);
205 if (stat(buf, &st) < 0) mkdir(buf, mask);
206 snprintf(buf, sizeof(buf), "%s/.ecore/%s", homedir, name);
207 if (stat(buf, &st) < 0) mkdir(buf, mask);
208 snprintf(buf, sizeof(buf), "%s/.ecore/%s/%i", homedir, name, port);
209 mask = S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH;
211 else if (type == ECORE_CON_LOCAL_SYSTEM)
217 snprintf(buf, sizeof(buf), "%s|%i", name, port);
219 snprintf(buf, sizeof(buf), "%s", name);
222 snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s|%i", name, port);
224 else if (type == ECORE_CON_LOCAL_ABSTRACT)
225 strncpy(buf, name, sizeof(buf));
228 svr->fd = socket(AF_UNIX, SOCK_STREAM, 0);
229 if (svr->fd < 0) goto error_umask;
230 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error_umask;
231 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error_umask;
234 if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, &lin, sizeof(struct linger)) < 0) goto error_umask;
235 socket_unix.sun_family = AF_UNIX;
236 if (type == ECORE_CON_LOCAL_ABSTRACT)
238 #ifdef HAVE_ABSTRACT_SOCKETS
239 /* . is a placeholder */
240 snprintf(socket_unix.sun_path, sizeof(socket_unix.sun_path), ".%s", name);
241 /* first char null indicates abstract namespace */
242 socket_unix.sun_path[0] = '\0';
243 socket_unix_len = LENGTH_OF_ABSTRACT_SOCKADDR_UN(&socket_unix, name);
245 fprintf(stderr, "Your system does not support abstract sockets!\n");
251 strncpy(socket_unix.sun_path, buf, sizeof(socket_unix.sun_path));
252 socket_unix_len = LENGTH_OF_SOCKADDR_UN(&socket_unix);
254 if (bind(svr->fd, (struct sockaddr *)&socket_unix, socket_unix_len) < 0)
256 if (((type == ECORE_CON_LOCAL_USER) || (type == ECORE_CON_LOCAL_SYSTEM)) &&
257 (connect(svr->fd, (struct sockaddr *)&socket_unix, socket_unix_len) < 0) &&
263 if (listen(svr->fd, 4096) < 0) goto error_umask;
264 svr->path = strdup(buf);
265 if (!svr->path) goto error_umask;
267 ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
268 _ecore_con_svr_handler, svr, NULL, NULL);
270 if (!svr->fd_handler) goto error;
273 if (type == ECORE_CON_REMOTE_TCP)
276 if (!ecore_con_info_tcp_listen(svr, _ecore_con_cb_tcp_listen, svr)) goto error;
278 else if (type == ECORE_CON_REMOTE_MCAST || type == ECORE_CON_REMOTE_UDP)
281 if (!ecore_con_info_udp_listen(svr, _ecore_con_cb_udp_listen, svr)) goto error;
284 ecore_list_append(servers, svr);
285 ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER);
292 if (svr->name) free(svr->name);
293 if (svr->path) free(svr->path);
294 if (svr->fd >= 0) close(svr->fd);
295 if (svr->fd_handler) ecore_main_fd_handler_del(svr->fd_handler);
296 if (svr->write_buf) free(svr->write_buf);
297 if (svr->ip) free(svr->ip);
298 ecore_con_ssl_server_shutdown(svr);
304 * Creates a server object to represent the server listening at the
307 * The socket to which the server connects depends on the connection type:
308 * @li If @a compl_type is @c ECORE_CON_LOCAL_USER, the function will
309 * connect to the server listening on the Unix socket
310 * "~/.ecore/[name]/[port]".
311 * @li If @a compl_type is @c ECORE_CON_LOCAL_SYSTEM, the function will
312 * connect to the server listening on the Unix socket
313 * "/tmp/.ecore_service|[name]|[port]".
314 * @li If @a compl_type is @c ECORE_CON_REMOTE_TCP, the function will
315 * connect to the server listening on the TCP port "[name]:[port]".
317 * @param compl_type The connection type.
318 * @param name Name used when determining what socket to connect to.
319 * It is used to generate the socket name when the socket
320 * is a Unix socket. It is used as the hostname when
321 * connecting with a TCP socket.
322 * @param port Number to identify the socket to connect to. Used when
323 * generating the socket name for a Unix socket, or as the
324 * TCP port when connecting to a TCP socket.
325 * @param data Data to associate with the created Ecore_Con_Server
327 * @return A new Ecore_Con_Server.
328 * @ingroup Ecore_Con_Server_Group
330 EAPI Ecore_Con_Server *
331 ecore_con_server_connect(Ecore_Con_Type compl_type, const char *name, int port,
334 Ecore_Con_Server *svr;
336 struct sockaddr_un socket_unix;
340 if (!name) return NULL;
341 /* 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));
345 if (!svr) return NULL;
347 svr->name = strdup(name);
348 if (!svr->name) goto error;
349 svr->type = compl_type;
351 svr->data = (void *)data;
353 svr->reject_excess_clients = 0;
355 svr->client_limit = -1;
356 ecore_con_ssl_server_prepare(svr);
358 type = compl_type & ECORE_CON_TYPE;
360 if ((type == ECORE_CON_REMOTE_TCP || type == ECORE_CON_REMOTE_UDP) && (port < 0)) return NULL;
362 if ((type == ECORE_CON_LOCAL_USER) || (type == ECORE_CON_LOCAL_SYSTEM) ||
363 (type == ECORE_CON_LOCAL_ABSTRACT))
368 if (type == ECORE_CON_LOCAL_USER)
370 homedir = getenv("HOME");
371 if (!homedir) homedir = getenv("TMP");
372 if (!homedir) homedir = "/tmp";
373 snprintf(buf, sizeof(buf), "%s/.ecore/%s/%i", homedir, name, port);
375 else if (type == ECORE_CON_LOCAL_SYSTEM)
380 strncpy(buf, name, sizeof(buf));
382 snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s", name);
387 snprintf(buf, sizeof(buf), "%s|%i", name, port);
389 snprintf(buf, sizeof(buf), "/tmp/.ecore_service|%s|%i", name, port);
392 else if (type == ECORE_CON_LOCAL_ABSTRACT)
393 strncpy(buf, name, sizeof(buf));
395 svr->fd = socket(AF_UNIX, SOCK_STREAM, 0);
396 if (svr->fd < 0) goto error;
397 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
398 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
399 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, &curstate, sizeof(curstate)) < 0) goto error;
400 socket_unix.sun_family = AF_UNIX;
402 if (type == ECORE_CON_LOCAL_ABSTRACT)
404 #ifdef HAVE_ABSTRACT_SOCKETS
405 /* copy name insto sun_path, prefixed by null to indicate abstract namespace */
406 snprintf(socket_unix.sun_path, sizeof(socket_unix.sun_path), ".%s", name);
407 socket_unix.sun_path[0] = '\0';
408 socket_unix_len = LENGTH_OF_ABSTRACT_SOCKADDR_UN(&socket_unix, name);
410 fprintf(stderr, "Your system does not support abstract sockets!\n");
416 strncpy(socket_unix.sun_path, buf, sizeof(socket_unix.sun_path));
417 socket_unix_len = LENGTH_OF_SOCKADDR_UN(&socket_unix);
420 if (connect(svr->fd, (struct sockaddr *)&socket_unix, socket_unix_len) < 0)
424 svr->path = strdup(buf);
425 if (!svr->path) goto error;
427 if (svr->type & ECORE_CON_SSL)
428 ecore_con_ssl_server_init(svr);
431 ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
432 _ecore_con_cl_handler, svr, NULL, NULL);
433 if (!svr->fd_handler) goto error;
437 /* we got our server! */
438 Ecore_Con_Event_Server_Add *e;
440 e = calloc(1, sizeof(Ecore_Con_Event_Server_Add));
445 ecore_event_add(ECORE_CON_EVENT_SERVER_ADD, e,
446 _ecore_con_event_server_add_free, NULL);
451 if (type == ECORE_CON_REMOTE_TCP)
454 if (!ecore_con_info_tcp_connect(svr, _ecore_con_cb_tcp_connect, svr)) goto error;
456 else if (type == ECORE_CON_REMOTE_UDP)
459 if (!ecore_con_info_udp_connect(svr, _ecore_con_cb_udp_connect, svr)) goto error;
462 ecore_list_append(servers, svr);
463 ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER);
468 if (svr->name) free(svr->name);
469 if (svr->path) free(svr->path);
470 if (svr->fd >= 0) close(svr->fd);
471 if (svr->fd_handler) ecore_main_fd_handler_del(svr->fd_handler);
472 ecore_con_ssl_server_shutdown(svr);
478 * Closes the connection and frees the given server.
479 * @param svr The given server.
480 * @return Data associated with the server when it was created.
481 * @ingroup Ecore_Con_Server_Group
484 ecore_con_server_del(Ecore_Con_Server *svr)
488 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
490 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_del");
496 if (svr->event_count > 0)
500 ecore_main_fd_handler_del(svr->fd_handler);
501 svr->fd_handler = NULL;
506 _ecore_con_server_free(svr);
507 if (ecore_list_goto(servers, svr)) ecore_list_remove(servers);
513 * Retrieves the data associated with the given server.
514 * @param svr The given server.
515 * @return The associated data.
516 * @ingroup Ecore_Con_Server_Group
519 ecore_con_server_data_get(Ecore_Con_Server *svr)
521 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
523 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_data_get");
530 * Retrieves whether the given server is currently connected.
531 * @todo Check that this function does what the documenter believes it does.
532 * @param svr The given server.
533 * @return @c 1 if the server is connected. @c 0 otherwise.
534 * @ingroup Ecore_Con_Server_Group
537 ecore_con_server_connected_get(Ecore_Con_Server *svr)
539 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
541 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_connected_get");
544 if (svr->connecting) return 0;
549 * Retrieves the current list of clients.
550 * @param svr The given server.
551 * @return The list of clients on this server.
552 * @ingroup Ecore_Con_Server_Group
555 ecore_con_server_clients_get(Ecore_Con_Server *svr)
557 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
559 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_clients_get");
566 * Sends the given data to the given server.
567 * @param svr The given server.
568 * @param data The given data.
569 * @param size Length of the data, in bytes, to send.
570 * @return The number of bytes sent. @c 0 will be returned if there is an
572 * @ingroup Ecore_Con_Server_Group
575 ecore_con_server_send(Ecore_Con_Server *svr, const void *data, int size)
577 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
579 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_send");
582 if (svr->dead) return 0;
584 if (size < 1) return 0;
586 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE);
589 unsigned char *newbuf;
591 newbuf = realloc(svr->write_buf, svr->write_buf_size + size);
592 if (newbuf) svr->write_buf = newbuf;
594 memcpy(svr->write_buf + svr->write_buf_size, data, size);
595 svr->write_buf_size += size;
599 svr->write_buf = malloc(size);
600 if (!svr->write_buf) return 0;
601 svr->write_buf_size = size;
602 memcpy(svr->write_buf, data, size);
608 * Sets a limit on the number of clients that can be handled concurrently
609 * by the given server, and a policy on what to do if excess clients try to
611 * Beware that if you set this once ecore is already running, you may
612 * already have pending CLIENT_ADD events in your event queue. Those
613 * clients have already connected and will not be affected by this call.
614 * Only clients subsequently trying to connect will be affected.
615 * @param svr The given server.
616 * @param client_limit The maximum number of clients to handle
617 * concurrently. -1 means unlimited (default). 0
618 * effectively disables the server.
619 * @param reject_excess_clients Set to 1 to automatically disconnect
620 * excess clients as soon as they connect if you are
621 * already handling client_limit clients. Set to 0
622 * (default) to just hold off on the "accept()"
623 * system call until the number of active clients
624 * drops. This causes the kernel to queue up to 4096
625 * connections (or your kernel's limit, whichever is
627 * @ingroup Ecore_Con_Server_Group
630 ecore_con_server_client_limit_set(Ecore_Con_Server *svr, int client_limit, char reject_excess_clients)
632 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
634 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_client_limit_set");
637 svr->client_limit = client_limit;
638 svr->reject_excess_clients = reject_excess_clients;
642 * Gets the IP address of a server that has been connected to.
644 * @param svr The given server.
645 * @return A pointer to an internal string that contains the IP address of
646 * the connected server in the form "XXX.YYY.ZZZ.AAA" IP notation.
647 * This string should not be modified or trusted to stay valid after
648 * deletion for the @p svr object. If no IP is known NULL is returned.
649 * @ingroup Ecore_Con_Server_Group
652 ecore_con_server_ip_get(Ecore_Con_Server *svr)
654 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
656 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_ip_get");
663 * Flushes all pending data to the given server. Will return when done.
665 * @param svr The given server.
666 * @ingroup Ecore_Con_Server_Group
669 ecore_con_server_flush(Ecore_Con_Server *svr)
671 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
673 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_flush");
676 _ecore_con_server_flush(svr);
680 * @defgroup Ecore_Con_Client_Group Ecore Connection Client Functions
682 * Functions that operate on Ecore connection client objects.
686 * Sends the given data to the given client.
687 * @param cl The given client.
688 * @param data The given data.
689 * @param size Length of the data, in bytes, to send.
690 * @return The number of bytes sent. @c 0 will be returned if there is an
692 * @ingroup Ecore_Con_Client_Group
695 ecore_con_client_send(Ecore_Con_Client *cl, const void *data, int size)
697 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
699 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_send");
702 if (cl->dead) return 0;
704 if (size < 1) return 0;
706 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE);
708 if(cl->server && cl->server->type == ECORE_CON_REMOTE_UDP)
710 sendto(cl->server->fd, data, size, 0, (struct sockaddr *) cl->data, sizeof(struct sockaddr_in));
714 unsigned char *newbuf;
716 newbuf = realloc(cl->buf, cl->buf_size + size);
717 if (newbuf) cl->buf = newbuf;
719 memcpy(cl->buf + cl->buf_size, data, size);
720 cl->buf_size += size;
724 cl->buf = malloc(size);
725 if (!cl->buf) return 0;
727 memcpy(cl->buf, data, size);
733 * Retrieves the server representing the socket the client has
735 * @param cl The given client.
736 * @return The server that the client connected to.
737 * @ingroup Ecore_Con_Client_Group
739 EAPI Ecore_Con_Server *
740 ecore_con_client_server_get(Ecore_Con_Client *cl)
742 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
744 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_server_get");
751 * Closes the connection and frees memory allocated to the given client.
752 * @param cl The given client.
753 * @return Data associated with the client.
754 * @ingroup Ecore_Con_Client_Group
757 ecore_con_client_del(Ecore_Con_Client *cl)
761 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
763 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_del");
767 if(cl->data && cl->server && (cl->server->type == ECORE_CON_REMOTE_UDP ||
768 cl->server->type == ECORE_CON_REMOTE_MCAST))
775 if (cl->event_count > 0)
779 ecore_main_fd_handler_del(cl->fd_handler);
780 cl->fd_handler = NULL;
785 cl->server->clients = eina_list_remove(cl->server->clients, cl);
786 _ecore_con_client_free(cl);
792 * Sets the data associated with the given client to @p data.
793 * @param cl The given client.
794 * @param data What to set the data to.
795 * @ingroup Ecore_Con_Client_Group
798 ecore_con_client_data_set(Ecore_Con_Client *cl, const void *data)
800 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
802 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_data_set");
805 cl->data = (void *)data;
809 * Retrieves the data associated with the given client.
810 * @param cl The given client.
811 * @return The data associated with @p cl.
812 * @ingroup Ecore_Con_Client_Group
815 ecore_con_client_data_get(Ecore_Con_Client *cl)
817 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
819 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_data_get");
826 * Gets the IP address of a cleint that has connected.
828 * @param cl The given client.
829 * @return A pointer to an internal string that contains the IP address of
830 * the connected client in the form "XXX.YYY.ZZZ.AAA" IP notation.
831 * This string should not be modified or trusted to stay valid after
832 * deletion for the @p cl object. If no IP is known NULL is returned.
833 * @ingroup Ecore_Con_Client_Group
836 ecore_con_client_ip_get(Ecore_Con_Client *cl)
838 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
840 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_ip_get");
847 * Flushes all pending data to the given client. Will return when done.
849 * @param cl The given client.
850 * @ingroup Ecore_Con_Client_Group
853 ecore_con_client_flush(Ecore_Con_Client *cl)
855 if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
857 ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_flush");
860 _ecore_con_client_flush(cl);
864 _ecore_con_server_free(Ecore_Con_Server *svr)
866 Ecore_Con_Client *cl;
869 ECORE_MAGIC_SET(svr, ECORE_MAGIC_NONE);
870 t_start = ecore_time_get();
871 while ((svr->write_buf) && (!svr->dead))
873 _ecore_con_server_flush(svr);
874 t = ecore_time_get();
875 if ((t - t_start) > 0.5)
877 printf("ECORE_CON: EEK - stuck in _ecore_con_server_free() trying\n"
878 " to flush data out from the server, and have been for\n"
879 " %1.1f seconds. This is taking too long. Aborting flush.\n",
884 if (svr->write_buf) free(svr->write_buf);
887 cl = eina_list_data_get(svr->clients);
888 svr->clients = eina_list_remove(svr->clients, cl);
889 _ecore_con_client_free(cl);
891 if ((svr->created) && (svr->path) && (svr->ppid == getpid()))
893 if (svr->fd >= 0) close(svr->fd);
894 ecore_con_ssl_server_shutdown(svr);
895 if (svr->name) free(svr->name);
896 if (svr->path) free(svr->path);
897 if (svr->ip) free(svr->ip);
898 if (svr->fd_handler) ecore_main_fd_handler_del(svr->fd_handler);
903 _ecore_con_client_free(Ecore_Con_Client *cl)
907 ECORE_MAGIC_SET(cl, ECORE_MAGIC_NONE);
908 t_start = ecore_time_get();
909 while ((cl->buf) && (!cl->dead))
911 _ecore_con_client_flush(cl);
912 t = ecore_time_get();
913 if ((t - t_start) > 0.5)
915 printf("ECORE_CON: EEK - stuck in _ecore_con_client_free() trying\n"
916 " to flush data out from the client, and have been for\n"
917 " %1.1f seconds. This is taking too long. Aborting flush.\n",
922 if (cl->buf) free(cl->buf);
923 if (cl->fd >= 0) close(cl->fd);
924 if (cl->fd_handler) ecore_main_fd_handler_del(cl->fd_handler);
925 if (cl->ip) free(cl->ip);
930 kill_server(Ecore_Con_Server *svr)
934 Ecore_Con_Event_Server_Del *e;
936 e = calloc(1, sizeof(Ecore_Con_Event_Server_Del));
941 ecore_event_add(ECORE_CON_EVENT_SERVER_DEL, e,
942 _ecore_con_event_server_del_free, NULL);
947 if (svr->fd_handler) ecore_main_fd_handler_del(svr->fd_handler);
948 svr->fd_handler = NULL;
952 _ecore_con_cb_tcp_listen(void *data, Ecore_Con_Info *net_info)
954 Ecore_Con_Server *svr;
959 if(!net_info) goto error;
961 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype, net_info->info.ai_protocol);
962 if (svr->fd < 0) goto error;
963 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
964 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
967 if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, &lin, sizeof(struct linger)) < 0) goto error;
968 if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0) goto error;
969 if (listen(svr->fd, 4096) < 0) goto error;
971 ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
972 _ecore_con_svr_handler, svr, NULL, NULL);
973 if (!svr->fd_handler) goto error;
978 ecore_con_ssl_server_shutdown(svr);
983 _ecore_con_cb_udp_listen(void *data, Ecore_Con_Info *net_info)
985 Ecore_Con_Server *svr;
988 struct ipv6_mreq mreq6;
993 type &= ECORE_CON_TYPE;
995 if (!net_info) goto error;
997 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype, net_info->info.ai_protocol);
998 if(svr->fd < 0) goto error;
1000 if (type == ECORE_CON_REMOTE_MCAST)
1002 if (net_info->info.ai_family == AF_INET)
1004 if (!inet_pton(net_info->info.ai_family, net_info->ip, &mreq.imr_multiaddr)) goto error;
1005 mreq.imr_interface.s_addr = htonl(INADDR_ANY);
1006 if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq,sizeof(mreq)) != 0) goto error;
1008 else if (net_info->info.ai_family == AF_INET6)
1010 if (!inet_pton(net_info->info.ai_family, net_info->ip, &mreq6.ipv6mr_multiaddr)) goto error;
1011 mreq6.ipv6mr_interface = htonl(INADDR_ANY);
1012 if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq6,sizeof(mreq6)) != 0) goto error;
1014 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, &on,sizeof(on)) != 0) goto error;
1017 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1018 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1019 if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0) goto error;
1021 ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
1022 _ecore_con_svr_udp_handler, svr, NULL, NULL);
1023 if (!svr->fd_handler) goto error;
1024 svr->ip = strdup(net_info->ip);
1029 ecore_con_ssl_server_shutdown(svr);
1034 _ecore_con_cb_tcp_connect(void *data, Ecore_Con_Info *net_info)
1036 Ecore_Con_Server *svr;
1041 if (!net_info) goto error;
1042 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype, net_info->info.ai_protocol);
1043 if (svr->fd < 0) goto error;
1044 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1045 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1046 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, &curstate, sizeof(curstate)) < 0)
1048 if (connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
1050 if (errno != EINPROGRESS)
1052 svr->connecting = 1;
1054 ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE,
1055 _ecore_con_cl_handler, svr, NULL, NULL);
1059 ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
1060 _ecore_con_cl_handler, svr, NULL, NULL);
1062 if (svr->type & ECORE_CON_SSL)
1063 if (ecore_con_ssl_server_init(svr))
1066 if (!svr->fd_handler) goto error;
1067 svr->ip = strdup(net_info->ip);
1072 ecore_con_ssl_server_shutdown(svr);
1077 _ecore_con_cb_udp_connect(void *data, Ecore_Con_Info *net_info)
1079 Ecore_Con_Server *svr;
1084 if (!net_info) goto error;
1085 svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype, net_info->info.ai_protocol);
1086 if (svr->fd < 0) goto error;
1087 if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
1088 if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
1089 if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, &curstate, sizeof(curstate)) < 0)
1091 if (connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
1095 ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE,
1096 _ecore_con_cl_udp_handler, svr, NULL, NULL);
1097 if (!svr->fd_handler) goto error;
1098 svr->ip = strdup(net_info->ip);
1103 ecore_con_ssl_server_shutdown(svr);
1107 static Ecore_Con_State
1108 svr_try_connect_plain(Ecore_Con_Server *svr)
1111 unsigned int size = sizeof(int);
1113 if (getsockopt(svr->fd, SOL_SOCKET, SO_ERROR, &so_err, &size) < 0)
1116 if (so_err == EINPROGRESS && !svr->dead)
1117 return ECORE_CON_INPROGRESS;
1121 /* we lost our server! */
1123 return ECORE_CON_DISCONNECTED;
1127 if (!svr->delete_me)
1129 /* we got our server! */
1130 Ecore_Con_Event_Server_Add *e;
1132 svr->connecting = 0;
1133 e = calloc(1, sizeof(Ecore_Con_Event_Server_Add));
1138 ecore_event_add(ECORE_CON_EVENT_SERVER_ADD, e,
1139 _ecore_con_event_server_add_free, NULL);
1142 if (svr->fd_handler)
1144 if (!svr->write_buf)
1145 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
1150 return ECORE_CON_CONNECTED;
1152 return ECORE_CON_DISCONNECTED;
1155 /* returns 1 on success, 0 on failure */
1156 static Ecore_Con_State svr_try_connect(Ecore_Con_Server *svr)
1158 if (!(svr->type & ECORE_CON_SSL))
1159 return svr_try_connect_plain(svr);
1162 switch (ecore_con_ssl_server_try(svr)) {
1163 case ECORE_CON_CONNECTED:
1164 return svr_try_connect_plain(svr);
1165 case ECORE_CON_DISCONNECTED:
1167 return ECORE_CON_DISCONNECTED;
1169 return ECORE_CON_INPROGRESS;
1175 _ecore_con_svr_handler(void *data, Ecore_Fd_Handler *fd_handler __UNUSED__)
1177 Ecore_Con_Server *svr;
1179 struct sockaddr_in incoming;
1183 if (svr->dead) return 1;
1184 if (svr->delete_me) return 1;
1185 if ((svr->client_limit >= 0) && (!svr->reject_excess_clients))
1187 if (eina_list_count(svr->clients) >= svr->client_limit) return 1;
1190 size_in = sizeof(struct sockaddr_in);
1192 new_fd = accept(svr->fd, (struct sockaddr *)&incoming, (socklen_t *)&size_in);
1195 Ecore_Con_Client *cl;
1199 if ((svr->client_limit >= 0) && (svr->reject_excess_clients))
1205 cl = calloc(1, sizeof(Ecore_Con_Client));
1212 fcntl(new_fd, F_SETFL, O_NONBLOCK);
1213 fcntl(new_fd, F_SETFD, FD_CLOEXEC);
1217 if ((svr->type & ECORE_CON_SSL) &&
1218 (ecore_con_ssl_client_init(cl)))
1221 ecore_con_ssl_client_shutdown(cl);
1226 ecore_main_fd_handler_add(cl->fd, ECORE_FD_READ,
1227 _ecore_con_svr_cl_handler, cl, NULL, NULL);
1228 ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
1229 eina_list_append(svr->clients, cl);
1232 ip = incoming.sin_addr.s_addr;
1233 snprintf(buf, sizeof(buf),
1239 cl->ip = strdup(buf);
1243 Ecore_Con_Event_Client_Add *e;
1245 e = calloc(1, sizeof(Ecore_Con_Event_Client_Add));
1250 ecore_event_add(ECORE_CON_EVENT_CLIENT_ADD, e,
1251 _ecore_con_event_client_add_free, NULL);
1259 _ecore_con_cl_handler(void *data, Ecore_Fd_Handler *fd_handler)
1261 Ecore_Con_Server *svr;
1264 if (svr->dead) return 1;
1265 if (svr->delete_me) return 1;
1266 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
1268 unsigned char *inbuf = NULL;
1271 if (svr->connecting && (svr_try_connect(svr) != ECORE_CON_CONNECTED))
1277 int lost_server = 1;
1278 unsigned char buf[READBUFSIZ];
1280 if (!(svr->type & ECORE_CON_SSL))
1282 if (((num = read(svr->fd, buf, READBUFSIZ)) < 0) &&
1287 if (!(num = ecore_con_ssl_server_read(svr, buf, READBUFSIZ)))
1292 if (inbuf && !svr->delete_me)
1294 Ecore_Con_Event_Server_Data *e;
1296 e = calloc(1, sizeof(Ecore_Con_Event_Server_Data));
1302 e->size = inbuf_num;
1303 ecore_event_add(ECORE_CON_EVENT_SERVER_DATA, e,
1304 _ecore_con_event_server_data_free,
1308 if (lost_server) kill_server(svr);
1312 inbuf = realloc(inbuf, inbuf_num + num);
1313 memcpy(inbuf + inbuf_num, buf, num);
1317 /* #if USE_OPENSSL */
1318 /* if (svr->fd_handler) */
1320 /* if (svr->ssl && ssl_err == SSL_ERROR_WANT_READ) */
1321 /* ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ); */
1322 /* else if (svr->ssl && ssl_err == SSL_ERROR_WANT_WRITE) */
1323 /* ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE); */
1327 else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
1329 if (svr->connecting && !svr_try_connect (svr))
1331 _ecore_con_server_flush(svr);
1338 _ecore_con_cl_udp_handler(void *data, Ecore_Fd_Handler *fd_handler)
1340 Ecore_Con_Server *svr;
1343 if (svr->dead) return 1;
1344 if (svr->delete_me) return 1;
1345 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
1347 unsigned char buf[65536];
1351 num = read(svr->fd, buf, 65536);
1354 if (!svr->delete_me)
1356 Ecore_Con_Event_Server_Data *e;
1357 unsigned char *inbuf;
1359 inbuf = malloc(num);
1362 memcpy(inbuf, buf, num);
1364 e = calloc(1, sizeof(Ecore_Con_Event_Server_Data));
1371 ecore_event_add(ECORE_CON_EVENT_SERVER_DATA, e,
1372 _ecore_con_event_server_data_free,
1378 else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
1379 _ecore_con_server_flush(svr);
1385 _ecore_con_svr_udp_handler(void *data, Ecore_Fd_Handler *fd_handler)
1387 Ecore_Con_Server *svr;
1388 Ecore_Con_Client *cl;
1391 if (svr->dead) return 1;
1392 if (svr->delete_me) return 1;
1393 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
1395 unsigned char buf[READBUFSIZ];
1396 struct sockaddr_in client_addr;
1397 unsigned int client_addr_len = sizeof(client_addr);
1401 num = recvfrom(svr->fd, buf, sizeof(buf), MSG_DONTWAIT, (struct sockaddr*) &client_addr, &client_addr_len);
1405 if (!svr->delete_me)
1407 Ecore_Con_Event_Client_Data *e;
1408 unsigned char *inbuf;
1412 /* Create a new client for use in the client data event */
1413 cl = calloc(1, sizeof(Ecore_Con_Client));
1418 cl->fd_handler = NULL;
1420 cl->data = calloc(1, sizeof(client_addr));
1421 if(cl->data == NULL)
1426 memcpy(cl->data, &client_addr, sizeof(client_addr));
1427 ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
1428 eina_list_append(svr->clients, cl);
1430 ip = client_addr.sin_addr.s_addr;
1431 snprintf(ipbuf, sizeof(ipbuf),
1437 cl->ip = strdup(ipbuf);
1439 inbuf = malloc(num);
1447 memcpy(inbuf, buf, num);
1449 e = calloc(1, sizeof(Ecore_Con_Event_Client_Data));
1456 ecore_event_add(ECORE_CON_EVENT_CLIENT_DATA, e,
1457 _ecore_con_event_client_data_free,
1463 Ecore_Con_Event_Client_Add *add;
1465 add = calloc(1, sizeof(Ecore_Con_Event_Client_Add));
1468 /*cl->event_count++;*/
1470 ecore_event_add(ECORE_CON_EVENT_CLIENT_ADD, add,
1471 _ecore_con_event_client_add_free, NULL);
1475 if ((errno == EIO) || (errno == EBADF) ||
1476 (errno == EPIPE) || (errno == EINVAL) ||
1477 (errno == ENOSPC) || (num == 0)/* is num == 0 right? */)
1479 if (!svr->delete_me)
1481 /* we lost our client! */
1482 Ecore_Con_Event_Client_Del *e;
1484 e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
1489 ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
1490 _ecore_con_event_client_del_free,
1495 if (svr->fd_handler)
1496 ecore_main_fd_handler_del(svr->fd_handler);
1497 svr->fd_handler = NULL;
1501 else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
1502 _ecore_con_client_flush(cl);
1507 _ecore_con_svr_cl_handler(void *data, Ecore_Fd_Handler *fd_handler)
1509 Ecore_Con_Client *cl;
1512 if (cl->dead) return 1;
1513 if (cl->delete_me) return 1;
1514 if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
1516 unsigned char *inbuf = NULL;
1518 int lost_client = 1;
1522 unsigned char buf[65536];
1527 if (!(cl->server->type & ECORE_CON_SSL))
1529 if (((num = read(cl->fd, buf, 65536)) < 0) &&
1534 if (!(num = ecore_con_ssl_client_read(cl, buf, 65536)))
1539 if (inbuf && !cl->delete_me)
1541 Ecore_Con_Event_Client_Data *e;
1543 e = calloc(1, sizeof(Ecore_Con_Event_Client_Data));
1549 e->size = inbuf_num;
1550 ecore_event_add(ECORE_CON_EVENT_CLIENT_DATA, e,
1551 _ecore_con_event_client_data_free,
1560 /* we lost our client! */
1561 Ecore_Con_Event_Client_Del *e;
1563 e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
1568 ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
1569 _ecore_con_event_client_del_free,
1575 ecore_main_fd_handler_del(cl->fd_handler);
1576 cl->fd_handler = NULL;
1582 inbuf = realloc(inbuf, inbuf_num + num);
1583 memcpy(inbuf + inbuf_num, buf, num);
1588 else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
1589 _ecore_con_client_flush(cl);
1594 _ecore_con_server_flush(Ecore_Con_Server *svr)
1598 if (!svr->write_buf) return;
1600 /* check whether we need to write anything at all.
1601 * we must not write zero bytes with SSL_write() since it
1602 * causes undefined behaviour
1604 if (svr->write_buf_size == svr->write_buf_offset)
1607 num = svr->write_buf_size - svr->write_buf_offset;
1609 if (!(svr->type & ECORE_CON_SSL))
1610 count = write(svr->fd, svr->write_buf + svr->write_buf_offset, num);
1612 count = ecore_con_ssl_server_write(svr, svr->write_buf + svr->write_buf_offset, num);
1616 /* we lost our server! */
1621 svr->write_buf_offset += count;
1622 if (svr->write_buf_offset >= svr->write_buf_size)
1624 svr->write_buf_size = 0;
1625 svr->write_buf_offset = 0;
1626 free(svr->write_buf);
1627 svr->write_buf = NULL;
1628 if (svr->fd_handler)
1629 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
1634 _ecore_con_client_flush(Ecore_Con_Client *cl)
1638 if (!cl->buf) return;
1639 num = cl->buf_size - cl->buf_offset;
1640 if (!(cl->server->type & ECORE_CON_SSL))
1641 count = write(cl->fd, cl->buf + cl->buf_offset, num);
1643 count = ecore_con_ssl_client_write(cl, cl->buf + cl->buf_offset, num);
1646 if ((errno == EIO) || (errno == EBADF) || (errno == EPIPE) ||
1647 (errno == EINVAL) || (errno == ENOSPC))
1651 /* we lost our client! */
1652 Ecore_Con_Event_Client_Del *e;
1654 e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
1659 ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
1660 _ecore_con_event_client_del_free, NULL);
1664 ecore_main_fd_handler_del(cl->fd_handler);
1665 cl->fd_handler = NULL;
1670 cl->buf_offset += count;
1671 if (cl->buf_offset >= cl->buf_size)
1678 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ);
1683 _ecore_con_event_client_add_free(void *data __UNUSED__, void *ev)
1685 Ecore_Con_Event_Client_Add *e;
1688 e->client->event_count--;
1689 if ((e->client->event_count == 0) && (e->client->delete_me))
1690 ecore_con_client_del(e->client);
1695 _ecore_con_event_client_del_free(void *data __UNUSED__, void *ev)
1697 Ecore_Con_Event_Client_Del *e;
1700 e->client->event_count--;
1701 if ((e->client->event_count == 0) && (e->client->delete_me))
1702 ecore_con_client_del(e->client);
1707 _ecore_con_event_client_data_free(void *data __UNUSED__, void *ev)
1709 Ecore_Con_Event_Client_Data *e;
1712 e->client->event_count--;
1713 if (e->data) free(e->data);
1714 if (((e->client->event_count == 0) && (e->client->delete_me)) ||
1715 ((e->client->server && (e->client->server->type == ECORE_CON_REMOTE_UDP ||
1716 e->client->server->type == ECORE_CON_REMOTE_MCAST))))
1717 ecore_con_client_del(e->client);
1722 _ecore_con_event_server_add_free(void *data __UNUSED__, void *ev)
1724 Ecore_Con_Event_Server_Add *e;
1727 e->server->event_count--;
1728 if ((e->server->event_count == 0) && (e->server->delete_me))
1729 ecore_con_server_del(e->server);
1734 _ecore_con_event_server_del_free(void *data __UNUSED__, void *ev)
1736 Ecore_Con_Event_Server_Del *e;
1739 e->server->event_count--;
1740 if ((e->server->event_count == 0) && (e->server->delete_me))
1741 ecore_con_server_del(e->server);
1746 _ecore_con_event_server_data_free(void *data __UNUSED__, void *ev)
1748 Ecore_Con_Event_Server_Data *e;
1751 e->server->event_count--;
1752 if (e->data) free(e->data);
1753 if ((e->server->event_count == 0) && (e->server->delete_me))
1754 ecore_con_server_del(e->server);