2009-01-31 10:33:39 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2010-01-04 15:43:16 -08:00
|
|
|
#include <stdio.h>
|
2010-01-16 05:44:25 -08:00
|
|
|
#include <string.h>
|
2009-11-20 02:58:19 -08:00
|
|
|
#include <sys/types.h>
|
2003-09-23 01:09:32 -07:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <errno.h>
|
2009-01-31 10:33:39 -08:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
2006-03-13 00:50:26 -08:00
|
|
|
|
2010-02-20 11:12:52 -08:00
|
|
|
#ifdef HAVE_ARPA_INET_H
|
2010-02-20 10:01:50 -08:00
|
|
|
# include <arpa/inet.h>
|
2010-02-20 11:12:52 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_NETINET_TCP_H
|
2010-02-20 10:01:50 -08:00
|
|
|
# include <netinet/tcp.h>
|
|
|
|
#endif
|
2006-01-06 09:58:12 -08:00
|
|
|
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
2008-01-25 21:40:53 -08:00
|
|
|
# include <netinet/in.h>
|
|
|
|
#endif
|
2006-01-06 09:58:12 -08:00
|
|
|
|
2010-02-20 11:12:52 -08:00
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
|
|
|
# include <sys/socket.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_UN_H
|
|
|
|
# include <sys/un.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_WS2TCPIP_H
|
|
|
|
# include <ws2tcpip.h>
|
|
|
|
#endif
|
|
|
|
|
2010-02-20 10:01:50 -08:00
|
|
|
#ifdef HAVE_EVIL
|
|
|
|
# include <Evil.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "Ecore.h"
|
|
|
|
#include "ecore_private.h"
|
|
|
|
#include "Ecore_Con.h"
|
|
|
|
#include "ecore_con_private.h"
|
|
|
|
|
2010-09-21 21:48:09 -07:00
|
|
|
static Eina_Bool _ecore_con_client_timer(Ecore_Con_Client *cl);
|
|
|
|
static void _ecore_con_cl_timer_update(Ecore_Con_Client *cl);
|
|
|
|
|
2010-11-03 10:58:37 -07:00
|
|
|
static void _ecore_con_cb_tcp_connect(void *data,
|
|
|
|
Ecore_Con_Info *info);
|
|
|
|
static void _ecore_con_cb_udp_connect(void *data,
|
|
|
|
Ecore_Con_Info *info);
|
|
|
|
static void _ecore_con_cb_tcp_listen(void *data,
|
|
|
|
Ecore_Con_Info *info);
|
|
|
|
static void _ecore_con_cb_udp_listen(void *data,
|
|
|
|
Ecore_Con_Info *info);
|
2008-10-09 05:30:19 -07:00
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
static void _ecore_con_server_free(Ecore_Con_Server *svr);
|
|
|
|
static void _ecore_con_client_free(Ecore_Con_Client *cl);
|
2008-10-09 05:30:19 -07:00
|
|
|
|
2010-11-03 10:58:37 -07:00
|
|
|
static Eina_Bool _ecore_con_svr_tcp_handler(void *data,
|
|
|
|
Ecore_Fd_Handler *fd_handler);
|
|
|
|
static Eina_Bool _ecore_con_cl_handler(void *data,
|
|
|
|
Ecore_Fd_Handler *fd_handler);
|
|
|
|
static Eina_Bool _ecore_con_cl_udp_handler(void *data,
|
|
|
|
Ecore_Fd_Handler *fd_handler);
|
|
|
|
static Eina_Bool _ecore_con_svr_udp_handler(void *data,
|
|
|
|
Ecore_Fd_Handler *fd_handler);
|
2010-09-17 22:30:16 -07:00
|
|
|
|
|
|
|
static void _ecore_con_svr_cl_read(Ecore_Con_Client *cl);
|
2010-11-03 10:58:37 -07:00
|
|
|
static Eina_Bool _ecore_con_svr_cl_handler(void *data,
|
|
|
|
Ecore_Fd_Handler *fd_handler);
|
|
|
|
|
|
|
|
static void _ecore_con_server_flush(Ecore_Con_Server *svr);
|
|
|
|
static void _ecore_con_client_flush(Ecore_Con_Client *cl);
|
|
|
|
|
|
|
|
static void _ecore_con_event_client_add_free(void *data,
|
|
|
|
void *ev);
|
|
|
|
static void _ecore_con_event_client_del_free(void *data,
|
|
|
|
void *ev);
|
|
|
|
static void _ecore_con_event_client_data_free(void *data,
|
|
|
|
void *ev);
|
|
|
|
static void _ecore_con_event_server_add_free(void *data,
|
|
|
|
void *ev);
|
|
|
|
static void _ecore_con_event_server_del_free(void *data,
|
|
|
|
void *ev);
|
|
|
|
static void _ecore_con_event_server_data_free(void *data,
|
|
|
|
void *ev);
|
|
|
|
|
|
|
|
static void _ecore_con_lookup_done(void *data,
|
|
|
|
Ecore_Con_Info *infos);
|
2010-07-22 04:32:55 -07:00
|
|
|
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI int ECORE_CON_EVENT_CLIENT_ADD = 0;
|
|
|
|
EAPI int ECORE_CON_EVENT_CLIENT_DEL = 0;
|
|
|
|
EAPI int ECORE_CON_EVENT_SERVER_ADD = 0;
|
|
|
|
EAPI int ECORE_CON_EVENT_SERVER_DEL = 0;
|
|
|
|
EAPI int ECORE_CON_EVENT_CLIENT_DATA = 0;
|
|
|
|
EAPI int ECORE_CON_EVENT_SERVER_DATA = 0;
|
2003-09-23 01:09:32 -07:00
|
|
|
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
static Eina_List *servers = NULL;
|
2009-10-09 22:28:43 -07:00
|
|
|
static int _ecore_con_init_count = 0;
|
2009-12-21 09:32:19 -08:00
|
|
|
int _ecore_con_log_dom = -1;
|
2003-09-23 01:09:32 -07:00
|
|
|
|
2004-09-22 01:17:15 -07:00
|
|
|
/**
|
2010-07-28 17:27:15 -07:00
|
|
|
* @addtogroup Ecore_Con_Lib_Group Ecore Connection Library Functions
|
2004-09-22 01:17:15 -07:00
|
|
|
*
|
|
|
|
* Utility functions that set up and shut down the Ecore Connection
|
|
|
|
* library.
|
2010-07-28 17:27:15 -07:00
|
|
|
* @{
|
2004-09-22 01:17:15 -07:00
|
|
|
*/
|
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
/**
|
2004-07-15 06:43:15 -07:00
|
|
|
* Initialises the Ecore_Con library.
|
2004-09-22 01:17:15 -07:00
|
|
|
* @return Number of times the library has been initialised without being
|
|
|
|
* shut down.
|
2003-09-23 01:09:32 -07:00
|
|
|
*/
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI int
|
2003-09-23 01:09:32 -07:00
|
|
|
ecore_con_init(void)
|
|
|
|
{
|
2009-10-09 22:28:43 -07:00
|
|
|
if (++_ecore_con_init_count != 1)
|
2010-11-03 10:58:37 -07:00
|
|
|
return _ecore_con_init_count;
|
2009-10-09 22:28:43 -07:00
|
|
|
|
2010-01-14 23:44:27 -08:00
|
|
|
#ifdef HAVE_EVIL
|
|
|
|
if (!evil_init())
|
2010-11-03 10:58:37 -07:00
|
|
|
return --_ecore_con_init_count;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-01-14 23:44:27 -08:00
|
|
|
#endif
|
|
|
|
|
2009-10-09 22:28:43 -07:00
|
|
|
if (!ecore_init())
|
2010-11-03 10:58:37 -07:00
|
|
|
return --_ecore_con_init_count;
|
2005-09-07 02:06:06 -07:00
|
|
|
|
2010-10-07 15:31:46 -07:00
|
|
|
_ecore_con_log_dom = eina_log_domain_register
|
2010-11-03 10:58:37 -07:00
|
|
|
("ecore_con", ECORE_CON_DEFAULT_LOG_COLOR);
|
2009-12-21 09:32:19 -08:00
|
|
|
if(_ecore_con_log_dom < 0)
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
EINA_LOG_ERR("Impossible to create a log domain for Ecore Con.");
|
|
|
|
ecore_shutdown();
|
|
|
|
return --_ecore_con_init_count;
|
2009-12-21 09:32:19 -08:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2005-09-07 02:06:06 -07:00
|
|
|
ECORE_CON_EVENT_CLIENT_ADD = ecore_event_type_new();
|
|
|
|
ECORE_CON_EVENT_CLIENT_DEL = ecore_event_type_new();
|
|
|
|
ECORE_CON_EVENT_SERVER_ADD = ecore_event_type_new();
|
|
|
|
ECORE_CON_EVENT_SERVER_DEL = ecore_event_type_new();
|
|
|
|
ECORE_CON_EVENT_CLIENT_DATA = ecore_event_type_new();
|
|
|
|
ECORE_CON_EVENT_SERVER_DATA = ecore_event_type_new();
|
2004-03-31 08:47:45 -08:00
|
|
|
|
2005-09-07 02:06:06 -07:00
|
|
|
/* TODO Remember return value, if it fails, use gethostbyname() */
|
2008-10-30 08:26:11 -07:00
|
|
|
ecore_con_ssl_init();
|
2008-10-09 05:30:19 -07:00
|
|
|
ecore_con_info_init();
|
2005-09-07 02:06:06 -07:00
|
|
|
|
2009-10-09 22:28:43 -07:00
|
|
|
return _ecore_con_init_count;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-07-15 06:43:15 -07:00
|
|
|
* Shuts down the Ecore_Con library.
|
2004-09-22 01:17:15 -07:00
|
|
|
* @return Number of times the library has been initialised without being
|
|
|
|
* shut down.
|
2003-09-23 01:09:32 -07:00
|
|
|
*/
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI int
|
2003-09-23 01:09:32 -07:00
|
|
|
ecore_con_shutdown(void)
|
|
|
|
{
|
2009-10-09 22:28:43 -07:00
|
|
|
if (--_ecore_con_init_count != 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
return _ecore_con_init_count;
|
2010-01-28 08:07:33 -08:00
|
|
|
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
while (servers)
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_server_free(eina_list_data_get(servers));
|
2005-09-07 02:06:06 -07:00
|
|
|
|
2008-10-09 05:30:19 -07:00
|
|
|
ecore_con_info_shutdown();
|
2008-10-30 08:26:11 -07:00
|
|
|
ecore_con_ssl_shutdown();
|
2009-12-21 09:32:19 -08:00
|
|
|
eina_log_domain_unregister(_ecore_con_log_dom);
|
|
|
|
_ecore_con_log_dom = -1;
|
2006-01-19 01:11:30 -08:00
|
|
|
ecore_shutdown();
|
2010-01-14 23:44:27 -08:00
|
|
|
#ifdef HAVE_EVIL
|
|
|
|
evil_shutdown();
|
|
|
|
#endif
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2009-10-09 22:28:43 -07:00
|
|
|
return _ecore_con_init_count;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
2010-09-20 23:49:07 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Do an asynchronous DNS lookup.
|
|
|
|
*
|
|
|
|
* This function performs a DNS lookup on the hostname specified by @p name, then
|
|
|
|
* calls @p done_cb with
|
|
|
|
*
|
|
|
|
* @param name IP address or server name to translate.
|
|
|
|
* @param done_cb Callback to notify when done.
|
|
|
|
* @param data User data to be given to done_cb.
|
|
|
|
* @return EINA_TRUE if the request did not fail to be set up, EINA_FALSE if it failed.
|
|
|
|
*/
|
|
|
|
EAPI Eina_Bool
|
2010-11-03 10:58:37 -07:00
|
|
|
ecore_con_lookup(const char *name,
|
|
|
|
Ecore_Con_Dns_Cb done_cb,
|
|
|
|
const void *data)
|
2010-09-20 23:49:07 -07:00
|
|
|
{
|
|
|
|
Ecore_Con_Server *svr;
|
|
|
|
Ecore_Con_Lookup *lk;
|
|
|
|
struct addrinfo hints;
|
|
|
|
|
|
|
|
if (!name || !done_cb)
|
2010-11-03 10:58:37 -07:00
|
|
|
return EINA_FALSE;
|
2010-09-20 23:49:07 -07:00
|
|
|
|
|
|
|
svr = calloc(1, sizeof(Ecore_Con_Server));
|
|
|
|
if (!svr)
|
2010-11-03 10:58:37 -07:00
|
|
|
return EINA_FALSE;
|
2010-09-20 23:49:07 -07:00
|
|
|
|
|
|
|
lk = malloc(sizeof (Ecore_Con_Lookup));
|
|
|
|
if (!lk)
|
|
|
|
{
|
|
|
|
free(svr);
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
lk->done_cb = done_cb;
|
|
|
|
lk->data = data;
|
|
|
|
|
|
|
|
svr->name = strdup(name);
|
|
|
|
if (!svr->name)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto on_error;
|
2010-09-20 23:49:07 -07:00
|
|
|
|
|
|
|
svr->type = ECORE_CON_REMOTE_TCP;
|
|
|
|
svr->port = 1025;
|
|
|
|
svr->data = lk;
|
|
|
|
svr->created = EINA_TRUE;
|
|
|
|
svr->reject_excess_clients = EINA_FALSE;
|
|
|
|
svr->client_limit = -1;
|
|
|
|
svr->clients = NULL;
|
|
|
|
svr->ppid = getpid();
|
|
|
|
|
|
|
|
memset(&hints, 0, sizeof(struct addrinfo));
|
|
|
|
hints.ai_family = AF_INET6;
|
|
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
|
|
hints.ai_flags = AI_CANONNAME;
|
|
|
|
hints.ai_protocol = IPPROTO_TCP;
|
|
|
|
hints.ai_canonname = NULL;
|
|
|
|
hints.ai_next = NULL;
|
|
|
|
hints.ai_addr = NULL;
|
|
|
|
|
|
|
|
if (ecore_con_info_get(svr, _ecore_con_lookup_done, svr,
|
|
|
|
&hints))
|
2010-11-03 10:58:37 -07:00
|
|
|
return EINA_TRUE;
|
2010-09-20 23:49:07 -07:00
|
|
|
|
|
|
|
free(svr->name);
|
|
|
|
on_error:
|
|
|
|
free(lk);
|
|
|
|
free(svr);
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
2010-07-28 17:27:15 -07:00
|
|
|
|
2004-09-22 01:17:15 -07:00
|
|
|
/**
|
2010-07-28 17:27:15 -07:00
|
|
|
* @addtogroup Ecore_Con_Server_Group Ecore Connection Server Functions
|
2004-09-22 01:17:15 -07:00
|
|
|
*
|
|
|
|
* Functions that operate on Ecore server objects.
|
2010-09-20 23:49:07 -07:00
|
|
|
*
|
2010-07-28 17:27:15 -07:00
|
|
|
* @{
|
2004-09-22 01:17:15 -07:00
|
|
|
*/
|
|
|
|
|
2010-09-20 23:49:07 -07:00
|
|
|
/**
|
|
|
|
* @example ecore_con_server_example.c
|
|
|
|
* Shows how to write a simple server using the Ecore_Con library.
|
2010-11-03 10:58:37 -07:00
|
|
|
*/
|
2010-09-20 23:49:07 -07:00
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
/**
|
2004-07-15 06:43:15 -07:00
|
|
|
* Creates a server to listen for connections.
|
2003-09-23 01:09:32 -07:00
|
|
|
*
|
2004-07-15 06:43:15 -07:00
|
|
|
* The socket on which the server listens depends on the connection
|
|
|
|
* type:
|
|
|
|
* @li If @a compl_type is @c ECORE_CON_LOCAL_USER, the server will listen on
|
|
|
|
* the Unix socket "~/.ecore/[name]/[port]".
|
|
|
|
* @li If @a compl_type is @c ECORE_CON_LOCAL_SYSTEM, the server will listen
|
|
|
|
* on Unix socket "/tmp/.ecore_service|[name]|[port]".
|
2008-09-25 04:37:01 -07:00
|
|
|
* @li If @a compl_type is @c ECORE_CON_REMOTE_TCP, the server will listen
|
2004-07-15 06:43:15 -07:00
|
|
|
* on TCP port @c port.
|
|
|
|
*
|
|
|
|
* @param compl_type The connection type.
|
|
|
|
* @param name Name to associate with the socket. It is used when
|
2010-08-28 03:01:20 -07:00
|
|
|
* generating the socket name of a Unix socket, or for
|
|
|
|
* determining what host to listen on for TCP sockets.
|
|
|
|
* @c NULL will not be accepted.
|
2004-07-15 06:43:15 -07:00
|
|
|
* @param port Number to identify socket. When a Unix socket is used,
|
|
|
|
* it becomes part of the socket name. When a TCP socket
|
|
|
|
* is used, it is used as the TCP port.
|
|
|
|
* @param data Data to associate with the created Ecore_Con_Server
|
|
|
|
* object.
|
|
|
|
* @return A new Ecore_Con_Server.
|
2003-09-23 01:09:32 -07:00
|
|
|
*/
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI Ecore_Con_Server *
|
2010-09-20 23:49:07 -07:00
|
|
|
ecore_con_server_add(Ecore_Con_Type compl_type,
|
2010-11-03 10:58:37 -07:00
|
|
|
const char *name,
|
|
|
|
int port,
|
|
|
|
const void *data)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
Ecore_Con_Server *svr;
|
|
|
|
Ecore_Con_Type type;
|
|
|
|
|
|
|
|
if (port < 0 || !name)
|
2010-11-03 10:58:37 -07:00
|
|
|
return NULL; /* local user socket: FILE: ~/.ecore/[name]/[port] */
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
/* local system socket: FILE: /tmp/.ecore_service|[name]|[port] */
|
|
|
|
/* remote system socket: TCP/IP: [name]:[port] */
|
|
|
|
svr = calloc(1, sizeof(Ecore_Con_Server));
|
2010-07-26 23:30:27 -07:00
|
|
|
if (!svr)
|
2010-11-03 10:58:37 -07:00
|
|
|
return NULL;
|
2003-09-23 01:09:32 -07:00
|
|
|
|
2008-10-09 05:30:19 -07:00
|
|
|
svr->name = strdup(name);
|
2010-07-26 23:30:27 -07:00
|
|
|
if (!svr->name)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2008-10-09 05:30:19 -07:00
|
|
|
svr->type = compl_type;
|
|
|
|
svr->port = port;
|
|
|
|
svr->data = (void *)data;
|
2010-09-17 23:30:13 -07:00
|
|
|
svr->created = EINA_TRUE;
|
2010-10-13 09:40:52 -07:00
|
|
|
if (compl_type & ECORE_CON_LOAD_CERT)
|
|
|
|
svr->use_cert = EINA_TRUE;
|
2010-09-17 23:30:13 -07:00
|
|
|
svr->reject_excess_clients = EINA_FALSE;
|
2008-10-09 05:30:19 -07:00
|
|
|
svr->client_limit = -1;
|
2008-12-11 05:55:47 -08:00
|
|
|
svr->clients = NULL;
|
2008-10-09 05:30:19 -07:00
|
|
|
svr->ppid = getpid();
|
2010-09-18 12:29:43 -07:00
|
|
|
if (ecore_con_ssl_server_prepare(svr, compl_type & ECORE_CON_SSL))
|
|
|
|
goto error;
|
2008-10-09 05:30:19 -07:00
|
|
|
|
|
|
|
type = compl_type & ECORE_CON_TYPE;
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
if ((type == ECORE_CON_LOCAL_USER) ||
|
2010-05-15 20:04:18 -07:00
|
|
|
(type == ECORE_CON_LOCAL_SYSTEM) ||
|
2006-09-24 00:53:47 -07:00
|
|
|
(type == ECORE_CON_LOCAL_ABSTRACT))
|
2010-11-03 10:58:37 -07:00
|
|
|
/* Local */
|
|
|
|
if (!ecore_con_local_listen(svr, _ecore_con_svr_tcp_handler, svr))
|
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if ((type == ECORE_CON_REMOTE_TCP) ||
|
2010-05-15 20:04:18 -07:00
|
|
|
(type == ECORE_CON_REMOTE_NODELAY))
|
2008-09-17 08:08:48 -07:00
|
|
|
{
|
2008-10-09 05:30:19 -07:00
|
|
|
/* TCP */
|
2010-11-03 10:58:37 -07:00
|
|
|
if (!ecore_con_info_tcp_listen(svr, _ecore_con_cb_tcp_listen,
|
|
|
|
svr))
|
2010-07-26 23:30:27 -07:00
|
|
|
goto error;
|
2004-04-14 01:51:19 -07:00
|
|
|
}
|
2010-05-15 20:04:18 -07:00
|
|
|
else if ((type == ECORE_CON_REMOTE_MCAST) ||
|
|
|
|
(type == ECORE_CON_REMOTE_UDP))
|
2010-11-03 10:58:37 -07:00
|
|
|
/* UDP and MCAST */
|
|
|
|
if (!ecore_con_info_udp_listen(svr, _ecore_con_cb_udp_listen,
|
|
|
|
svr))
|
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
servers = eina_list_append(servers, svr);
|
2008-10-08 17:46:29 -07:00
|
|
|
ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER);
|
2008-10-09 05:30:19 -07:00
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
return svr;
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
error:
|
|
|
|
if (svr->name)
|
2010-11-03 10:58:37 -07:00
|
|
|
free(svr->name);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (svr->path)
|
2010-11-03 10:58:37 -07:00
|
|
|
free(svr->path);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-01-14 23:44:27 -08:00
|
|
|
#ifndef _WIN32
|
2010-07-26 23:30:27 -07:00
|
|
|
if (svr->fd >= 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
close(svr->fd);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (svr->fd_handler)
|
2010-11-03 10:58:37 -07:00
|
|
|
ecore_main_fd_handler_del(svr->fd_handler);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (svr->write_buf)
|
2010-11-03 10:58:37 -07:00
|
|
|
free(svr->write_buf);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (svr->ip)
|
2010-11-03 10:58:37 -07:00
|
|
|
free(svr->ip);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-01-14 23:44:27 -08:00
|
|
|
#endif
|
2010-11-03 10:58:37 -07:00
|
|
|
ecore_con_ssl_server_shutdown(svr);
|
2003-09-23 01:09:32 -07:00
|
|
|
free(svr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-07-26 17:10:40 -07:00
|
|
|
* Creates a connection to the specified server and returns an associated object.
|
2004-07-15 06:43:15 -07:00
|
|
|
*
|
2010-07-26 17:10:40 -07:00
|
|
|
* The socket to which the connection is made depends on the connection type:
|
2004-07-15 06:43:15 -07:00
|
|
|
* @li If @a compl_type is @c ECORE_CON_LOCAL_USER, the function will
|
2010-07-26 17:10:40 -07:00
|
|
|
* connect to the server at the Unix socket
|
2004-07-15 06:43:15 -07:00
|
|
|
* "~/.ecore/[name]/[port]".
|
|
|
|
* @li If @a compl_type is @c ECORE_CON_LOCAL_SYSTEM, the function will
|
2010-07-26 17:10:40 -07:00
|
|
|
* connect to the server at the Unix socket
|
2004-07-15 06:43:15 -07:00
|
|
|
* "/tmp/.ecore_service|[name]|[port]".
|
2008-09-25 04:37:01 -07:00
|
|
|
* @li If @a compl_type is @c ECORE_CON_REMOTE_TCP, the function will
|
2010-07-26 17:10:40 -07:00
|
|
|
* connect to the server at the TCP port "[name]:[port]".
|
2003-09-23 01:09:32 -07:00
|
|
|
*
|
2004-07-15 06:43:15 -07:00
|
|
|
* @param compl_type The connection type.
|
|
|
|
* @param name Name used when determining what socket to connect to.
|
|
|
|
* It is used to generate the socket name when the socket
|
|
|
|
* is a Unix socket. It is used as the hostname when
|
|
|
|
* connecting with a TCP socket.
|
2004-07-22 06:07:25 -07:00
|
|
|
* @param port Number to identify the socket to connect to. Used when
|
2004-07-15 06:43:15 -07:00
|
|
|
* generating the socket name for a Unix socket, or as the
|
|
|
|
* TCP port when connecting to a TCP socket.
|
|
|
|
* @param data Data to associate with the created Ecore_Con_Server
|
|
|
|
* object.
|
|
|
|
* @return A new Ecore_Con_Server.
|
2003-09-23 01:09:32 -07:00
|
|
|
*/
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI Ecore_Con_Server *
|
2010-09-20 23:49:07 -07:00
|
|
|
ecore_con_server_connect(Ecore_Con_Type compl_type,
|
2010-11-03 10:58:37 -07:00
|
|
|
const char *name,
|
|
|
|
int port,
|
|
|
|
const void *data)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
Ecore_Con_Server *svr;
|
|
|
|
Ecore_Con_Type type;
|
|
|
|
|
|
|
|
if (!name)
|
2010-11-03 10:58:37 -07:00
|
|
|
return NULL;
|
2010-09-18 12:26:05 -07:00
|
|
|
/* local user socket: FILE: ~/.ecore/[name]/[port] */
|
2003-09-23 01:09:32 -07:00
|
|
|
/* local system socket: FILE: /tmp/.ecore_service|[name]|[port] */
|
|
|
|
/* remote system socket: TCP/IP: [name]:[port] */
|
|
|
|
svr = calloc(1, sizeof(Ecore_Con_Server));
|
2010-07-26 23:30:27 -07:00
|
|
|
if (!svr)
|
2010-11-03 10:58:37 -07:00
|
|
|
return NULL;
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2008-10-09 05:30:19 -07:00
|
|
|
svr->name = strdup(name);
|
2010-07-26 23:30:27 -07:00
|
|
|
if (!svr->name)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2008-10-09 05:30:19 -07:00
|
|
|
svr->type = compl_type;
|
|
|
|
svr->port = port;
|
|
|
|
svr->data = (void *)data;
|
2010-09-17 23:30:13 -07:00
|
|
|
svr->created = EINA_FALSE;
|
2010-09-27 20:16:08 -07:00
|
|
|
svr->use_cert = (compl_type & ECORE_CON_LOAD_CERT);
|
2010-09-17 23:30:13 -07:00
|
|
|
svr->reject_excess_clients = EINA_FALSE;
|
2008-12-11 05:55:47 -08:00
|
|
|
svr->clients = NULL;
|
2008-10-09 05:30:19 -07:00
|
|
|
svr->client_limit = -1;
|
2010-09-18 12:29:43 -07:00
|
|
|
if (ecore_con_ssl_server_prepare(svr, compl_type & ECORE_CON_SSL))
|
|
|
|
goto error;
|
2008-10-09 05:30:19 -07:00
|
|
|
|
|
|
|
type = compl_type & ECORE_CON_TYPE;
|
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
if (((type == ECORE_CON_REMOTE_TCP) ||
|
2010-05-15 20:04:18 -07:00
|
|
|
(type == ECORE_CON_REMOTE_NODELAY) ||
|
2010-07-26 23:30:27 -07:00
|
|
|
(type == ECORE_CON_REMOTE_UDP) ||
|
2010-05-15 20:04:18 -07:00
|
|
|
(type == ECORE_CON_REMOTE_BROADCAST)) &&
|
|
|
|
(port < 0))
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if ((type == ECORE_CON_LOCAL_USER) ||
|
2010-05-15 20:04:18 -07:00
|
|
|
(type == ECORE_CON_LOCAL_SYSTEM) ||
|
2006-09-24 00:53:47 -07:00
|
|
|
(type == ECORE_CON_LOCAL_ABSTRACT))
|
2010-11-03 10:58:37 -07:00
|
|
|
/* Local */
|
|
|
|
if (!ecore_con_local_connect(svr, _ecore_con_cl_handler, svr,
|
|
|
|
_ecore_con_event_server_add_free))
|
|
|
|
goto
|
|
|
|
error;
|
2004-03-31 08:47:45 -08:00
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
if ((type == ECORE_CON_REMOTE_TCP) ||
|
2010-05-15 20:04:18 -07:00
|
|
|
(type == ECORE_CON_REMOTE_NODELAY))
|
2006-01-19 01:11:30 -08:00
|
|
|
{
|
2008-10-09 05:30:19 -07:00
|
|
|
/* TCP */
|
2010-11-03 10:58:37 -07:00
|
|
|
if (!ecore_con_info_tcp_connect(svr, _ecore_con_cb_tcp_connect,
|
|
|
|
svr))
|
2010-07-26 23:30:27 -07:00
|
|
|
goto error;
|
2006-01-19 01:11:30 -08:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
else if ((type == ECORE_CON_REMOTE_UDP) ||
|
2010-05-15 20:04:18 -07:00
|
|
|
(type == ECORE_CON_REMOTE_BROADCAST))
|
2010-11-03 10:58:37 -07:00
|
|
|
/* UDP and MCAST */
|
|
|
|
if (!ecore_con_info_udp_connect(svr, _ecore_con_cb_udp_connect,
|
|
|
|
svr))
|
|
|
|
goto error;
|
2005-09-02 20:07:29 -07:00
|
|
|
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
servers = eina_list_append(servers, svr);
|
2008-10-09 05:30:19 -07:00
|
|
|
ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER);
|
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
return svr;
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
error:
|
|
|
|
if (svr->name)
|
2010-11-03 10:58:37 -07:00
|
|
|
free(svr->name);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (svr->path)
|
2010-11-03 10:58:37 -07:00
|
|
|
free(svr->path);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (svr->fd >= 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
close(svr->fd);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (svr->fd_handler)
|
2010-11-03 10:58:37 -07:00
|
|
|
ecore_main_fd_handler_del(svr->fd_handler);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2008-10-30 08:26:11 -07:00
|
|
|
ecore_con_ssl_server_shutdown(svr);
|
2003-09-23 01:09:32 -07:00
|
|
|
free(svr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-21 21:48:09 -07:00
|
|
|
/**
|
|
|
|
* Set the default time after which an inactive client will be disconnected
|
|
|
|
* @param svr The server object
|
|
|
|
* @param timeout The timeout, in seconds, to disconnect after
|
|
|
|
* This function is used to set the idle timeout on clients. A value of < 1
|
|
|
|
* disables the idle timeout.
|
|
|
|
*/
|
|
|
|
EAPI void
|
2010-11-03 10:58:37 -07:00
|
|
|
ecore_con_server_timeout_set(Ecore_Con_Server *svr,
|
|
|
|
double timeout)
|
2010-09-21 21:48:09 -07:00
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
|
|
|
|
{
|
|
|
|
ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_timeout_set");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
svr->client_disconnect_time = timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the default time after which an inactive client will be disconnected
|
|
|
|
* @param svr The server object
|
|
|
|
* @return The timeout, in seconds, to disconnect after
|
|
|
|
* This function is used to get the idle timeout for clients. A value of < 1
|
|
|
|
* means the idle timeout is disabled.
|
|
|
|
*/
|
|
|
|
EAPI double
|
|
|
|
ecore_con_server_timeout_get(Ecore_Con_Server *svr)
|
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
|
|
|
|
{
|
|
|
|
ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_timeout_get");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return svr->client_disconnect_time;
|
|
|
|
}
|
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
/**
|
2004-07-15 06:43:15 -07:00
|
|
|
* Closes the connection and frees the given server.
|
2004-09-22 01:17:15 -07:00
|
|
|
* @param svr The given server.
|
|
|
|
* @return Data associated with the server when it was created.
|
2010-07-26 17:10:40 -07:00
|
|
|
* @see ecore_con_server_add, ecore_con_server_connect
|
2003-09-23 01:09:32 -07:00
|
|
|
*/
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI void *
|
2003-09-23 01:09:32 -07:00
|
|
|
ecore_con_server_del(Ecore_Con_Server *svr)
|
|
|
|
{
|
|
|
|
void *data;
|
|
|
|
|
|
|
|
if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_del");
|
|
|
|
return NULL;
|
2006-03-19 21:53:12 -08:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (svr->delete_me)
|
2010-11-03 10:58:37 -07:00
|
|
|
return NULL;
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
data = svr->data;
|
2006-03-19 21:59:21 -08:00
|
|
|
svr->data = NULL;
|
2010-09-17 23:30:13 -07:00
|
|
|
svr->delete_me = EINA_TRUE;
|
2006-03-19 21:53:12 -08:00
|
|
|
if (svr->event_count > 0)
|
2006-06-02 00:01:49 -07:00
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
if (svr->fd_handler)
|
|
|
|
{
|
|
|
|
ecore_main_fd_handler_del(svr->fd_handler);
|
|
|
|
svr->fd_handler = NULL;
|
|
|
|
}
|
2006-06-02 00:01:49 -07:00
|
|
|
}
|
2006-03-19 21:53:12 -08:00
|
|
|
else
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_server_free(svr);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-07-15 06:43:15 -07:00
|
|
|
* Retrieves the data associated with the given server.
|
2004-09-22 01:17:15 -07:00
|
|
|
* @param svr The given server.
|
|
|
|
* @return The associated data.
|
2003-09-23 01:09:32 -07:00
|
|
|
*/
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI void *
|
2003-09-23 01:09:32 -07:00
|
|
|
ecore_con_server_data_get(Ecore_Con_Server *svr)
|
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
ECORE_MAGIC_FAIL(svr,
|
|
|
|
ECORE_MAGIC_CON_SERVER,
|
|
|
|
"ecore_con_server_data_get");
|
|
|
|
return NULL;
|
2007-08-26 04:17:21 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
return svr->data;
|
|
|
|
}
|
|
|
|
|
2010-07-28 17:27:15 -07:00
|
|
|
/**
|
|
|
|
* Sets the data associated with the given server.
|
|
|
|
* @param svr The given server.
|
|
|
|
* @param data The data to associate with @p svr
|
|
|
|
* @return The previously associated data, if any.
|
|
|
|
*/
|
|
|
|
EAPI void *
|
2010-11-03 10:58:37 -07:00
|
|
|
ecore_con_server_data_set(Ecore_Con_Server *svr,
|
|
|
|
void *data)
|
2010-07-28 17:27:15 -07:00
|
|
|
{
|
|
|
|
void *ret = NULL;
|
|
|
|
|
|
|
|
if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
|
|
|
|
{
|
|
|
|
ECORE_MAGIC_FAIL(svr,
|
|
|
|
ECORE_MAGIC_CON_SERVER,
|
|
|
|
"ecore_con_server_data_get");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = svr->data;
|
|
|
|
svr->data = data;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
/**
|
2004-07-15 06:43:15 -07:00
|
|
|
* Retrieves whether the given server is currently connected.
|
2004-09-22 01:17:15 -07:00
|
|
|
* @param svr The given server.
|
2010-09-20 18:48:46 -07:00
|
|
|
* @return #EINA_TRUE if the server is connected. #EINA_FALSE otherwise.
|
2003-09-23 01:09:32 -07:00
|
|
|
*/
|
2010-09-20 18:48:46 -07:00
|
|
|
EAPI Eina_Bool
|
2003-09-23 01:09:32 -07:00
|
|
|
ecore_con_server_connected_get(Ecore_Con_Server *svr)
|
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
|
|
|
|
"ecore_con_server_connected_get");
|
2010-09-20 18:48:46 -07:00
|
|
|
return EINA_FALSE;
|
2007-08-26 04:17:21 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (svr->connecting)
|
2010-11-03 10:58:37 -07:00
|
|
|
return EINA_FALSE;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-09-20 18:48:46 -07:00
|
|
|
return EINA_TRUE;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2006-03-29 22:48:45 -08:00
|
|
|
/**
|
|
|
|
* Retrieves the current list of clients.
|
|
|
|
* @param svr The given server.
|
|
|
|
* @return The list of clients on this server.
|
|
|
|
*/
|
2008-12-11 05:55:47 -08:00
|
|
|
EAPI Eina_List *
|
2006-03-29 22:48:45 -08:00
|
|
|
ecore_con_server_clients_get(Ecore_Con_Server *svr)
|
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
|
|
|
|
"ecore_con_server_clients_get");
|
|
|
|
return NULL;
|
2007-08-26 04:17:21 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2006-03-29 22:48:45 -08:00
|
|
|
return svr->clients;
|
|
|
|
}
|
|
|
|
|
2010-08-26 22:16:00 -07:00
|
|
|
/**
|
|
|
|
* Retrieves the name of server.
|
|
|
|
* @param svr The given server.
|
|
|
|
* @return The name of the server.
|
|
|
|
*/
|
|
|
|
EAPI const char *
|
|
|
|
ecore_con_server_name_get(Ecore_Con_Server *svr)
|
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
|
|
|
|
{
|
|
|
|
ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
|
|
|
|
"ecore_con_server_name_get");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return svr->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the server port in use.
|
|
|
|
* @param svr The given server.
|
|
|
|
* @return The server port in use.
|
|
|
|
*/
|
|
|
|
EAPI int
|
|
|
|
ecore_con_server_port_get(Ecore_Con_Server *svr)
|
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
|
|
|
|
{
|
|
|
|
ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
|
|
|
|
"ecore_con_server_port_get");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return svr->port;
|
|
|
|
}
|
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
/**
|
2004-07-15 06:43:15 -07:00
|
|
|
* Sends the given data to the given server.
|
2004-09-22 01:17:15 -07:00
|
|
|
* @param svr The given server.
|
|
|
|
* @param data The given data.
|
|
|
|
* @param size Length of the data, in bytes, to send.
|
|
|
|
* @return The number of bytes sent. @c 0 will be returned if there is an
|
|
|
|
* error.
|
2003-09-23 01:09:32 -07:00
|
|
|
*/
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI int
|
2010-09-20 23:49:07 -07:00
|
|
|
ecore_con_server_send(Ecore_Con_Server *svr,
|
2010-11-03 10:58:37 -07:00
|
|
|
const void *data,
|
|
|
|
int size)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_send");
|
|
|
|
return 0;
|
2007-08-26 04:17:21 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-11-03 09:11:12 -07:00
|
|
|
EINA_SAFETY_ON_TRUE_RETURN_VAL(svr->dead, 0);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-11-03 09:11:12 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(data, 0);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-11-03 09:11:12 -07:00
|
|
|
EINA_SAFETY_ON_TRUE_RETURN_VAL(size < 1, 0);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2005-09-22 22:46:56 -07:00
|
|
|
if (svr->fd_handler)
|
2010-11-03 10:58:37 -07:00
|
|
|
ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2004-04-03 07:03:33 -08:00
|
|
|
if (svr->write_buf)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
unsigned char *newbuf;
|
|
|
|
|
|
|
|
newbuf = realloc(svr->write_buf, svr->write_buf_size + size);
|
2010-11-03 09:11:12 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(newbuf, 0);
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2010-11-03 09:11:12 -07:00
|
|
|
svr->write_buf = newbuf;
|
2010-07-26 23:30:27 -07:00
|
|
|
memcpy(svr->write_buf + svr->write_buf_size, data, size);
|
|
|
|
svr->write_buf_size += size;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
svr->write_buf = malloc(size);
|
2010-11-03 09:11:12 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(svr->write_buf, 0);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
svr->write_buf_size = size;
|
|
|
|
memcpy(svr->write_buf, data, size);
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2004-04-23 00:24:40 -07:00
|
|
|
return size;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
2004-09-22 01:17:15 -07:00
|
|
|
|
2005-04-28 21:51:31 -07:00
|
|
|
/**
|
|
|
|
* Sets a limit on the number of clients that can be handled concurrently
|
|
|
|
* by the given server, and a policy on what to do if excess clients try to
|
|
|
|
* connect.
|
|
|
|
* Beware that if you set this once ecore is already running, you may
|
|
|
|
* already have pending CLIENT_ADD events in your event queue. Those
|
|
|
|
* clients have already connected and will not be affected by this call.
|
|
|
|
* Only clients subsequently trying to connect will be affected.
|
|
|
|
* @param svr The given server.
|
|
|
|
* @param client_limit The maximum number of clients to handle
|
2007-08-26 04:17:21 -07:00
|
|
|
* concurrently. -1 means unlimited (default). 0
|
2005-04-28 21:51:31 -07:00
|
|
|
* effectively disables the server.
|
|
|
|
* @param reject_excess_clients Set to 1 to automatically disconnect
|
|
|
|
* excess clients as soon as they connect if you are
|
|
|
|
* already handling client_limit clients. Set to 0
|
|
|
|
* (default) to just hold off on the "accept()"
|
|
|
|
* system call until the number of active clients
|
|
|
|
* drops. This causes the kernel to queue up to 4096
|
|
|
|
* connections (or your kernel's limit, whichever is
|
|
|
|
* lower).
|
|
|
|
*/
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI void
|
2010-09-20 23:49:07 -07:00
|
|
|
ecore_con_server_client_limit_set(Ecore_Con_Server *svr,
|
2010-11-03 10:58:37 -07:00
|
|
|
int client_limit,
|
|
|
|
char reject_excess_clients)
|
2005-04-28 21:51:31 -07:00
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
|
|
|
|
"ecore_con_server_client_limit_set");
|
|
|
|
return;
|
2007-08-26 04:17:21 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2005-04-28 21:51:31 -07:00
|
|
|
svr->client_limit = client_limit;
|
|
|
|
svr->reject_excess_clients = reject_excess_clients;
|
|
|
|
}
|
|
|
|
|
2006-03-19 23:45:58 -08:00
|
|
|
/**
|
|
|
|
* Gets the IP address of a server that has been connected to.
|
2007-08-26 04:17:21 -07:00
|
|
|
*
|
2006-03-19 23:45:58 -08:00
|
|
|
* @param svr The given server.
|
|
|
|
* @return A pointer to an internal string that contains the IP address of
|
|
|
|
* the connected server in the form "XXX.YYY.ZZZ.AAA" IP notation.
|
|
|
|
* This string should not be modified or trusted to stay valid after
|
|
|
|
* deletion for the @p svr object. If no IP is known NULL is returned.
|
|
|
|
*/
|
2010-07-28 15:32:39 -07:00
|
|
|
EAPI const char *
|
2006-03-19 23:45:58 -08:00
|
|
|
ecore_con_server_ip_get(Ecore_Con_Server *svr)
|
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_ip_get");
|
|
|
|
return NULL;
|
2006-03-19 23:45:58 -08:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2006-03-19 23:45:58 -08:00
|
|
|
return svr->ip;
|
|
|
|
}
|
|
|
|
|
2010-09-21 21:48:09 -07:00
|
|
|
/**
|
|
|
|
* @brief Check how long a server has been connected
|
|
|
|
* @param svr The server to check
|
|
|
|
* @return The total time, in seconds, that the server has been connected/running
|
|
|
|
* This function is used to find out how long a server has been connected/running for.
|
|
|
|
*/
|
|
|
|
EAPI double
|
|
|
|
ecore_con_server_uptime_get(Ecore_Con_Server *svr)
|
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
|
|
|
|
{
|
|
|
|
ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_uptime_get");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ecore_time_get() - svr->start_time;
|
|
|
|
}
|
2010-11-03 10:58:37 -07:00
|
|
|
|
2007-02-16 10:12:38 -08:00
|
|
|
/**
|
|
|
|
* Flushes all pending data to the given server. Will return when done.
|
2007-08-26 04:17:21 -07:00
|
|
|
*
|
2007-02-16 10:12:38 -08:00
|
|
|
* @param svr The given server.
|
|
|
|
*/
|
|
|
|
EAPI void
|
|
|
|
ecore_con_server_flush(Ecore_Con_Server *svr)
|
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER, "ecore_con_server_flush");
|
|
|
|
return;
|
2007-02-16 10:12:38 -08:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2007-02-16 10:12:38 -08:00
|
|
|
_ecore_con_server_flush(svr);
|
|
|
|
}
|
|
|
|
|
2010-07-28 17:27:15 -07:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup Ecore_Con_Client_Group Ecore Connection Client Functions
|
2004-09-22 01:17:15 -07:00
|
|
|
*
|
|
|
|
* Functions that operate on Ecore connection client objects.
|
2010-09-20 23:49:07 -07:00
|
|
|
*
|
2010-07-28 17:27:15 -07:00
|
|
|
* @{
|
2004-09-22 01:17:15 -07:00
|
|
|
*/
|
|
|
|
|
2010-09-20 23:49:07 -07:00
|
|
|
/**
|
|
|
|
* @example ecore_con_client_example.c
|
|
|
|
* Shows how to write a simple client that connects to the example server.
|
2010-11-03 10:58:37 -07:00
|
|
|
*/
|
2010-09-20 23:49:07 -07:00
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
/**
|
2004-07-15 06:43:15 -07:00
|
|
|
* Sends the given data to the given client.
|
2004-09-22 01:17:15 -07:00
|
|
|
* @param cl The given client.
|
|
|
|
* @param data The given data.
|
|
|
|
* @param size Length of the data, in bytes, to send.
|
|
|
|
* @return The number of bytes sent. @c 0 will be returned if there is an
|
|
|
|
* error.
|
2003-09-23 01:09:32 -07:00
|
|
|
*/
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI int
|
2010-09-20 23:49:07 -07:00
|
|
|
ecore_con_client_send(Ecore_Con_Client *cl,
|
2010-11-03 10:58:37 -07:00
|
|
|
const void *data,
|
|
|
|
int size)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_send");
|
|
|
|
return 0;
|
2007-08-26 04:17:21 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-11-03 09:11:12 -07:00
|
|
|
EINA_SAFETY_ON_TRUE_RETURN_VAL(cl->dead, 0);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-11-03 09:11:12 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(data, 0);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-11-03 09:11:12 -07:00
|
|
|
EINA_SAFETY_ON_TRUE_RETURN_VAL(size < 1, 0);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2005-09-22 22:46:56 -07:00
|
|
|
if (cl->fd_handler)
|
2010-11-03 10:58:37 -07:00
|
|
|
ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE);
|
2008-10-09 05:30:19 -07:00
|
|
|
|
2010-09-18 12:26:05 -07:00
|
|
|
if(cl->host_server && ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP))
|
2010-11-03 10:58:37 -07:00
|
|
|
sendto(cl->host_server->fd, data, size, 0, (struct sockaddr *)cl->client_addr,
|
|
|
|
cl->client_addr_len);
|
2008-10-09 05:30:19 -07:00
|
|
|
else if (cl->buf)
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
unsigned char *newbuf;
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
newbuf = realloc(cl->buf, cl->buf_size + size);
|
2010-11-03 09:11:12 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(newbuf, 0);
|
|
|
|
|
|
|
|
cl->buf = newbuf;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
memcpy(cl->buf + cl->buf_size, data, size);
|
|
|
|
cl->buf_size += size;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
cl->buf = malloc(size);
|
2010-11-03 09:11:12 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(cl->buf, 0);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
cl->buf_size = size;
|
|
|
|
memcpy(cl->buf, data, size);
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2004-04-23 00:24:40 -07:00
|
|
|
return size;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
/**
|
2004-07-15 06:43:15 -07:00
|
|
|
* Retrieves the server representing the socket the client has
|
|
|
|
* connected to.
|
2007-08-26 04:17:21 -07:00
|
|
|
* @param cl The given client.
|
2004-09-22 01:17:15 -07:00
|
|
|
* @return The server that the client connected to.
|
2003-09-23 01:09:32 -07:00
|
|
|
*/
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI Ecore_Con_Server *
|
2003-09-23 01:09:32 -07:00
|
|
|
ecore_con_client_server_get(Ecore_Con_Client *cl)
|
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
|
|
|
|
"ecore_con_client_server_get");
|
|
|
|
return NULL;
|
2007-08-26 04:17:21 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-09-18 12:26:05 -07:00
|
|
|
return cl->host_server;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2010-11-05 17:17:04 -07:00
|
|
|
/**
|
|
|
|
* Returns whether the client is still connected
|
|
|
|
* @param cl The given client.
|
|
|
|
* @return #EINA_TRUE if connected, else EINA_FALSE
|
|
|
|
*/
|
|
|
|
EAPI Eina_Bool
|
|
|
|
ecore_con_client_connected_get(Ecore_Con_Client *cl)
|
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
|
|
|
|
{
|
|
|
|
ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
|
|
|
|
"ecore_con_client_connected_get");
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !cl->dead;
|
|
|
|
}
|
|
|
|
|
2010-09-21 21:48:09 -07:00
|
|
|
/**
|
|
|
|
* Set the time after which the client will be disconnected when inactive
|
|
|
|
* @param cl The client object
|
|
|
|
* @param timeout The timeout, in seconds, to disconnect after
|
|
|
|
* This function is used to set the idle timeout on a client. A value of < 1
|
|
|
|
* disables the idle timeout.
|
|
|
|
*/
|
|
|
|
EAPI void
|
2010-11-03 10:58:37 -07:00
|
|
|
ecore_con_client_timeout_set(Ecore_Con_Client *cl,
|
|
|
|
double timeout)
|
2010-09-21 21:48:09 -07:00
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
|
|
|
|
{
|
|
|
|
ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT,
|
|
|
|
"ecore_con_client_timeout_set");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cl->disconnect_time = timeout;
|
|
|
|
|
|
|
|
_ecore_con_cl_timer_update(cl);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the default time after which the client will be disconnected when inactive
|
|
|
|
* @param cl The client object
|
|
|
|
* @return The timeout, in seconds, to disconnect after
|
|
|
|
* This function is used to get the idle timeout for a client. A value of < 1
|
|
|
|
* means the idle timeout is disabled.
|
|
|
|
*/
|
|
|
|
EAPI double
|
|
|
|
ecore_con_client_timeout_get(Ecore_Con_Client *cl)
|
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
|
|
|
|
{
|
|
|
|
ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_timeout_get");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cl->disconnect_time;
|
|
|
|
}
|
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
/**
|
2004-07-15 06:43:15 -07:00
|
|
|
* Closes the connection and frees memory allocated to the given client.
|
2004-09-22 01:17:15 -07:00
|
|
|
* @param cl The given client.
|
|
|
|
* @return Data associated with the client.
|
2003-09-23 01:09:32 -07:00
|
|
|
*/
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI void *
|
2003-09-23 01:09:32 -07:00
|
|
|
ecore_con_client_del(Ecore_Con_Client *cl)
|
|
|
|
{
|
2008-10-09 05:30:19 -07:00
|
|
|
void *data = NULL;
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_del");
|
|
|
|
return NULL;
|
2007-08-26 04:17:21 -07:00
|
|
|
}
|
2008-10-09 05:30:19 -07:00
|
|
|
|
2010-09-18 12:26:05 -07:00
|
|
|
if (cl->client_addr && cl->host_server &&
|
2010-11-03 10:58:37 -07:00
|
|
|
(((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP) ||
|
|
|
|
((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_MCAST)))
|
|
|
|
free(cl->client_addr);
|
2009-11-27 06:36:43 -08:00
|
|
|
|
|
|
|
data = cl->data;
|
2008-10-09 05:30:19 -07:00
|
|
|
|
2006-03-19 21:59:21 -08:00
|
|
|
cl->data = NULL;
|
2010-09-17 23:30:13 -07:00
|
|
|
cl->delete_me = EINA_TRUE;
|
2006-03-19 21:53:12 -08:00
|
|
|
if (cl->event_count > 0)
|
2006-06-02 00:01:49 -07:00
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
if (cl->fd_handler)
|
|
|
|
{
|
|
|
|
ecore_main_fd_handler_del(cl->fd_handler);
|
|
|
|
cl->fd_handler = NULL;
|
|
|
|
}
|
2006-06-02 00:01:49 -07:00
|
|
|
}
|
2006-03-19 21:53:12 -08:00
|
|
|
else
|
|
|
|
{
|
2010-09-18 12:26:05 -07:00
|
|
|
if (cl->host_server)
|
2010-09-20 12:31:11 -07:00
|
|
|
{
|
|
|
|
cl->host_server->clients = eina_list_remove(cl->host_server->clients, cl);
|
2010-09-23 22:57:03 -07:00
|
|
|
--cl->host_server->client_count;
|
2010-09-20 12:31:11 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
_ecore_con_client_free(cl);
|
2006-03-19 21:53:12 -08:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2003-11-19 15:05:08 -08:00
|
|
|
return data;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-07-15 06:43:15 -07:00
|
|
|
* Sets the data associated with the given client to @p data.
|
2004-09-22 01:17:15 -07:00
|
|
|
* @param cl The given client.
|
|
|
|
* @param data What to set the data to.
|
2003-09-23 01:09:32 -07:00
|
|
|
*/
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI void
|
2010-11-03 10:58:37 -07:00
|
|
|
ecore_con_client_data_set(Ecore_Con_Client *cl,
|
|
|
|
const void *data)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
ECORE_MAGIC_FAIL(cl,
|
|
|
|
ECORE_MAGIC_CON_CLIENT,
|
|
|
|
"ecore_con_client_data_set");
|
|
|
|
return;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
cl->data = (void *)data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-07-15 06:43:15 -07:00
|
|
|
* Retrieves the data associated with the given client.
|
2004-09-22 01:17:15 -07:00
|
|
|
* @param cl The given client.
|
|
|
|
* @return The data associated with @p cl.
|
2003-09-23 01:09:32 -07:00
|
|
|
*/
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI void *
|
2003-09-23 01:09:32 -07:00
|
|
|
ecore_con_client_data_get(Ecore_Con_Client *cl)
|
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
ECORE_MAGIC_FAIL(cl,
|
|
|
|
ECORE_MAGIC_CON_CLIENT,
|
|
|
|
"ecore_con_client_data_get");
|
|
|
|
return NULL;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
return cl->data;
|
|
|
|
}
|
|
|
|
|
2006-03-19 23:45:58 -08:00
|
|
|
/**
|
|
|
|
* Gets the IP address of a cleint that has connected.
|
2007-08-26 04:17:21 -07:00
|
|
|
*
|
2006-03-19 23:45:58 -08:00
|
|
|
* @param cl The given client.
|
|
|
|
* @return A pointer to an internal string that contains the IP address of
|
|
|
|
* the connected client in the form "XXX.YYY.ZZZ.AAA" IP notation.
|
|
|
|
* This string should not be modified or trusted to stay valid after
|
|
|
|
* deletion for the @p cl object. If no IP is known NULL is returned.
|
|
|
|
*/
|
2010-07-28 15:32:39 -07:00
|
|
|
EAPI const char *
|
2006-03-19 23:45:58 -08:00
|
|
|
ecore_con_client_ip_get(Ecore_Con_Client *cl)
|
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_ip_get");
|
|
|
|
return NULL;
|
2006-03-19 23:45:58 -08:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2006-03-19 23:45:58 -08:00
|
|
|
return cl->ip;
|
|
|
|
}
|
|
|
|
|
2010-09-21 21:48:09 -07:00
|
|
|
/**
|
|
|
|
* @brief Check how long a client has been connected
|
|
|
|
* @param cl The client to check
|
|
|
|
* @return The total time, in seconds, that the client has been connected to the server
|
|
|
|
* This function is used to find out how long a client has been connected for.
|
|
|
|
*/
|
|
|
|
EAPI double
|
|
|
|
ecore_con_client_uptime_get(Ecore_Con_Client *cl)
|
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
|
|
|
|
{
|
|
|
|
ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_uptime_get");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ecore_time_get() - cl->start_time;
|
|
|
|
}
|
|
|
|
|
2007-02-16 10:12:38 -08:00
|
|
|
/**
|
|
|
|
* Flushes all pending data to the given client. Will return when done.
|
2007-08-26 04:17:21 -07:00
|
|
|
*
|
2007-02-16 10:12:38 -08:00
|
|
|
* @param cl The given client.
|
|
|
|
*/
|
|
|
|
EAPI void
|
|
|
|
ecore_con_client_flush(Ecore_Con_Client *cl)
|
|
|
|
{
|
|
|
|
if (!ECORE_MAGIC_CHECK(cl, ECORE_MAGIC_CON_CLIENT))
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
ECORE_MAGIC_FAIL(cl, ECORE_MAGIC_CON_CLIENT, "ecore_con_client_flush");
|
|
|
|
return;
|
2007-02-16 10:12:38 -08:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2007-02-16 10:12:38 -08:00
|
|
|
_ecore_con_client_flush(cl);
|
|
|
|
}
|
|
|
|
|
2010-07-28 17:27:15 -07:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
static void
|
|
|
|
_ecore_con_server_free(Ecore_Con_Server *svr)
|
|
|
|
{
|
2008-12-11 05:55:47 -08:00
|
|
|
Ecore_Con_Client *cl;
|
2006-05-18 20:52:24 -07:00
|
|
|
double t_start, t;
|
2007-08-26 04:17:21 -07:00
|
|
|
|
|
|
|
ECORE_MAGIC_SET(svr, ECORE_MAGIC_NONE);
|
2006-05-18 20:52:24 -07:00
|
|
|
t_start = ecore_time_get();
|
|
|
|
while ((svr->write_buf) && (!svr->dead))
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
_ecore_con_server_flush(svr);
|
|
|
|
t = ecore_time_get();
|
|
|
|
if ((t - t_start) > 0.5)
|
|
|
|
{
|
|
|
|
WRN("ECORE_CON: EEK - stuck in _ecore_con_server_free() trying\n"
|
|
|
|
" to flush data out from the server, and have been for\n"
|
|
|
|
" %1.1f seconds. This is taking too long. Aborting flush.",
|
|
|
|
(t - t_start));
|
|
|
|
break;
|
|
|
|
}
|
2006-05-18 20:52:24 -07:00
|
|
|
}
|
2010-09-21 21:48:09 -07:00
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
if (svr->write_buf)
|
2010-11-03 10:58:37 -07:00
|
|
|
free(svr->write_buf);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
EINA_LIST_FREE(svr->clients, cl)
|
2010-09-21 21:48:09 -07:00
|
|
|
_ecore_con_client_free(cl);
|
2008-10-09 05:30:19 -07:00
|
|
|
if ((svr->created) && (svr->path) && (svr->ppid == getpid()))
|
2010-11-03 10:58:37 -07:00
|
|
|
unlink(svr->path);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-09-21 21:48:09 -07:00
|
|
|
ecore_con_ssl_server_shutdown(svr);
|
2010-07-26 23:30:27 -07:00
|
|
|
if (svr->fd >= 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
close(svr->fd);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (svr->name)
|
2010-11-03 10:58:37 -07:00
|
|
|
free(svr->name);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (svr->path)
|
2010-11-03 10:58:37 -07:00
|
|
|
free(svr->path);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (svr->ip)
|
2010-11-03 10:58:37 -07:00
|
|
|
free(svr->ip);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (svr->fd_handler)
|
2010-11-03 10:58:37 -07:00
|
|
|
ecore_main_fd_handler_del(svr->fd_handler);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
servers = eina_list_remove(servers, svr);
|
2003-09-23 01:09:32 -07:00
|
|
|
free(svr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ecore_con_client_free(Ecore_Con_Client *cl)
|
|
|
|
{
|
2006-05-18 20:52:24 -07:00
|
|
|
double t_start, t;
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2010-09-23 22:57:03 -07:00
|
|
|
if ((!cl->buf) && cl->delete_me && (!cl->dead) && (cl->event_count < 1))
|
2010-09-20 12:32:37 -07:00
|
|
|
{
|
2010-11-03 10:58:37 -07:00
|
|
|
/* this is a catch-all for cases when a client is not properly killed.
|
|
|
|
* the only example case I've found so far is if a client ssl handshakes
|
|
|
|
* and then immediately disconnects without sending any further data.
|
|
|
|
*/
|
2010-09-22 01:03:38 -07:00
|
|
|
|
2010-11-03 10:58:37 -07:00
|
|
|
/* we lost our client! */
|
|
|
|
Ecore_Con_Event_Client_Del *e;
|
2010-09-20 12:32:37 -07:00
|
|
|
|
2010-11-03 10:58:37 -07:00
|
|
|
cl->dead = EINA_TRUE;
|
2010-11-05 16:48:15 -07:00
|
|
|
INF("Lost client %s", cl->ip);
|
2010-11-03 10:58:37 -07:00
|
|
|
e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
|
2010-11-03 12:08:31 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
|
|
|
cl->event_count++;
|
|
|
|
_ecore_con_cl_timer_update(cl);
|
|
|
|
e->client = cl;
|
|
|
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
|
|
|
|
_ecore_con_event_client_del_free, NULL);
|
|
|
|
return;
|
2010-09-20 12:32:37 -07:00
|
|
|
}
|
|
|
|
|
2007-08-26 04:17:21 -07:00
|
|
|
ECORE_MAGIC_SET(cl, ECORE_MAGIC_NONE);
|
2006-05-18 20:52:24 -07:00
|
|
|
t_start = ecore_time_get();
|
|
|
|
while ((cl->buf) && (!cl->dead))
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
_ecore_con_client_flush(cl);
|
|
|
|
t = ecore_time_get();
|
|
|
|
if ((t - t_start) > 0.5)
|
|
|
|
{
|
|
|
|
WRN("EEK - stuck in _ecore_con_client_free() trying\n"
|
|
|
|
" to flush data out from the client, and have been for\n"
|
|
|
|
" %1.1f seconds. This is taking too long. Aborting flush.",
|
|
|
|
(t - t_start));
|
|
|
|
break;
|
|
|
|
}
|
2006-05-18 20:52:24 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
if (cl->buf)
|
2010-11-03 10:58:37 -07:00
|
|
|
free(cl->buf);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-10-15 00:42:29 -07:00
|
|
|
if (cl->host_server->type & ECORE_CON_SSL)
|
2010-09-21 21:48:09 -07:00
|
|
|
ecore_con_ssl_client_shutdown(cl);
|
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
if (cl->fd >= 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
close(cl->fd);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (cl->fd_handler)
|
2010-11-03 10:58:37 -07:00
|
|
|
ecore_main_fd_handler_del(cl->fd_handler);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (cl->ip)
|
2010-11-03 10:58:37 -07:00
|
|
|
free(cl->ip);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-11-03 10:58:37 -07:00
|
|
|
free(cl);
|
2010-09-23 22:57:03 -07:00
|
|
|
return;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2004-04-25 08:42:57 -07:00
|
|
|
static void
|
2010-09-23 21:15:42 -07:00
|
|
|
_ecore_con_server_kill(Ecore_Con_Server *svr)
|
2004-04-25 08:42:57 -07:00
|
|
|
{
|
2006-06-02 00:24:04 -07:00
|
|
|
if (!svr->delete_me)
|
2005-03-03 00:54:09 -08:00
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
Ecore_Con_Event_Server_Del *e;
|
|
|
|
|
|
|
|
e = calloc(1, sizeof(Ecore_Con_Event_Server_Del));
|
2010-11-03 12:08:31 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
|
|
|
svr->event_count++;
|
|
|
|
e->server = svr;
|
|
|
|
ecore_event_add(ECORE_CON_EVENT_SERVER_DEL, e,
|
|
|
|
_ecore_con_event_server_del_free, NULL);
|
2005-03-03 00:54:09 -08:00
|
|
|
}
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2010-09-17 23:30:13 -07:00
|
|
|
svr->dead = EINA_TRUE;
|
2010-07-26 23:30:27 -07:00
|
|
|
if (svr->fd_handler)
|
2010-11-03 10:58:37 -07:00
|
|
|
ecore_main_fd_handler_del(svr->fd_handler);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2004-04-25 08:42:57 -07:00
|
|
|
svr->fd_handler = NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-21 21:48:09 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_ecore_con_client_timer(Ecore_Con_Client *cl)
|
|
|
|
{
|
|
|
|
ecore_con_client_del(cl);
|
|
|
|
|
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ecore_con_cl_timer_update(Ecore_Con_Client *cl)
|
|
|
|
{
|
|
|
|
if (cl->disconnect_time)
|
|
|
|
{
|
|
|
|
if (cl->disconnect_time > 0)
|
|
|
|
{
|
|
|
|
if (cl->until_deletion)
|
|
|
|
ecore_timer_interval_set(cl->until_deletion, cl->disconnect_time);
|
|
|
|
else
|
|
|
|
cl->until_deletion = ecore_timer_add(cl->disconnect_time, (Ecore_Task_Cb)_ecore_con_client_timer, cl);
|
|
|
|
}
|
|
|
|
else if (cl->until_deletion)
|
|
|
|
{
|
|
|
|
ecore_timer_del(cl->until_deletion);
|
|
|
|
cl->until_deletion = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (cl->host_server->client_disconnect_time > 0)
|
|
|
|
{
|
|
|
|
if (cl->until_deletion)
|
|
|
|
ecore_timer_interval_set(cl->until_deletion, cl->host_server->client_disconnect_time);
|
|
|
|
else
|
|
|
|
cl->until_deletion = ecore_timer_add(cl->host_server->client_disconnect_time, (Ecore_Task_Cb)_ecore_con_client_timer, cl);
|
|
|
|
}
|
|
|
|
else if (cl->until_deletion)
|
|
|
|
{
|
|
|
|
ecore_timer_del(cl->until_deletion);
|
|
|
|
cl->until_deletion = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-06 02:41:39 -07:00
|
|
|
static void
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_cb_tcp_listen(void *data,
|
|
|
|
Ecore_Con_Info *net_info)
|
2008-10-09 05:30:19 -07:00
|
|
|
{
|
|
|
|
Ecore_Con_Server *svr;
|
|
|
|
struct linger lin;
|
|
|
|
|
|
|
|
svr = data;
|
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
if(!net_info)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
|
|
|
|
net_info->info.ai_protocol);
|
|
|
|
if (svr->fd < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2008-10-09 05:30:19 -07:00
|
|
|
|
|
|
|
lin.l_onoff = 1;
|
|
|
|
lin.l_linger = 0;
|
2010-07-26 23:30:27 -07:00
|
|
|
if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, (const void *)&lin,
|
|
|
|
sizeof(struct linger)) < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-07-30 10:03:34 -07:00
|
|
|
if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY)
|
2009-11-20 02:58:19 -08:00
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
int flag = 1;
|
2009-11-20 02:58:19 -08:00
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag,
|
|
|
|
sizeof(int)) < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2009-11-20 02:58:19 -08:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (bind(svr->fd, net_info->info.ai_addr,
|
|
|
|
net_info->info.ai_addrlen) < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (listen(svr->fd, 4096) < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-09-17 23:06:05 -07:00
|
|
|
svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_svr_tcp_handler, svr, NULL, NULL);
|
2010-07-26 23:30:27 -07:00
|
|
|
if (!svr->fd_handler)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2008-10-09 05:30:19 -07:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
error:
|
2008-10-30 08:26:11 -07:00
|
|
|
ecore_con_ssl_server_shutdown(svr);
|
2010-09-23 21:15:42 -07:00
|
|
|
_ecore_con_server_kill(svr);
|
2008-10-09 05:30:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_cb_udp_listen(void *data,
|
|
|
|
Ecore_Con_Info *net_info)
|
2008-10-09 05:30:19 -07:00
|
|
|
{
|
|
|
|
Ecore_Con_Server *svr;
|
|
|
|
Ecore_Con_Type type;
|
|
|
|
struct ip_mreq mreq;
|
|
|
|
struct ipv6_mreq mreq6;
|
|
|
|
const int on = 1;
|
|
|
|
|
|
|
|
svr = data;
|
|
|
|
type = svr->type;
|
|
|
|
type &= ECORE_CON_TYPE;
|
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
if (!net_info)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2008-10-09 05:30:19 -07:00
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
|
|
|
|
net_info->info.ai_protocol);
|
|
|
|
if(svr->fd < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2008-10-09 05:30:19 -07:00
|
|
|
|
|
|
|
if (type == ECORE_CON_REMOTE_MCAST)
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
if (net_info->info.ai_family == AF_INET)
|
|
|
|
{
|
|
|
|
if (!inet_pton(net_info->info.ai_family, net_info->ip,
|
|
|
|
&mreq.imr_multiaddr))
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
|
|
|
|
if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
|
2010-11-03 10:58:37 -07:00
|
|
|
(const void *)&mreq, sizeof(mreq)) != 0)
|
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
}
|
|
|
|
else if (net_info->info.ai_family == AF_INET6)
|
|
|
|
{
|
|
|
|
if (!inet_pton(net_info->info.ai_family, net_info->ip,
|
|
|
|
&mreq6.ipv6mr_multiaddr))
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
mreq6.ipv6mr_interface = htonl(INADDR_ANY);
|
|
|
|
if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
|
2010-11-03 10:58:37 -07:00
|
|
|
(const void *)&mreq6, sizeof(mreq6)) != 0)
|
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on,
|
|
|
|
sizeof(on)) != 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2008-10-09 05:30:19 -07:00
|
|
|
}
|
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (bind(svr->fd, net_info->info.ai_addr,
|
|
|
|
net_info->info.ai_addrlen) < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2008-10-09 05:30:19 -07:00
|
|
|
svr->fd_handler =
|
2010-11-03 10:58:37 -07:00
|
|
|
ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
|
|
|
|
_ecore_con_svr_udp_handler, svr, NULL, NULL);
|
2010-07-26 23:30:27 -07:00
|
|
|
if (!svr->fd_handler)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2008-10-09 05:30:19 -07:00
|
|
|
svr->ip = strdup(net_info->ip);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
error:
|
2008-10-30 08:26:11 -07:00
|
|
|
ecore_con_ssl_server_shutdown(svr);
|
2010-09-23 21:15:42 -07:00
|
|
|
_ecore_con_server_kill(svr);
|
2008-10-09 05:30:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_cb_tcp_connect(void *data,
|
|
|
|
Ecore_Con_Info *net_info)
|
2008-10-06 02:41:39 -07:00
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
Ecore_Con_Server *svr;
|
|
|
|
int res;
|
|
|
|
int curstate = 0;
|
2008-10-06 02:41:39 -07:00
|
|
|
|
|
|
|
svr = data;
|
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
if (!net_info)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
|
|
|
|
net_info->info.ai_protocol);
|
|
|
|
if (svr->fd < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate,
|
|
|
|
sizeof(curstate)) < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-07-30 10:03:34 -07:00
|
|
|
if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY)
|
2009-11-20 02:58:19 -08:00
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
int flag = 1;
|
2009-11-20 02:58:19 -08:00
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag,
|
|
|
|
sizeof(int)) < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2009-11-20 02:58:19 -08:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-02-20 10:01:50 -08:00
|
|
|
res = connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen);
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (res == SOCKET_ERROR)
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
if (WSAGetLastError() != WSAEINPROGRESS)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-02-20 10:01:50 -08:00
|
|
|
#else
|
|
|
|
if (res < 0)
|
2008-10-06 02:41:39 -07:00
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
if (errno != EINPROGRESS)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-02-20 10:01:50 -08:00
|
|
|
#endif
|
2010-09-17 23:30:13 -07:00
|
|
|
svr->connecting = EINA_TRUE;
|
2010-07-26 23:30:27 -07:00
|
|
|
svr->fd_handler =
|
2010-11-03 10:58:37 -07:00
|
|
|
ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE,
|
|
|
|
_ecore_con_cl_handler, svr, NULL, NULL);
|
2008-10-06 02:41:39 -07:00
|
|
|
}
|
|
|
|
else
|
2010-11-03 10:58:37 -07:00
|
|
|
svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
|
|
|
|
_ecore_con_cl_handler, svr, NULL, NULL);
|
2008-10-30 08:26:11 -07:00
|
|
|
|
2010-10-15 00:42:29 -07:00
|
|
|
if (svr->type & ECORE_CON_SSL)
|
2010-09-23 21:15:42 -07:00
|
|
|
{
|
|
|
|
svr->handshaking = EINA_TRUE;
|
|
|
|
svr->ssl_state = ECORE_CON_SSL_STATE_INIT;
|
2010-09-28 20:52:32 -07:00
|
|
|
DBG("beginning ssl handshake");
|
2010-09-23 21:15:42 -07:00
|
|
|
if (ecore_con_ssl_server_init(svr))
|
|
|
|
goto error;
|
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (!svr->fd_handler)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2008-10-06 02:41:39 -07:00
|
|
|
|
2008-10-09 05:30:19 -07:00
|
|
|
svr->ip = strdup(net_info->ip);
|
2008-10-08 17:46:29 -07:00
|
|
|
|
2008-10-06 02:41:39 -07:00
|
|
|
return;
|
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
error:
|
2008-10-30 08:26:11 -07:00
|
|
|
ecore_con_ssl_server_shutdown(svr);
|
2010-09-23 21:15:42 -07:00
|
|
|
_ecore_con_server_kill(svr);
|
2008-10-06 02:41:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_cb_udp_connect(void *data,
|
|
|
|
Ecore_Con_Info *net_info)
|
2008-10-06 02:41:39 -07:00
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
Ecore_Con_Server *svr;
|
|
|
|
int curstate = 0;
|
|
|
|
int broadcast = 1;
|
2008-10-06 02:41:39 -07:00
|
|
|
svr = data;
|
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
if (!net_info)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
|
|
|
|
net_info->info.ai_protocol);
|
|
|
|
if (svr->fd < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2009-08-12 04:24:33 -07:00
|
|
|
|
2010-07-30 10:03:34 -07:00
|
|
|
if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_BROADCAST)
|
2009-08-12 04:24:33 -07:00
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
if (setsockopt(svr->fd, SOL_SOCKET, SO_BROADCAST,
|
|
|
|
(const void *)&broadcast,
|
|
|
|
sizeof(broadcast)) < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2009-08-12 04:24:33 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
else if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR,
|
2010-09-17 23:06:05 -07:00
|
|
|
(const void *)&curstate, sizeof(curstate)) < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-09-17 23:06:05 -07:00
|
|
|
if (connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-09-17 23:06:05 -07:00
|
|
|
|
|
|
|
svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE,
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_cl_udp_handler, svr, NULL, NULL);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (!svr->fd_handler)
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2009-08-12 04:24:33 -07:00
|
|
|
|
2008-10-09 05:30:19 -07:00
|
|
|
svr->ip = strdup(net_info->ip);
|
|
|
|
|
2008-10-06 02:41:39 -07:00
|
|
|
return;
|
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
error:
|
2008-10-30 08:26:11 -07:00
|
|
|
ecore_con_ssl_server_shutdown(svr);
|
2010-09-23 21:15:42 -07:00
|
|
|
_ecore_con_server_kill(svr);
|
2008-10-06 02:41:39 -07:00
|
|
|
}
|
|
|
|
|
2008-10-01 08:27:52 -07:00
|
|
|
static Ecore_Con_State
|
2004-05-09 13:23:23 -07:00
|
|
|
svr_try_connect_plain(Ecore_Con_Server *svr)
|
2004-04-03 07:03:33 -08:00
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
int res;
|
|
|
|
int so_err = 0;
|
2005-08-16 02:25:02 -07:00
|
|
|
unsigned int size = sizeof(int);
|
2004-04-03 07:03:33 -08:00
|
|
|
|
2010-02-20 10:01:50 -08:00
|
|
|
res = getsockopt(svr->fd, SOL_SOCKET, SO_ERROR, (void *)&so_err, &size);
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (res == SOCKET_ERROR)
|
2010-11-03 10:58:37 -07:00
|
|
|
so_err = -1;
|
2010-02-20 10:01:50 -08:00
|
|
|
|
|
|
|
if (so_err == WSAEINPROGRESS && !svr->dead)
|
2010-11-03 10:58:37 -07:00
|
|
|
return ECORE_CON_INPROGRESS;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-02-20 10:01:50 -08:00
|
|
|
#else
|
|
|
|
if (res < 0)
|
2010-11-03 10:58:37 -07:00
|
|
|
so_err = -1;
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2008-10-01 08:27:52 -07:00
|
|
|
if (so_err == EINPROGRESS && !svr->dead)
|
2010-11-03 10:58:37 -07:00
|
|
|
return ECORE_CON_INPROGRESS;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-02-20 10:01:50 -08:00
|
|
|
#endif
|
2008-10-01 08:27:52 -07:00
|
|
|
|
2004-04-14 01:51:19 -07:00
|
|
|
if (so_err != 0)
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
/* we lost our server! */
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_server_kill(svr);
|
|
|
|
return ECORE_CON_DISCONNECTED;
|
2004-04-14 01:51:19 -07:00
|
|
|
}
|
2010-09-17 23:06:05 -07:00
|
|
|
|
2010-09-23 22:57:03 -07:00
|
|
|
if ((!svr->delete_me) && (!svr->handshaking) && svr->connecting)
|
2004-04-14 01:51:19 -07:00
|
|
|
{
|
2010-09-17 23:06:05 -07:00
|
|
|
/* we got our server! */
|
2010-11-03 10:58:37 -07:00
|
|
|
Ecore_Con_Event_Server_Add *e;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-11-03 10:58:37 -07:00
|
|
|
svr->connecting = EINA_FALSE;
|
|
|
|
e = calloc(1, sizeof(Ecore_Con_Event_Server_Add));
|
2010-11-03 12:08:31 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, ECORE_CON_CONNECTED);
|
|
|
|
|
|
|
|
svr->event_count++;
|
|
|
|
svr->start_time = ecore_time_get();
|
|
|
|
e->server = svr;
|
|
|
|
ecore_event_add(ECORE_CON_EVENT_SERVER_ADD, e,
|
|
|
|
_ecore_con_event_server_add_free, NULL);
|
2004-04-14 01:51:19 -07:00
|
|
|
}
|
2008-10-01 08:27:52 -07:00
|
|
|
|
2010-09-17 23:06:05 -07:00
|
|
|
if (svr->fd_handler && (!svr->write_buf))
|
2010-11-03 10:58:37 -07:00
|
|
|
ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
|
2010-09-17 23:06:05 -07:00
|
|
|
|
2008-10-01 08:27:52 -07:00
|
|
|
if (!svr->dead)
|
2010-11-03 10:58:37 -07:00
|
|
|
return ECORE_CON_CONNECTED;
|
2008-10-01 08:27:52 -07:00
|
|
|
else
|
2010-11-03 10:58:37 -07:00
|
|
|
return ECORE_CON_DISCONNECTED;
|
2004-04-03 07:03:33 -08:00
|
|
|
}
|
|
|
|
|
2010-01-31 03:58:37 -08:00
|
|
|
static char *
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_pretty_ip(struct sockaddr *client_addr,
|
|
|
|
socklen_t size)
|
2010-01-31 03:58:37 -08:00
|
|
|
{
|
|
|
|
char ipbuf[INET6_ADDRSTRLEN + 1];
|
|
|
|
|
|
|
|
/* show v4mapped address in pretty form */
|
|
|
|
if (client_addr->sa_family == AF_INET6)
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
struct sockaddr_in6 *sa6;
|
|
|
|
|
|
|
|
sa6 = (struct sockaddr_in6 *)client_addr;
|
|
|
|
if (IN6_IS_ADDR_V4MAPPED(&sa6->sin6_addr))
|
|
|
|
{
|
|
|
|
snprintf(ipbuf, sizeof (ipbuf), "%u.%u.%u.%u",
|
|
|
|
sa6->sin6_addr.s6_addr[12],
|
|
|
|
sa6->sin6_addr.s6_addr[13],
|
|
|
|
sa6->sin6_addr.s6_addr[14],
|
|
|
|
sa6->sin6_addr.s6_addr[15]);
|
|
|
|
return strdup(ipbuf);
|
|
|
|
}
|
2010-01-31 03:58:37 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (getnameinfo(client_addr, size,
|
2010-07-26 23:30:27 -07:00
|
|
|
ipbuf, sizeof (ipbuf), NULL, 0,
|
|
|
|
NI_NUMERICHOST))
|
2010-11-03 10:58:37 -07:00
|
|
|
return strdup("0.0.0.0");
|
2010-01-31 03:58:37 -08:00
|
|
|
|
|
|
|
ipbuf[sizeof (ipbuf) - 1] = 0;
|
|
|
|
return strdup(ipbuf);
|
|
|
|
}
|
|
|
|
|
2010-06-24 09:15:56 -07:00
|
|
|
static Eina_Bool
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_svr_tcp_handler(void *data,
|
|
|
|
Ecore_Fd_Handler *fd_handler __UNUSED__)
|
2008-10-30 08:26:11 -07:00
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
Ecore_Con_Server *svr;
|
2010-09-17 23:06:05 -07:00
|
|
|
Ecore_Con_Client *cl = NULL;
|
2010-07-26 23:30:27 -07:00
|
|
|
int new_fd;
|
|
|
|
unsigned char incoming[256];
|
|
|
|
size_t size_in;
|
2008-10-30 08:26:11 -07:00
|
|
|
|
|
|
|
svr = data;
|
2010-07-26 23:30:27 -07:00
|
|
|
if (svr->dead)
|
2010-11-03 10:58:37 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (svr->delete_me)
|
2010-11-03 10:58:37 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-09-17 23:06:05 -07:00
|
|
|
if ((svr->client_limit >= 0) && (!svr->reject_excess_clients) &&
|
2010-09-20 12:31:11 -07:00
|
|
|
(svr->client_count >= (unsigned int)svr->client_limit))
|
2010-09-17 23:06:05 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2008-10-30 08:26:11 -07:00
|
|
|
/* a new client */
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-01-31 03:58:37 -08:00
|
|
|
size_in = sizeof(incoming);
|
2008-10-30 08:26:11 -07:00
|
|
|
|
2010-01-14 23:44:27 -08:00
|
|
|
memset(&incoming, 0, size_in);
|
2008-10-30 08:26:11 -07:00
|
|
|
new_fd = accept(svr->fd, (struct sockaddr *)&incoming, (socklen_t *)&size_in);
|
2010-09-17 21:59:11 -07:00
|
|
|
if (new_fd < 0)
|
|
|
|
/* error! */
|
|
|
|
return ECORE_CALLBACK_RENEW;
|
2010-09-22 01:03:38 -07:00
|
|
|
|
2010-09-17 23:06:05 -07:00
|
|
|
if ((svr->client_limit >= 0) && (svr->reject_excess_clients) &&
|
2010-09-20 12:31:11 -07:00
|
|
|
(svr->client_count >= (unsigned int)svr->client_limit))
|
2010-09-17 23:06:05 -07:00
|
|
|
goto error;
|
2010-09-17 21:59:11 -07:00
|
|
|
|
|
|
|
cl = calloc(1, sizeof(Ecore_Con_Client));
|
|
|
|
if (!cl)
|
2010-09-17 23:06:05 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-09-17 21:59:11 -07:00
|
|
|
fcntl(new_fd, F_SETFL, O_NONBLOCK);
|
|
|
|
fcntl(new_fd, F_SETFD, FD_CLOEXEC);
|
|
|
|
cl->fd = new_fd;
|
2010-09-18 12:26:05 -07:00
|
|
|
cl->host_server = svr;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-10-13 09:40:52 -07:00
|
|
|
cl->fd_handler = ecore_main_fd_handler_add(cl->fd, ECORE_FD_READ,
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_svr_cl_handler, cl, NULL, NULL);
|
2010-10-13 09:40:52 -07:00
|
|
|
ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
|
|
|
|
|
2010-10-15 00:42:29 -07:00
|
|
|
if (svr->type & ECORE_CON_SSL)
|
2010-09-23 21:15:42 -07:00
|
|
|
{
|
|
|
|
cl->handshaking = EINA_TRUE;
|
|
|
|
cl->ssl_state = ECORE_CON_SSL_STATE_INIT;
|
|
|
|
if (ecore_con_ssl_client_init(cl))
|
|
|
|
goto error;
|
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-09-17 21:59:11 -07:00
|
|
|
svr->clients = eina_list_append(svr->clients, cl);
|
2010-09-20 12:31:11 -07:00
|
|
|
svr->client_count++;
|
2010-09-17 21:59:11 -07:00
|
|
|
if (!svr->path)
|
2010-11-03 10:58:37 -07:00
|
|
|
cl->ip = _ecore_con_pretty_ip((struct sockaddr *)&incoming, size_in);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-09-23 21:15:42 -07:00
|
|
|
if ((!cl->delete_me) && (!cl->handshaking))
|
2010-09-17 21:59:11 -07:00
|
|
|
{
|
|
|
|
Ecore_Con_Event_Client_Add *e;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-09-17 21:59:11 -07:00
|
|
|
e = calloc(1, sizeof(Ecore_Con_Event_Client_Add));
|
2010-11-03 12:08:31 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, ECORE_CALLBACK_RENEW);
|
|
|
|
|
|
|
|
cl->event_count++;
|
|
|
|
_ecore_con_cl_timer_update(cl);
|
|
|
|
e->client = cl;
|
|
|
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_ADD, e,
|
|
|
|
_ecore_con_event_client_add_free, NULL);
|
|
|
|
|
2008-10-30 08:26:11 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-06-24 09:15:56 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2010-09-17 23:06:05 -07:00
|
|
|
|
|
|
|
error:
|
|
|
|
close(new_fd);
|
2010-10-13 09:40:52 -07:00
|
|
|
if (cl->fd_handler)
|
|
|
|
ecore_main_fd_handler_del(cl->fd_handler);
|
2010-09-17 23:06:05 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2008-10-30 08:26:11 -07:00
|
|
|
}
|
2004-04-03 07:03:33 -08:00
|
|
|
|
2010-09-17 23:06:05 -07:00
|
|
|
static void
|
|
|
|
_ecore_con_cl_read(Ecore_Con_Server *svr)
|
|
|
|
{
|
2010-11-03 12:08:31 -07:00
|
|
|
int num = 0;
|
|
|
|
Eina_Bool lost_server = EINA_TRUE;
|
|
|
|
unsigned char buf[READBUFSIZ];
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-10-02 14:13:56 -07:00
|
|
|
/* only possible with non-ssl connections */
|
|
|
|
if (svr->connecting && (svr_try_connect_plain(svr) != ECORE_CON_CONNECTED))
|
2010-11-03 10:58:37 -07:00
|
|
|
return;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-11-03 12:08:31 -07:00
|
|
|
if (svr->handshaking)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2010-11-03 12:08:31 -07:00
|
|
|
DBG("Continuing ssl handshake");
|
|
|
|
if (!ecore_con_ssl_server_init(svr))
|
|
|
|
lost_server = EINA_FALSE;
|
|
|
|
}
|
2010-09-24 20:02:10 -07:00
|
|
|
|
2010-11-03 12:08:31 -07:00
|
|
|
if (!(svr->type & ECORE_CON_SSL))
|
|
|
|
{
|
2010-11-03 12:38:00 -07:00
|
|
|
errno = 0;
|
2010-11-03 12:08:31 -07:00
|
|
|
num = read(svr->fd, buf, sizeof(buf));
|
2010-11-05 12:46:48 -07:00
|
|
|
if ((num >= 0) || (errno == EAGAIN))
|
2010-11-03 10:58:37 -07:00
|
|
|
lost_server = EINA_FALSE;
|
2010-11-03 12:08:31 -07:00
|
|
|
}
|
2010-11-03 12:38:00 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
num = ecore_con_ssl_server_read(svr, buf, sizeof(buf));
|
|
|
|
if (num >= 0)
|
|
|
|
lost_server = EINA_FALSE;
|
|
|
|
}
|
2008-10-30 08:26:11 -07:00
|
|
|
|
2010-11-03 12:38:00 -07:00
|
|
|
if (lost_server)
|
|
|
|
_ecore_con_server_kill(svr);
|
|
|
|
|
2010-11-05 18:22:29 -07:00
|
|
|
if ((num > 0) && (!svr->delete_me))
|
2010-11-03 12:38:00 -07:00
|
|
|
{
|
|
|
|
Ecore_Con_Event_Server_Data *e;
|
|
|
|
|
|
|
|
e = malloc(sizeof(Ecore_Con_Event_Server_Data));
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
|
|
|
svr->event_count++;
|
|
|
|
e->server = svr;
|
2010-11-05 18:22:29 -07:00
|
|
|
e->data = malloc(num);
|
|
|
|
if (!e->data)
|
2010-11-04 08:48:17 -07:00
|
|
|
{
|
2010-11-05 18:22:29 -07:00
|
|
|
ERR("alloc!");
|
|
|
|
free(e);
|
|
|
|
return;
|
2010-11-04 08:48:17 -07:00
|
|
|
}
|
2010-11-05 18:22:29 -07:00
|
|
|
memcpy(e->data, buf, num);
|
2010-11-03 12:38:00 -07:00
|
|
|
e->size = num;
|
|
|
|
ecore_event_add(ECORE_CON_EVENT_SERVER_DATA, e,
|
|
|
|
_ecore_con_event_server_data_free, NULL);
|
|
|
|
}
|
2004-03-31 08:47:45 -08:00
|
|
|
|
2010-09-17 23:06:05 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_cl_handler(void *data,
|
|
|
|
Ecore_Fd_Handler *fd_handler)
|
2010-09-17 23:06:05 -07:00
|
|
|
{
|
|
|
|
Ecore_Con_Server *svr;
|
2010-09-29 16:53:00 -07:00
|
|
|
Eina_Bool want_read, want_write;
|
2010-09-17 23:06:05 -07:00
|
|
|
|
|
|
|
svr = data;
|
|
|
|
if (svr->dead)
|
2010-11-03 10:58:37 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2010-09-17 23:06:05 -07:00
|
|
|
|
|
|
|
if (svr->delete_me)
|
2010-11-03 10:58:37 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2010-09-17 23:06:05 -07:00
|
|
|
|
2010-09-29 16:53:00 -07:00
|
|
|
want_read = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ);
|
|
|
|
want_write = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE);
|
|
|
|
|
|
|
|
if (svr->handshaking && (want_read || want_write))
|
2010-09-23 21:15:42 -07:00
|
|
|
{
|
2010-09-29 16:53:00 -07:00
|
|
|
DBG("Continuing ssl handshake: preparing to %s...", want_read ? "read" : "write");
|
2010-11-03 09:11:12 -07:00
|
|
|
#ifdef ISCOMFITOR
|
2010-11-03 10:58:37 -07:00
|
|
|
if (want_read)
|
|
|
|
{
|
2010-11-03 12:08:31 -07:00
|
|
|
char buf[READBUFSIZ];
|
2010-11-03 10:58:37 -07:00
|
|
|
ssize_t len;
|
|
|
|
len = recv(svr->fd, buf, sizeof(buf), MSG_DONTWAIT | MSG_PEEK);
|
|
|
|
DBG("%zu bytes in buffer", len);
|
|
|
|
}
|
2010-09-29 07:52:36 -07:00
|
|
|
#endif
|
2010-10-01 18:32:54 -07:00
|
|
|
if (ecore_con_ssl_server_init(svr))
|
2010-09-23 21:15:42 -07:00
|
|
|
{
|
2010-10-01 18:32:54 -07:00
|
|
|
ERR("ssl handshaking failed!");
|
2010-10-28 03:59:30 -07:00
|
|
|
svr->handshaking = EINA_FALSE;
|
2010-10-01 18:32:54 -07:00
|
|
|
Ecore_Con_Event_Server_Del *e;
|
2010-09-23 22:57:03 -07:00
|
|
|
|
2010-10-01 18:32:54 -07:00
|
|
|
e = calloc(1, sizeof(Ecore_Con_Event_Server_Del));
|
2010-11-03 12:08:31 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, ECORE_CALLBACK_RENEW);
|
|
|
|
|
|
|
|
svr->event_count++;
|
|
|
|
e->server = svr;
|
|
|
|
ecore_event_add(ECORE_CON_EVENT_SERVER_DEL, e,
|
|
|
|
_ecore_con_event_server_del_free, NULL);
|
2010-09-23 22:57:03 -07:00
|
|
|
}
|
2010-10-01 18:32:54 -07:00
|
|
|
else if (!svr->ssl_state)
|
2010-09-23 22:57:03 -07:00
|
|
|
{
|
2010-10-01 18:32:54 -07:00
|
|
|
/* we got our server! */
|
2010-11-03 10:58:37 -07:00
|
|
|
Ecore_Con_Event_Server_Add *e;
|
|
|
|
|
|
|
|
svr->connecting = EINA_FALSE;
|
|
|
|
e = calloc(1, sizeof(Ecore_Con_Event_Server_Add));
|
2010-11-03 12:08:31 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, ECORE_CALLBACK_RENEW);
|
|
|
|
|
|
|
|
svr->event_count++;
|
|
|
|
svr->start_time = ecore_time_get();
|
|
|
|
e->server = svr;
|
|
|
|
ecore_event_add(ECORE_CON_EVENT_SERVER_ADD, e,
|
|
|
|
_ecore_con_event_server_add_free, NULL);
|
2010-09-23 21:15:42 -07:00
|
|
|
}
|
|
|
|
}
|
2010-09-29 16:53:00 -07:00
|
|
|
else if (want_read)
|
2010-09-17 23:06:05 -07:00
|
|
|
_ecore_con_cl_read(svr);
|
2010-11-03 10:58:37 -07:00
|
|
|
else if (want_write) /* only possible with non-ssl connections */
|
|
|
|
{
|
2010-10-02 14:13:56 -07:00
|
|
|
if (svr->connecting && (!svr_try_connect_plain(svr)))
|
2010-11-03 10:58:37 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
_ecore_con_server_flush(svr);
|
2004-04-14 01:51:19 -07:00
|
|
|
}
|
2004-04-03 07:03:33 -08:00
|
|
|
|
2010-06-24 09:15:56 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2010-06-24 09:15:56 -07:00
|
|
|
static Eina_Bool
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_cl_udp_handler(void *data,
|
|
|
|
Ecore_Fd_Handler *fd_handler)
|
2008-09-25 03:14:31 -07:00
|
|
|
{
|
2010-11-05 18:22:40 -07:00
|
|
|
Ecore_Con_Event_Server_Data *e;
|
|
|
|
unsigned char *inbuf;
|
2010-11-03 12:08:31 -07:00
|
|
|
unsigned char buf[READBUFSIZ];
|
|
|
|
int num;
|
2010-07-26 23:30:27 -07:00
|
|
|
Ecore_Con_Server *svr;
|
2010-11-03 12:08:31 -07:00
|
|
|
Eina_Bool want_read, want_write;
|
|
|
|
|
|
|
|
want_read = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ);
|
|
|
|
want_write = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE);
|
2008-09-25 03:14:31 -07:00
|
|
|
|
|
|
|
svr = data;
|
2010-11-03 12:08:31 -07:00
|
|
|
if (svr->dead || svr->delete_me || ((!want_read) && (!want_write)))
|
2010-11-03 10:58:37 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-11-03 12:08:31 -07:00
|
|
|
if (want_write)
|
|
|
|
{
|
|
|
|
_ecore_con_server_flush(svr);
|
|
|
|
return ECORE_CALLBACK_RENEW;
|
|
|
|
}
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
num = read(svr->fd, buf, READBUFSIZ);
|
|
|
|
|
|
|
|
if ((errno == EIO) || (errno == EBADF) || (errno == EPIPE) || (errno == EINVAL) ||
|
|
|
|
(errno == ENOSPC) || (errno == ECONNREFUSED))
|
|
|
|
_ecore_con_server_kill(svr);
|
|
|
|
|
|
|
|
if ((num < 1) || (svr->delete_me))
|
2010-11-03 10:58:37 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-11-03 12:08:31 -07:00
|
|
|
inbuf = malloc(num);
|
|
|
|
if(!inbuf)
|
|
|
|
return ECORE_CALLBACK_RENEW;
|
|
|
|
|
|
|
|
memcpy(inbuf, buf, num);
|
|
|
|
|
|
|
|
e = calloc(1, sizeof(Ecore_Con_Event_Server_Data));
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, ECORE_CALLBACK_RENEW);
|
|
|
|
|
|
|
|
svr->event_count++;
|
|
|
|
e->server = svr;
|
|
|
|
e->data = inbuf;
|
|
|
|
e->size = num;
|
|
|
|
ecore_event_add(ECORE_CON_EVENT_SERVER_DATA, e,
|
|
|
|
_ecore_con_event_server_data_free, NULL);
|
2008-10-09 05:30:19 -07:00
|
|
|
|
2010-06-24 09:15:56 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2008-09-25 03:14:31 -07:00
|
|
|
}
|
|
|
|
|
2010-06-24 09:15:56 -07:00
|
|
|
static Eina_Bool
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_svr_udp_handler(void *data,
|
|
|
|
Ecore_Fd_Handler *fd_handler)
|
2008-09-17 08:08:48 -07:00
|
|
|
{
|
2010-11-03 12:08:31 -07:00
|
|
|
unsigned char buf[READBUFSIZ];
|
|
|
|
unsigned char client_addr[256];
|
|
|
|
unsigned int client_addr_len = sizeof(client_addr);
|
|
|
|
int num;
|
2010-07-26 23:30:27 -07:00
|
|
|
Ecore_Con_Server *svr;
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
Ecore_Con_Client *cl = NULL;
|
2008-09-17 08:08:48 -07:00
|
|
|
|
2008-10-09 05:30:19 -07:00
|
|
|
svr = data;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-11-03 12:08:31 -07:00
|
|
|
if (svr->delete_me || svr->dead)
|
2010-11-03 10:58:37 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-11-03 12:08:31 -07:00
|
|
|
if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
|
2008-09-17 08:08:48 -07:00
|
|
|
{
|
2010-11-03 12:08:31 -07:00
|
|
|
_ecore_con_client_flush(cl);
|
|
|
|
return ECORE_CALLBACK_RENEW;
|
|
|
|
}
|
2008-09-17 08:08:48 -07:00
|
|
|
|
2010-11-03 12:08:31 -07:00
|
|
|
if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
|
|
|
|
return ECORE_CALLBACK_RENEW;
|
|
|
|
|
|
|
|
errno = 0;
|
2010-02-20 10:01:50 -08:00
|
|
|
#ifdef _WIN32
|
2010-11-03 12:08:31 -07:00
|
|
|
num = fcntl(svr->fd, F_SETFL, O_NONBLOCK);
|
|
|
|
if (num >= 0)
|
|
|
|
num = recvfrom(svr->fd, buf, sizeof(buf), 0,
|
|
|
|
(struct sockaddr *)&client_addr,
|
|
|
|
&client_addr_len);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-02-20 10:01:50 -08:00
|
|
|
#else
|
2010-11-03 12:08:31 -07:00
|
|
|
num = recvfrom(svr->fd, buf, sizeof(buf), MSG_DONTWAIT,
|
|
|
|
(struct sockaddr *)&client_addr,
|
|
|
|
&client_addr_len);
|
2010-02-20 10:01:50 -08:00
|
|
|
#endif
|
2008-10-09 05:30:19 -07:00
|
|
|
|
2010-11-03 12:08:31 -07:00
|
|
|
if ((errno == EIO) || (errno == EBADF) || (errno == EPIPE) ||
|
|
|
|
(errno == EINVAL) || (errno == ENOSPC) || (errno == ECONNREFUSED))
|
|
|
|
{
|
|
|
|
if (!svr->delete_me)
|
2010-07-26 23:30:27 -07:00
|
|
|
{
|
2010-11-03 12:08:31 -07:00
|
|
|
/* we lost our client! */
|
|
|
|
Ecore_Con_Event_Client_Del *e;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-11-03 12:08:31 -07:00
|
|
|
e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, ECORE_CALLBACK_RENEW);
|
|
|
|
|
|
|
|
svr->event_count++;
|
|
|
|
/* be explicit here */
|
|
|
|
e->client = NULL;
|
|
|
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
|
|
|
|
_ecore_con_event_client_del_free, NULL);
|
2010-07-26 23:30:27 -07:00
|
|
|
}
|
2010-11-03 12:08:31 -07:00
|
|
|
|
|
|
|
svr->dead = EINA_TRUE;
|
|
|
|
svr->fd_handler = NULL;
|
|
|
|
return ECORE_CALLBACK_CANCEL;
|
2008-09-17 08:08:48 -07:00
|
|
|
}
|
2010-11-03 12:08:31 -07:00
|
|
|
|
|
|
|
|
|
|
|
/* Create a new client for use in the client data event */
|
|
|
|
cl = calloc(1, sizeof(Ecore_Con_Client));
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(cl, ECORE_CALLBACK_RENEW);
|
|
|
|
|
|
|
|
cl->host_server = svr;
|
|
|
|
cl->client_addr = calloc(1, client_addr_len);
|
|
|
|
if(!cl->client_addr)
|
|
|
|
{
|
|
|
|
free(cl);
|
|
|
|
return ECORE_CALLBACK_RENEW;
|
|
|
|
}
|
|
|
|
cl->client_addr_len = client_addr_len;
|
|
|
|
|
|
|
|
memcpy(cl->client_addr, &client_addr, client_addr_len);
|
|
|
|
ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
|
|
|
|
svr->clients = eina_list_append(svr->clients, cl);
|
|
|
|
svr->client_count++;
|
|
|
|
|
|
|
|
cl->ip = _ecore_con_pretty_ip(cl->client_addr,
|
|
|
|
cl->client_addr_len);
|
|
|
|
|
|
|
|
{ /* indent to keep it all nicely separated */
|
|
|
|
Ecore_Con_Event_Client_Add *add;
|
|
|
|
|
|
|
|
add = calloc(1, sizeof(Ecore_Con_Event_Client_Add));
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(add, ECORE_CALLBACK_RENEW);
|
|
|
|
|
|
|
|
/*cl->event_count++;*/
|
|
|
|
add->client = cl;
|
|
|
|
_ecore_con_cl_timer_update(cl);
|
|
|
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_ADD, add,
|
|
|
|
_ecore_con_event_client_add_free, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
Ecore_Con_Event_Client_Data *e;
|
|
|
|
e = calloc(1, sizeof(Ecore_Con_Event_Client_Data));
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, ECORE_CALLBACK_RENEW);
|
|
|
|
|
|
|
|
svr->event_count++;
|
|
|
|
_ecore_con_cl_timer_update(cl);
|
|
|
|
e->client = cl;
|
|
|
|
e->data = malloc(num);
|
|
|
|
if(!e->data)
|
|
|
|
{
|
|
|
|
free(cl->client_addr);
|
|
|
|
free(cl);
|
|
|
|
return ECORE_CALLBACK_RENEW;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(e->data, buf, num);
|
|
|
|
e->size = num;
|
|
|
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_DATA, e,
|
|
|
|
_ecore_con_event_client_data_free, NULL);
|
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-06-24 09:15:56 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2008-09-17 08:08:48 -07:00
|
|
|
}
|
|
|
|
|
2010-09-17 22:30:16 -07:00
|
|
|
static void
|
|
|
|
_ecore_con_svr_cl_read(Ecore_Con_Client *cl)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2010-11-03 12:08:31 -07:00
|
|
|
int num = 0;
|
|
|
|
Eina_Bool lost_client = EINA_TRUE;
|
|
|
|
unsigned char buf[READBUFSIZ];
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2010-11-03 12:08:31 -07:00
|
|
|
if (cl->handshaking)
|
2010-09-17 22:30:16 -07:00
|
|
|
{
|
2010-11-03 12:08:31 -07:00
|
|
|
/* add an extra handshake attempt just before read, even though
|
|
|
|
* read also attempts to handshake, to try to finish sooner
|
|
|
|
*/
|
|
|
|
if (ecore_con_ssl_client_init(cl))
|
|
|
|
lost_client = EINA_FALSE;
|
2010-09-24 21:22:10 -07:00
|
|
|
|
2010-11-03 12:08:31 -07:00
|
|
|
_ecore_con_cl_timer_update(cl);
|
|
|
|
}
|
2010-09-24 20:02:10 -07:00
|
|
|
|
2010-11-03 12:08:31 -07:00
|
|
|
if (!(cl->host_server->type & ECORE_CON_SSL))
|
|
|
|
{
|
|
|
|
errno = 0;
|
|
|
|
num = read(cl->fd, buf, sizeof(buf));
|
2010-11-05 12:46:48 -07:00
|
|
|
if ((num >= 0) || (errno == EAGAIN))
|
2010-11-03 10:58:37 -07:00
|
|
|
lost_client = EINA_FALSE;
|
2010-11-03 12:08:31 -07:00
|
|
|
}
|
2010-11-03 12:38:00 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
num = ecore_con_ssl_client_read(cl, buf, sizeof(buf));
|
|
|
|
if (num >= 0)
|
|
|
|
lost_client = EINA_FALSE;
|
|
|
|
}
|
2010-09-17 22:30:16 -07:00
|
|
|
|
2010-11-03 12:38:00 -07:00
|
|
|
if (lost_client)
|
|
|
|
{
|
|
|
|
if (!cl->delete_me)
|
|
|
|
{
|
|
|
|
/* we lost our client! */
|
|
|
|
Ecore_Con_Event_Client_Del *e;
|
|
|
|
|
|
|
|
e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
|
|
|
cl->event_count++;
|
|
|
|
_ecore_con_cl_timer_update(cl);
|
|
|
|
e->client = cl;
|
|
|
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
|
|
|
|
_ecore_con_event_client_del_free, NULL);
|
|
|
|
}
|
2010-11-05 16:48:15 -07:00
|
|
|
INF("Lost client %s", cl->ip);
|
2010-11-03 12:38:00 -07:00
|
|
|
cl->dead = EINA_TRUE;
|
|
|
|
if (cl->fd_handler)
|
|
|
|
ecore_main_fd_handler_del(cl->fd_handler);
|
|
|
|
|
|
|
|
cl->fd_handler = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((num > 0) && (!cl->delete_me))
|
2010-11-03 12:08:31 -07:00
|
|
|
{
|
|
|
|
Ecore_Con_Event_Client_Data *e;
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2010-11-03 12:08:31 -07:00
|
|
|
e = malloc(sizeof(Ecore_Con_Event_Client_Data));
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
|
|
|
cl->event_count++;
|
|
|
|
_ecore_con_cl_timer_update(cl);
|
|
|
|
e->client = cl;
|
2010-11-05 18:22:29 -07:00
|
|
|
e->data = malloc(num);
|
|
|
|
if (!e->data)
|
2010-09-17 22:30:16 -07:00
|
|
|
{
|
2010-11-05 18:22:29 -07:00
|
|
|
ERR("alloc!");
|
|
|
|
free(e);
|
|
|
|
return;
|
2010-09-17 22:30:16 -07:00
|
|
|
}
|
2010-11-05 18:22:29 -07:00
|
|
|
memcpy(e->data, buf, num);
|
2010-11-03 12:08:31 -07:00
|
|
|
e->size = num;
|
|
|
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_DATA, e,
|
|
|
|
_ecore_con_event_client_data_free, NULL);
|
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
|
2010-09-17 22:30:16 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-09-17 22:30:16 -07:00
|
|
|
static Eina_Bool
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_svr_cl_handler(void *data,
|
|
|
|
Ecore_Fd_Handler *fd_handler)
|
2010-09-17 22:30:16 -07:00
|
|
|
{
|
|
|
|
Ecore_Con_Client *cl;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-09-17 22:30:16 -07:00
|
|
|
cl = data;
|
|
|
|
if (cl->dead)
|
2010-11-03 10:58:37 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2010-09-17 22:30:16 -07:00
|
|
|
|
|
|
|
if (cl->delete_me)
|
2010-11-03 10:58:37 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2010-09-17 22:30:16 -07:00
|
|
|
|
2010-09-28 22:08:47 -07:00
|
|
|
if (cl->handshaking && ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ | ECORE_FD_WRITE))
|
2010-09-23 21:15:42 -07:00
|
|
|
{
|
2010-10-01 18:32:54 -07:00
|
|
|
if (ecore_con_ssl_client_init(cl))
|
2010-09-23 21:15:42 -07:00
|
|
|
{
|
|
|
|
ERR("ssl handshaking failed!");
|
2010-10-28 03:59:30 -07:00
|
|
|
cl->handshaking = EINA_FALSE;
|
2010-09-23 22:57:03 -07:00
|
|
|
/* we lost our client! */
|
|
|
|
Ecore_Con_Event_Client_Del *e;
|
|
|
|
|
|
|
|
cl->dead = EINA_TRUE;
|
2010-11-05 16:48:15 -07:00
|
|
|
INF("Lost client %s", cl->ip);
|
2010-09-23 22:57:03 -07:00
|
|
|
e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
|
2010-11-03 12:08:31 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, ECORE_CALLBACK_RENEW);
|
|
|
|
|
|
|
|
cl->event_count++;
|
|
|
|
_ecore_con_cl_timer_update(cl);
|
|
|
|
e->client = cl;
|
|
|
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
|
|
|
|
_ecore_con_event_client_del_free, NULL);
|
2010-09-23 21:15:42 -07:00
|
|
|
}
|
2010-10-01 18:32:54 -07:00
|
|
|
else if (!cl->ssl_state)
|
|
|
|
{
|
2010-11-03 12:08:31 -07:00
|
|
|
Ecore_Con_Event_Client_Add *e;
|
|
|
|
|
|
|
|
e = calloc(1, sizeof(Ecore_Con_Event_Client_Add));
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, ECORE_CALLBACK_RENEW);
|
|
|
|
|
|
|
|
e->client = cl;
|
2010-11-05 13:55:02 -07:00
|
|
|
cl->event_count++;
|
2010-11-03 12:08:31 -07:00
|
|
|
_ecore_con_cl_timer_update(cl);
|
|
|
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_ADD, e,
|
|
|
|
_ecore_con_event_client_add_free, NULL);
|
2010-10-01 18:32:54 -07:00
|
|
|
}
|
2010-09-23 21:15:42 -07:00
|
|
|
}
|
2010-09-28 22:08:47 -07:00
|
|
|
else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
|
2010-09-17 22:30:16 -07:00
|
|
|
_ecore_con_svr_cl_read(cl);
|
2010-09-22 01:03:38 -07:00
|
|
|
|
2010-09-17 22:30:16 -07:00
|
|
|
else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
|
|
|
|
_ecore_con_client_flush(cl);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-06-24 09:15:56 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ecore_con_server_flush(Ecore_Con_Server *svr)
|
|
|
|
{
|
2008-12-15 09:59:19 -08:00
|
|
|
int count, num;
|
2003-09-23 01:09:32 -07:00
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
if (!svr->write_buf)
|
2010-11-03 10:58:37 -07:00
|
|
|
return;
|
2004-04-02 10:32:55 -08:00
|
|
|
|
|
|
|
/* check whether we need to write anything at all.
|
2008-10-09 05:30:19 -07:00
|
|
|
* we must not write zero bytes with SSL_write() since it
|
|
|
|
* causes undefined behaviour
|
|
|
|
*/
|
2004-04-03 07:03:33 -08:00
|
|
|
if (svr->write_buf_size == svr->write_buf_offset)
|
2010-11-03 10:58:37 -07:00
|
|
|
return;
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2004-04-03 07:03:33 -08:00
|
|
|
num = svr->write_buf_size - svr->write_buf_offset;
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2010-09-24 21:22:10 -07:00
|
|
|
if (svr->handshaking)
|
|
|
|
{
|
2010-09-28 20:52:32 -07:00
|
|
|
DBG("Continuing ssl handshake");
|
2010-09-24 21:22:10 -07:00
|
|
|
if (ecore_con_ssl_server_init(svr))
|
2010-09-28 21:06:28 -07:00
|
|
|
_ecore_con_server_kill(svr);
|
2010-09-24 21:22:10 -07:00
|
|
|
return;
|
|
|
|
}
|
2010-09-24 20:02:10 -07:00
|
|
|
|
2008-10-30 08:26:11 -07:00
|
|
|
if (!(svr->type & ECORE_CON_SSL))
|
2010-11-03 10:58:37 -07:00
|
|
|
count = write(svr->fd, svr->write_buf + svr->write_buf_offset, num);
|
2008-10-30 08:26:11 -07:00
|
|
|
else
|
2010-11-03 10:58:37 -07:00
|
|
|
count = ecore_con_ssl_server_write(svr, svr->write_buf + svr->write_buf_offset, num);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-09-24 20:02:10 -07:00
|
|
|
if (count < 0)
|
2010-09-28 21:06:28 -07:00
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
/* we lost our server! */
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_server_kill(svr);
|
|
|
|
return;
|
2010-09-28 21:06:28 -07:00
|
|
|
}
|
2004-04-02 10:32:55 -08:00
|
|
|
|
2004-04-03 07:03:33 -08:00
|
|
|
svr->write_buf_offset += count;
|
|
|
|
if (svr->write_buf_offset >= svr->write_buf_size)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
svr->write_buf_size = 0;
|
|
|
|
svr->write_buf_offset = 0;
|
|
|
|
free(svr->write_buf);
|
|
|
|
svr->write_buf = NULL;
|
|
|
|
if (svr->fd_handler)
|
2010-11-03 10:58:37 -07:00
|
|
|
ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
2010-11-04 08:01:05 -07:00
|
|
|
else if (count < num)
|
|
|
|
ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE);
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ecore_con_client_flush(Ecore_Con_Client *cl)
|
|
|
|
{
|
2010-09-24 20:02:10 -07:00
|
|
|
int num, count = 0;
|
2003-09-23 01:09:32 -07:00
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
if (!cl->buf)
|
2010-11-03 10:58:37 -07:00
|
|
|
return;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-09-24 21:22:10 -07:00
|
|
|
if (cl->handshaking)
|
|
|
|
{
|
|
|
|
if (ecore_con_ssl_client_init(cl))
|
|
|
|
count = -1;
|
|
|
|
|
|
|
|
_ecore_con_cl_timer_update(cl);
|
|
|
|
}
|
2010-09-24 20:02:10 -07:00
|
|
|
|
|
|
|
if (!count)
|
|
|
|
{
|
|
|
|
num = cl->buf_size - cl->buf_offset;
|
|
|
|
if (!(cl->host_server->type & ECORE_CON_SSL))
|
2010-11-03 10:58:37 -07:00
|
|
|
count = write(cl->fd, cl->buf + cl->buf_offset, num);
|
2010-09-24 20:02:10 -07:00
|
|
|
else
|
2010-11-03 10:58:37 -07:00
|
|
|
count = ecore_con_ssl_client_write(cl, cl->buf + cl->buf_offset, num);
|
2010-09-24 20:02:10 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-09-24 20:02:10 -07:00
|
|
|
if (count < 0)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
if ((errno == EIO) || (errno == EBADF) || (errno == EPIPE) ||
|
|
|
|
(errno == EINVAL) || (errno == ENOSPC) || (errno == ECONNREFUSED))
|
2010-11-03 10:58:37 -07:00
|
|
|
if (!cl->delete_me)
|
|
|
|
{
|
|
|
|
/* we lost our client! */
|
2010-07-26 23:30:27 -07:00
|
|
|
Ecore_Con_Event_Client_Del *e;
|
|
|
|
|
|
|
|
e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
|
2010-11-03 12:08:31 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
|
|
|
cl->event_count++;
|
|
|
|
_ecore_con_cl_timer_update(cl);
|
|
|
|
e->client = cl;
|
|
|
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
|
|
|
|
_ecore_con_event_client_del_free, NULL);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-09-17 23:30:13 -07:00
|
|
|
cl->dead = EINA_TRUE;
|
2010-11-05 16:48:15 -07:00
|
|
|
INF("Lost client %s", cl->ip);
|
2010-07-26 23:30:27 -07:00
|
|
|
if (cl->fd_handler)
|
2010-11-03 10:58:37 -07:00
|
|
|
ecore_main_fd_handler_del(cl->fd_handler);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
cl->fd_handler = NULL;
|
2010-11-03 10:58:37 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
return;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
cl->buf_offset += count;
|
|
|
|
if (cl->buf_offset >= cl->buf_size)
|
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
cl->buf_size = 0;
|
|
|
|
cl->buf_offset = 0;
|
|
|
|
free(cl->buf);
|
|
|
|
cl->buf = NULL;
|
|
|
|
if (cl->fd_handler)
|
2010-11-03 10:58:37 -07:00
|
|
|
ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ);
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
2010-11-04 08:01:05 -07:00
|
|
|
else if (count < num)
|
|
|
|
ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_WRITE);
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2006-03-19 21:53:12 -08:00
|
|
|
static void
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_event_client_add_free(void *data __UNUSED__,
|
|
|
|
void *ev)
|
2006-03-19 21:53:12 -08:00
|
|
|
{
|
|
|
|
Ecore_Con_Event_Client_Add *e;
|
|
|
|
|
|
|
|
e = ev;
|
|
|
|
e->client->event_count--;
|
2010-11-05 13:55:02 -07:00
|
|
|
if ((e->client->event_count <= 0) &&
|
2010-07-26 23:30:27 -07:00
|
|
|
(e->client->delete_me))
|
2010-11-03 10:58:37 -07:00
|
|
|
ecore_con_client_del(e->client);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2006-03-19 21:53:12 -08:00
|
|
|
free(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_event_client_del_free(void *data __UNUSED__,
|
|
|
|
void *ev)
|
2006-03-19 21:53:12 -08:00
|
|
|
{
|
|
|
|
Ecore_Con_Event_Client_Del *e;
|
|
|
|
|
|
|
|
e = ev;
|
|
|
|
e->client->event_count--;
|
2010-11-05 13:55:02 -07:00
|
|
|
if ((e->client->event_count <= 0) && (e->client->delete_me))
|
2010-11-03 10:58:37 -07:00
|
|
|
ecore_con_client_del(e->client);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-11-03 10:58:37 -07:00
|
|
|
free(e);
|
2006-03-19 21:53:12 -08:00
|
|
|
}
|
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
static void
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_event_client_data_free(void *data __UNUSED__,
|
|
|
|
void *ev)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
|
|
|
Ecore_Con_Event_Client_Data *e;
|
|
|
|
|
|
|
|
e = ev;
|
2006-03-19 21:53:12 -08:00
|
|
|
e->client->event_count--;
|
2010-07-26 23:30:27 -07:00
|
|
|
if (e->data)
|
2010-11-03 10:58:37 -07:00
|
|
|
free(e->data);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-11-05 13:55:02 -07:00
|
|
|
if (((e->client->event_count <= 0) && (e->client->delete_me)) ||
|
2010-09-18 12:26:05 -07:00
|
|
|
((e->client->host_server &&
|
|
|
|
((e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP ||
|
|
|
|
(e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_MCAST))))
|
2010-11-03 10:58:37 -07:00
|
|
|
ecore_con_client_del(e->client);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2006-03-19 21:53:12 -08:00
|
|
|
free(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_event_server_add_free(void *data __UNUSED__,
|
|
|
|
void *ev)
|
2006-03-19 21:53:12 -08:00
|
|
|
{
|
|
|
|
Ecore_Con_Event_Server_Add *e;
|
|
|
|
|
|
|
|
e = ev;
|
|
|
|
e->server->event_count--;
|
2010-11-05 13:55:02 -07:00
|
|
|
if ((e->server->event_count <= 0) &&
|
2010-07-26 23:30:27 -07:00
|
|
|
(e->server->delete_me))
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_server_free(e->server);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2006-03-19 21:53:12 -08:00
|
|
|
free(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_event_server_del_free(void *data __UNUSED__,
|
|
|
|
void *ev)
|
2006-03-19 21:53:12 -08:00
|
|
|
{
|
|
|
|
Ecore_Con_Event_Server_Del *e;
|
|
|
|
|
|
|
|
e = ev;
|
|
|
|
e->server->event_count--;
|
2010-11-05 13:55:02 -07:00
|
|
|
if ((e->server->event_count <= 0) &&
|
2010-07-26 23:30:27 -07:00
|
|
|
(e->server->delete_me))
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_server_free(e->server);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-11-03 10:58:37 -07:00
|
|
|
free(e);
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_event_server_data_free(void *data __UNUSED__,
|
|
|
|
void *ev)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
|
|
|
Ecore_Con_Event_Server_Data *e;
|
|
|
|
|
|
|
|
e = ev;
|
2006-03-19 21:53:12 -08:00
|
|
|
e->server->event_count--;
|
2010-07-26 23:30:27 -07:00
|
|
|
if (e->data)
|
2010-11-03 10:58:37 -07:00
|
|
|
free(e->data);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-11-05 13:55:02 -07:00
|
|
|
if ((e->server->event_count <= 0) &&
|
2010-07-26 23:30:27 -07:00
|
|
|
(e->server->delete_me))
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_server_free(e->server);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
free(e);
|
|
|
|
}
|
2010-07-22 04:32:55 -07:00
|
|
|
|
|
|
|
static void
|
2010-11-03 10:58:37 -07:00
|
|
|
_ecore_con_lookup_done(void *data,
|
|
|
|
Ecore_Con_Info *infos)
|
2010-07-22 04:32:55 -07:00
|
|
|
{
|
|
|
|
Ecore_Con_Server *svr;
|
|
|
|
Ecore_Con_Lookup *lk;
|
|
|
|
|
|
|
|
svr = data;
|
|
|
|
lk = svr->data;
|
|
|
|
|
|
|
|
if (infos)
|
2010-11-03 10:58:37 -07:00
|
|
|
lk->done_cb(infos->info.ai_canonname, infos->ip,
|
|
|
|
infos->info.ai_addr, infos->info.ai_addrlen,
|
|
|
|
(void *)lk->data);
|
2010-07-22 04:32:55 -07:00
|
|
|
else
|
2010-11-03 10:58:37 -07:00
|
|
|
lk->done_cb(NULL, NULL, NULL, 0, (void *)lk->data);
|
2010-07-22 04:32:55 -07:00
|
|
|
|
|
|
|
free(svr->name);
|
|
|
|
free(lk);
|
|
|
|
free(svr);
|
|
|
|
}
|
2010-11-03 10:58:37 -07:00
|
|
|
|