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>
|
2013-03-15 01:12:05 -07:00
|
|
|
|
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
|
|
|
# include <sys/socket.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_NETINET_TCP_H
|
|
|
|
# include <netinet/tcp.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
|
|
# include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_ARPA_INET_H
|
|
|
|
# include <arpa/inet.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_UN_H
|
2013-01-10 12:26:02 -08:00
|
|
|
#include <sys/un.h>
|
2013-03-15 01:12:05 -07:00
|
|
|
#endif
|
2010-02-20 11:12:52 -08:00
|
|
|
|
2013-03-09 22:49:54 -08:00
|
|
|
#ifdef HAVE_SYSTEMD
|
|
|
|
# include <systemd/sd-daemon.h>
|
|
|
|
#endif
|
|
|
|
|
2010-02-20 11:12:52 -08:00
|
|
|
#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"
|
|
|
|
|
2013-12-19 21:07:50 -08:00
|
|
|
static Eina_Bool _ecore_con_client_timer(Ecore_Con_Client *cl);
|
|
|
|
static void _ecore_con_cl_timer_update(Ecore_Con_Client *cl);
|
|
|
|
static Eina_Bool _ecore_con_server_timer(Ecore_Con_Server *svr);
|
|
|
|
static void _ecore_con_server_timer_update(Ecore_Con_Server *svr);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
static void _ecore_con_server_free(Ecore_Con_Server *svr);
|
|
|
|
static void _ecore_con_client_free(Ecore_Con_Client *cl);
|
|
|
|
|
|
|
|
static void _ecore_con_cl_read(Ecore_Con_Server *svr);
|
|
|
|
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);
|
|
|
|
|
|
|
|
static void _ecore_con_svr_cl_read(Ecore_Con_Client *cl);
|
|
|
|
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);
|
2014-08-22 05:14:59 -07:00
|
|
|
static void _ecore_con_client_flush(Ecore_Con_Client *obj);
|
2013-12-19 21:07:50 -08:00
|
|
|
|
|
|
|
static void _ecore_con_event_client_add_free(Ecore_Con_Server *svr,
|
|
|
|
void *ev);
|
|
|
|
static void _ecore_con_event_client_del_free(Ecore_Con_Server *svr,
|
|
|
|
void *ev);
|
|
|
|
static void _ecore_con_event_client_data_free(Ecore_Con_Server *svr,
|
|
|
|
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_event_server_error_free(void *data,
|
|
|
|
Ecore_Con_Event_Server_Error *e);
|
|
|
|
static void _ecore_con_event_client_error_free(Ecore_Con_Server *svr,
|
|
|
|
Ecore_Con_Event_Client_Error *e);
|
|
|
|
static void _ecore_con_event_server_write_free(void *data,
|
|
|
|
Ecore_Con_Event_Server_Write *e);
|
|
|
|
static void _ecore_con_event_client_write_free(Ecore_Con_Server *svr,
|
|
|
|
Ecore_Con_Event_Client_Write *e);
|
|
|
|
|
|
|
|
static void _ecore_con_lookup_done(void *data,
|
|
|
|
Ecore_Con_Info *infos);
|
|
|
|
|
|
|
|
static const char *_ecore_con_pretty_ip(struct sockaddr *client_addr);
|
2010-11-16 13:32:50 -08:00
|
|
|
|
2014-08-28 06:17:16 -07:00
|
|
|
#define EO_CONSTRUCTOR_CHECK_RETURN(obj) do { \
|
2016-08-10 07:23:04 -07:00
|
|
|
if (efl_finalized_get(obj)) \
|
2014-08-28 06:17:16 -07:00
|
|
|
{ \
|
|
|
|
ERR("This function is only allowed during construction."); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2013-03-09 22:49:54 -08:00
|
|
|
#ifdef HAVE_SYSTEMD
|
|
|
|
int sd_fd_index = 0;
|
|
|
|
int sd_fd_max = 0;
|
|
|
|
#endif
|
2011-12-21 02:13:57 -08:00
|
|
|
|
2012-01-19 00:02:41 -08:00
|
|
|
void
|
2014-08-22 05:14:59 -07:00
|
|
|
_ecore_con_client_kill(Ecore_Con_Client *obj)
|
2011-12-21 02:13:57 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Client_Data *cl = efl_data_scope_get(obj, EFL_NETWORK_CLIENT_CLASS);
|
2011-12-21 02:13:57 -08:00
|
|
|
if (cl->delete_me)
|
|
|
|
DBG("Multi kill request for client %p", cl);
|
|
|
|
else
|
2012-02-22 00:50:43 -08:00
|
|
|
{
|
2014-08-22 05:14:59 -07:00
|
|
|
ecore_con_event_client_del(obj);
|
2012-02-22 00:50:43 -08:00
|
|
|
if (cl->buf) return;
|
|
|
|
}
|
2011-12-21 02:13:57 -08:00
|
|
|
INF("Lost client %s", (cl->ip) ? cl->ip : "");
|
|
|
|
if (cl->fd_handler)
|
2012-06-06 02:49:24 -07:00
|
|
|
ecore_main_fd_handler_del(cl->fd_handler);
|
|
|
|
|
|
|
|
cl->fd_handler = NULL;
|
2011-12-21 02:13:57 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_server_kill(Ecore_Con_Server *obj)
|
2011-12-21 02:13:57 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2011-12-21 02:13:57 -08:00
|
|
|
if (svr->delete_me)
|
|
|
|
DBG("Multi kill request for svr %p", svr);
|
|
|
|
else
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_event_server_del(obj);
|
2011-12-21 02:13:57 -08:00
|
|
|
|
|
|
|
if (svr->fd_handler)
|
2012-06-06 02:49:24 -07:00
|
|
|
ecore_main_fd_handler_del(svr->fd_handler);
|
|
|
|
|
|
|
|
svr->fd_handler = NULL;
|
2011-12-21 02:13:57 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define _ecore_con_server_kill(svr) do { \
|
2013-12-19 21:07:50 -08:00
|
|
|
DBG("KILL %p", (svr)); \
|
|
|
|
_ecore_con_server_kill((svr)); \
|
|
|
|
} while (0)
|
2011-12-21 02:13:57 -08:00
|
|
|
|
2013-12-19 21:07:50 -08:00
|
|
|
#define _ecore_con_client_kill(cl) do { \
|
|
|
|
DBG("KILL %p", (cl)); \
|
|
|
|
_ecore_con_client_kill((cl)); \
|
|
|
|
} while (0)
|
2011-12-21 02:13:57 -08: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;
|
2011-09-13 16:03:26 -07:00
|
|
|
EAPI int ECORE_CON_EVENT_CLIENT_WRITE = 0;
|
|
|
|
EAPI int ECORE_CON_EVENT_SERVER_WRITE = 0;
|
2011-02-10 00:49:23 -08:00
|
|
|
EAPI int ECORE_CON_EVENT_CLIENT_ERROR = 0;
|
|
|
|
EAPI int ECORE_CON_EVENT_SERVER_ERROR = 0;
|
2011-12-05 19:32:16 -08:00
|
|
|
EAPI int ECORE_CON_EVENT_PROXY_BIND = 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;
|
2011-11-10 18:44:16 -08:00
|
|
|
static int _ecore_con_event_count = 0;
|
2009-12-21 09:32:19 -08:00
|
|
|
int _ecore_con_log_dom = -1;
|
2011-12-05 19:32:16 -08:00
|
|
|
Ecore_Con_Socks *_ecore_con_proxy_once = NULL;
|
|
|
|
Ecore_Con_Socks *_ecore_con_proxy_global = NULL;
|
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-01-14 23:44:27 -08:00
|
|
|
#endif
|
|
|
|
|
2009-10-09 22:28:43 -07:00
|
|
|
if (!ecore_init())
|
2015-02-05 02:26:58 -08:00
|
|
|
goto ecore_err;
|
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);
|
2010-11-05 18:22:50 -07:00
|
|
|
if (_ecore_con_log_dom < 0)
|
2015-02-05 02:26:58 -08:00
|
|
|
goto ecore_con_log_error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2011-11-06 04:26:00 -08:00
|
|
|
ecore_con_mempool_init();
|
|
|
|
|
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();
|
2011-09-13 16:03:26 -07:00
|
|
|
ECORE_CON_EVENT_CLIENT_WRITE = ecore_event_type_new();
|
|
|
|
ECORE_CON_EVENT_SERVER_WRITE = ecore_event_type_new();
|
2011-02-10 00:49:23 -08:00
|
|
|
ECORE_CON_EVENT_CLIENT_ERROR = ecore_event_type_new();
|
|
|
|
ECORE_CON_EVENT_SERVER_ERROR = ecore_event_type_new();
|
2011-12-05 19:32:16 -08:00
|
|
|
ECORE_CON_EVENT_PROXY_BIND = ecore_event_type_new();
|
2004-03-31 08:47:45 -08:00
|
|
|
|
2010-11-06 10:04:09 -07:00
|
|
|
eina_magic_string_set(ECORE_MAGIC_CON_SERVER, "Ecore_Con_Server");
|
2012-06-22 05:17:59 -07:00
|
|
|
eina_magic_string_set(ECORE_MAGIC_CON_CLIENT, "Ecore_Con_Client");
|
2010-11-06 10:04:09 -07:00
|
|
|
eina_magic_string_set(ECORE_MAGIC_CON_URL, "Ecore_Con_Url");
|
|
|
|
|
2005-09-07 02:06:06 -07:00
|
|
|
/* TODO Remember return value, if it fails, use gethostbyname() */
|
2011-12-05 19:32:16 -08:00
|
|
|
ecore_con_socks_init();
|
2008-10-30 08:26:11 -07:00
|
|
|
ecore_con_ssl_init();
|
2008-10-09 05:30:19 -07:00
|
|
|
ecore_con_info_init();
|
2015-03-06 06:52:43 -08:00
|
|
|
ecore_con_local_init();
|
2005-09-07 02:06:06 -07:00
|
|
|
|
2013-03-09 22:49:54 -08:00
|
|
|
#ifdef HAVE_SYSTEMD
|
|
|
|
sd_fd_max = sd_listen_fds(0);
|
|
|
|
#endif
|
|
|
|
|
2013-03-27 05:42:55 -07:00
|
|
|
eina_log_timing(_ecore_con_log_dom,
|
2013-12-19 21:07:50 -08:00
|
|
|
EINA_LOG_STATE_STOP,
|
|
|
|
EINA_LOG_STATE_INIT);
|
2013-03-27 05:42:55 -07:00
|
|
|
|
2009-10-09 22:28:43 -07:00
|
|
|
return _ecore_con_init_count;
|
2015-02-05 02:26:58 -08:00
|
|
|
|
|
|
|
ecore_con_log_error:
|
|
|
|
EINA_LOG_ERR("Failed to create a log domain for Ecore Con.");
|
|
|
|
ecore_shutdown();
|
|
|
|
|
|
|
|
ecore_err:
|
|
|
|
#ifdef HAVE_EVIL
|
|
|
|
evil_shutdown();
|
|
|
|
#endif
|
|
|
|
return --_ecore_con_init_count;
|
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)
|
|
|
|
{
|
2010-11-11 12:34:35 -08:00
|
|
|
Eina_List *l, *l2;
|
2014-08-22 08:06:27 -07:00
|
|
|
Ecore_Con_Server *obj;
|
2011-04-20 07:15:33 -07:00
|
|
|
|
2014-10-29 05:24:53 -07:00
|
|
|
/* _ecore_con_init_count should not go below zero. */
|
|
|
|
if (_ecore_con_init_count < 1)
|
|
|
|
{
|
|
|
|
ERR("Ecore_Con Shutdown called without calling Ecore_Con Init.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
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
|
|
|
|
2013-03-27 05:42:55 -07:00
|
|
|
eina_log_timing(_ecore_con_log_dom,
|
2013-12-19 21:07:50 -08:00
|
|
|
EINA_LOG_STATE_START,
|
|
|
|
EINA_LOG_STATE_SHUTDOWN);
|
2013-03-27 05:42:55 -07:00
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
EINA_LIST_FOREACH_SAFE(servers, l, l2, obj)
|
2011-11-10 18:44:16 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2011-11-10 18:44:16 -08:00
|
|
|
Ecore_Con_Event_Server_Add *ev;
|
|
|
|
|
2015-06-24 21:18:22 -07:00
|
|
|
if (!svr) continue;
|
2011-12-21 02:02:30 -08:00
|
|
|
svr->delete_me = EINA_TRUE;
|
2011-12-02 19:50:20 -08:00
|
|
|
INF("svr %p is dead", svr);
|
2011-11-10 18:44:16 -08:00
|
|
|
/* some pointer hacks here to prevent double frees if people are being stupid */
|
|
|
|
EINA_LIST_FREE(svr->event_count, ev)
|
|
|
|
ev->server = NULL;
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_server_free(obj);
|
2011-11-10 18:44:16 -08:00
|
|
|
}
|
2005-09-07 02:06:06 -07:00
|
|
|
|
2011-12-05 19:32:16 -08:00
|
|
|
ecore_con_socks_shutdown();
|
2011-11-10 18:44:16 -08:00
|
|
|
if (!_ecore_con_event_count) ecore_con_mempool_shutdown();
|
2011-11-06 04:26:00 -08:00
|
|
|
|
2015-03-06 06:52:43 -08:00
|
|
|
ecore_con_local_shutdown();
|
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
|
|
|
|
2014-08-22 03:11:41 -07:00
|
|
|
EOLIAN static Eina_Bool
|
2016-05-11 05:00:57 -07:00
|
|
|
_efl_network_lookup(Eo *kls_obj EINA_UNUSED, void *pd EINA_UNUSED, const char *name, Ecore_Con_Dns_Cb done_cb, const void *data)
|
2010-09-20 23:49:07 -07:00
|
|
|
{
|
2014-08-22 08:06:27 -07:00
|
|
|
Ecore_Con_Server *obj;
|
2010-09-20 23:49:07 -07:00
|
|
|
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
|
|
|
|
2016-09-05 08:57:35 -07:00
|
|
|
obj = efl_add(EFL_NETWORK_CONNECTOR_CLASS, NULL, efl_network_server_connection_type_set(efl_added, ECORE_CON_REMOTE_TCP), efl_network_server_name_set(efl_added, name), efl_network_port_set(efl_added, 1025));
|
2010-09-20 23:49:07 -07:00
|
|
|
|
|
|
|
lk = malloc(sizeof (Ecore_Con_Lookup));
|
|
|
|
if (!lk)
|
|
|
|
{
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
lk->done_cb = done_cb;
|
|
|
|
lk->data = data;
|
|
|
|
|
2014-08-28 06:17:16 -07:00
|
|
|
ecore_con_server_data_set(obj, lk);
|
2010-09-20 23:49:07 -07:00
|
|
|
|
|
|
|
memset(&hints, 0, sizeof(struct addrinfo));
|
2011-07-04 13:04:18 -07:00
|
|
|
hints.ai_family = AF_UNSPEC;
|
2010-09-20 23:49:07 -07:00
|
|
|
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;
|
|
|
|
|
2014-08-28 06:17:16 -07:00
|
|
|
if (ecore_con_info_get(obj, _ecore_con_lookup_done, obj,
|
2010-09-20 23:49:07 -07:00
|
|
|
&hints))
|
2010-11-03 10:58:37 -07:00
|
|
|
return EINA_TRUE;
|
2010-09-20 23:49:07 -07:00
|
|
|
|
|
|
|
free(lk);
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_del(obj);
|
2010-09-20 23:49:07 -07:00
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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,
|
2013-12-19 21:07:50 -08:00
|
|
|
const char *name,
|
|
|
|
int port,
|
|
|
|
const void *data)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2014-08-22 08:06:27 -07:00
|
|
|
Ecore_Con_Server *obj;
|
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] */
|
2016-09-05 08:57:35 -07:00
|
|
|
obj = efl_add(EFL_NETWORK_SERVER_CLASS, NULL, efl_network_server_connection_type_set(efl_added, compl_type), efl_network_server_name_set(efl_added, name), efl_network_port_set(efl_added, port));
|
2014-08-28 06:17:16 -07:00
|
|
|
|
|
|
|
ecore_con_server_data_set(obj, (void *) data);
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2015-05-19 03:41:27 -07:00
|
|
|
EOLIAN static Eo *
|
2016-08-10 07:23:04 -07:00
|
|
|
_efl_network_server_efl_object_constructor(Ecore_Con_Server *obj, Efl_Network_Server_Data *svr)
|
2014-08-28 06:17:16 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
obj = efl_constructor(efl_super(obj, EFL_NETWORK_SERVER_CLASS));
|
2003-09-23 01:09:32 -07:00
|
|
|
|
2014-08-11 04:48:03 -07:00
|
|
|
svr->fd = -1;
|
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;
|
2015-05-19 03:41:27 -07:00
|
|
|
|
|
|
|
return obj;
|
2014-08-28 06:17:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static Eo *
|
2016-08-10 07:23:04 -07:00
|
|
|
_efl_network_server_efl_object_finalize(Ecore_Con_Server *obj, Efl_Network_Server_Data *svr)
|
2014-08-28 06:17:16 -07:00
|
|
|
{
|
|
|
|
Ecore_Con_Type compl_type = svr->type;
|
|
|
|
Ecore_Con_Type type;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_finalize(efl_super(obj, EFL_NETWORK_SERVER_CLASS));
|
2014-08-28 06:17:16 -07:00
|
|
|
|
|
|
|
svr->created = EINA_TRUE;
|
2008-10-09 05:30:19 -07:00
|
|
|
svr->ppid = getpid();
|
2014-08-28 06:17:16 -07:00
|
|
|
svr->start_time = ecore_time_get();
|
|
|
|
svr->use_cert = (svr->type & ECORE_CON_SSL & ECORE_CON_LOAD_CERT) == ECORE_CON_LOAD_CERT;
|
2014-08-11 04:48:03 -07:00
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
servers = eina_list_append(servers, obj);
|
2014-08-12 16:44:44 -07:00
|
|
|
|
2015-03-06 07:26:24 -08:00
|
|
|
if (!svr->name)
|
2014-08-11 04:48:03 -07:00
|
|
|
goto error;
|
|
|
|
|
2015-03-07 06:53:40 -08:00
|
|
|
type = compl_type & ECORE_CON_TYPE;
|
|
|
|
|
2015-03-06 07:26:24 -08:00
|
|
|
EINA_SAFETY_ON_TRUE_GOTO(((type == ECORE_CON_REMOTE_TCP) ||
|
|
|
|
(type == ECORE_CON_REMOTE_NODELAY) ||
|
|
|
|
(type == ECORE_CON_REMOTE_CORK) ||
|
|
|
|
(type == ECORE_CON_REMOTE_UDP) ||
|
|
|
|
(type == ECORE_CON_REMOTE_BROADCAST)) &&
|
|
|
|
(svr->port < 0), error);
|
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
if (ecore_con_ssl_server_prepare(obj, compl_type & ECORE_CON_SSL))
|
2010-09-18 12:29:43 -07:00
|
|
|
goto error;
|
2008-10-09 05:30:19 -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))
|
2013-12-19 21:07:50 -08:00
|
|
|
/* Local */
|
2011-05-14 10:52:30 -07:00
|
|
|
#ifdef _WIN32
|
2014-08-22 08:06:27 -07:00
|
|
|
if (!ecore_con_local_listen(obj))
|
2011-05-14 10:52:30 -07:00
|
|
|
goto error;
|
|
|
|
#else
|
2014-08-22 08:06:27 -07:00
|
|
|
if (!ecore_con_local_listen(obj, _ecore_con_svr_tcp_handler, obj))
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2011-05-14 10:52:30 -07:00
|
|
|
#endif
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if ((type == ECORE_CON_REMOTE_TCP) ||
|
2011-12-10 00:14:50 -08:00
|
|
|
(type == ECORE_CON_REMOTE_NODELAY) ||
|
|
|
|
(type == ECORE_CON_REMOTE_CORK))
|
2008-09-17 08:08:48 -07:00
|
|
|
{
|
2008-10-09 05:30:19 -07:00
|
|
|
/* TCP */
|
2014-08-22 08:06:27 -07:00
|
|
|
if (!ecore_con_info_tcp_listen(obj, _ecore_con_cb_tcp_listen,
|
|
|
|
obj))
|
2013-12-19 21:07:50 -08: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 */
|
2014-08-22 08:06:27 -07:00
|
|
|
if (!ecore_con_info_udp_listen(obj, _ecore_con_cb_udp_listen,
|
|
|
|
obj))
|
2010-11-03 10:58:37 -07:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
return obj;
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
error:
|
2014-08-11 04:48:03 -07:00
|
|
|
if (svr->delete_me) return NULL;
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_server_kill(obj);
|
2003-09-23 01:09:32 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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,
|
2013-12-19 21:07:50 -08:00
|
|
|
const char *name,
|
|
|
|
int port,
|
|
|
|
const void *data)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2014-08-22 08:06:27 -07:00
|
|
|
Ecore_Con_Server *obj;
|
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] */
|
2016-09-05 08:57:35 -07:00
|
|
|
obj = efl_add(EFL_NETWORK_CONNECTOR_CLASS, NULL, efl_network_server_connection_type_set(efl_added, compl_type), efl_network_server_name_set(efl_added, name), efl_network_port_set(efl_added, port));
|
2014-08-28 06:17:16 -07:00
|
|
|
|
|
|
|
ecore_con_server_data_set(obj, (void *) data);
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static Eo *
|
2016-08-10 07:23:04 -07:00
|
|
|
_efl_network_connector_efl_object_finalize(Ecore_Con_Server *obj, void *pd EINA_UNUSED)
|
2014-08-28 06:17:16 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2014-08-28 06:17:16 -07:00
|
|
|
Ecore_Con_Type compl_type = svr->type;
|
|
|
|
Ecore_Con_Type type;
|
|
|
|
|
|
|
|
/* XXX: We intentionally put SERVER class here and not connector, as we'd
|
|
|
|
* like to skip that one. */
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_finalize(efl_super(obj, EFL_NETWORK_SERVER_CLASS));
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2011-12-10 00:09:17 -08:00
|
|
|
svr->use_cert = (compl_type & ECORE_CON_SSL & ECORE_CON_LOAD_CERT) == ECORE_CON_LOAD_CERT;
|
2012-06-04 02:16:19 -07:00
|
|
|
svr->disable_proxy = (compl_type & ECORE_CON_SUPER_SSL & ECORE_CON_NO_PROXY) == ECORE_CON_NO_PROXY;
|
2014-08-22 08:06:27 -07:00
|
|
|
servers = eina_list_append(servers, obj);
|
2014-08-12 16:44:44 -07:00
|
|
|
|
2014-08-28 06:17:16 -07:00
|
|
|
if (!svr->name || !(svr->name[0]))
|
2014-08-11 04:48:03 -07:00
|
|
|
goto error;
|
|
|
|
|
2008-10-09 05:30:19 -07:00
|
|
|
type = compl_type & ECORE_CON_TYPE;
|
|
|
|
|
2012-06-04 02:03:04 -07:00
|
|
|
if ((!svr->disable_proxy) && (type > ECORE_CON_LOCAL_ABSTRACT))
|
2011-12-05 19:32:16 -08:00
|
|
|
{
|
|
|
|
/* never use proxies on local connections */
|
|
|
|
if (_ecore_con_proxy_once)
|
|
|
|
svr->ecs = _ecore_con_proxy_once;
|
|
|
|
else if (_ecore_con_proxy_global)
|
|
|
|
svr->ecs = _ecore_con_proxy_global;
|
|
|
|
_ecore_con_proxy_once = NULL;
|
|
|
|
if (svr->ecs)
|
|
|
|
{
|
|
|
|
if ((!svr->ecs->lookup) &&
|
|
|
|
(!ecore_con_lookup(svr->name, (Ecore_Con_Dns_Cb)ecore_con_socks_dns_cb, svr)))
|
|
|
|
goto error;
|
|
|
|
if (svr->ecs->lookup)
|
2012-02-14 21:53:50 -08:00
|
|
|
svr->ecs_state = ECORE_CON_PROXY_STATE_RESOLVED;
|
2011-12-05 19:32:16 -08:00
|
|
|
}
|
|
|
|
}
|
2014-08-22 08:06:27 -07:00
|
|
|
EINA_SAFETY_ON_TRUE_GOTO(ecore_con_ssl_server_prepare(obj, compl_type & ECORE_CON_SSL), error);
|
2011-12-05 19:32:16 -08:00
|
|
|
|
2012-06-28 01:51:06 -07:00
|
|
|
EINA_SAFETY_ON_TRUE_GOTO(((type == ECORE_CON_REMOTE_TCP) ||
|
2013-12-19 21:07:50 -08:00
|
|
|
(type == ECORE_CON_REMOTE_NODELAY) ||
|
|
|
|
(type == ECORE_CON_REMOTE_CORK) ||
|
|
|
|
(type == ECORE_CON_REMOTE_UDP) ||
|
|
|
|
(type == ECORE_CON_REMOTE_BROADCAST)) &&
|
2015-03-06 07:26:24 -08:00
|
|
|
(svr->port < 0), 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))
|
2013-12-19 21:07:50 -08:00
|
|
|
/* Local */
|
2011-05-14 10:52:30 -07:00
|
|
|
#ifdef _WIN32
|
2014-08-22 08:06:27 -07:00
|
|
|
if (!ecore_con_local_connect(obj, _ecore_con_cl_handler)) goto error;
|
2011-05-14 10:52:30 -07:00
|
|
|
#else
|
2014-08-22 08:06:27 -07:00
|
|
|
if (!ecore_con_local_connect(obj, _ecore_con_cl_handler, obj)) goto error;
|
2011-05-14 10:52:30 -07:00
|
|
|
#endif
|
2004-03-31 08:47:45 -08:00
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
if ((type == ECORE_CON_REMOTE_TCP) ||
|
2011-12-10 00:14:50 -08:00
|
|
|
(type == ECORE_CON_REMOTE_NODELAY) ||
|
|
|
|
(type == ECORE_CON_REMOTE_CORK))
|
2006-01-19 01:11:30 -08:00
|
|
|
{
|
2008-10-09 05:30:19 -07:00
|
|
|
/* TCP */
|
2014-08-22 08:06:27 -07:00
|
|
|
EINA_SAFETY_ON_FALSE_GOTO(ecore_con_info_tcp_connect(obj, _ecore_con_cb_tcp_connect, obj), error);
|
2006-01-19 01:11:30 -08:00
|
|
|
}
|
2012-06-28 01:51:06 -07:00
|
|
|
else if ((type == ECORE_CON_REMOTE_UDP) || (type == ECORE_CON_REMOTE_BROADCAST))
|
2010-11-03 10:58:37 -07:00
|
|
|
/* UDP and MCAST */
|
2014-08-22 08:06:27 -07:00
|
|
|
EINA_SAFETY_ON_FALSE_GOTO(ecore_con_info_udp_connect(obj, _ecore_con_cb_udp_connect, obj), error);
|
2005-09-02 20:07:29 -07:00
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
return obj;
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
error:
|
2003-09-23 01:09:32 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-21 21:48:09 -07:00
|
|
|
EAPI void
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_server_timeout_set(Ecore_Con *obj, double timeout)
|
2010-09-21 21:48:09 -07:00
|
|
|
{
|
2016-05-11 05:00:57 -07:00
|
|
|
efl_network_timeout_set((Ecore_Con *)obj, timeout);
|
2014-08-22 08:06:27 -07:00
|
|
|
}
|
2010-09-21 21:48:09 -07:00
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
EOLIAN static void
|
2016-05-11 05:00:57 -07:00
|
|
|
_efl_network_server_efl_network_timeout_set(Eo *obj, Efl_Network_Server_Data *svr, double timeout)
|
2014-08-22 08:06:27 -07:00
|
|
|
{
|
2011-06-17 04:16:50 -07:00
|
|
|
if (svr->created)
|
|
|
|
svr->client_disconnect_time = timeout;
|
|
|
|
else
|
|
|
|
svr->disconnect_time = timeout;
|
2013-07-17 07:20:45 -07:00
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_server_timer_update(obj);
|
2010-09-21 21:48:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI double
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_server_timeout_get(const Ecore_Con *obj)
|
2010-09-21 21:48:09 -07:00
|
|
|
{
|
2016-05-11 05:00:57 -07:00
|
|
|
return efl_network_timeout_get((Ecore_Con *)obj);
|
2014-08-22 08:06:27 -07:00
|
|
|
}
|
2010-09-21 21:48:09 -07:00
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
EOLIAN static double
|
2016-05-11 05:00:57 -07:00
|
|
|
_efl_network_server_efl_network_timeout_get(Eo *obj EINA_UNUSED, Efl_Network_Server_Data *svr)
|
2014-08-22 08:06:27 -07:00
|
|
|
{
|
2011-06-17 04:16:50 -07:00
|
|
|
return svr->created ? svr->client_disconnect_time : svr->disconnect_time;
|
2010-09-21 21:48:09 -07:00
|
|
|
}
|
|
|
|
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI void *
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_server_del(Ecore_Con_Server *obj)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2014-08-22 08:06:27 -07:00
|
|
|
if (!obj) return NULL;
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2014-10-07 07:28:17 -07:00
|
|
|
if (!svr || 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
|
|
|
|
2015-01-30 05:16:59 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
WSASendDisconnect(svr->fd, NULL);
|
|
|
|
#endif
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_server_kill(obj);
|
2011-12-09 21:42:32 -08:00
|
|
|
return svr->data;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI void *
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_server_data_get(Ecore_Con_Server *obj)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2014-08-22 08:06:27 -07:00
|
|
|
if (!svr)
|
|
|
|
return NULL;
|
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
|
|
|
EAPI void *
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_server_data_set(Ecore_Con_Server *obj,
|
2013-12-19 21:07:50 -08:00
|
|
|
void *data)
|
2010-07-28 17:27:15 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2014-10-07 07:28:17 -07:00
|
|
|
void *ret = NULL;
|
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
if (!svr)
|
|
|
|
return NULL;
|
2010-07-28 17:27:15 -07:00
|
|
|
|
|
|
|
ret = svr->data;
|
|
|
|
svr->data = data;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-09-20 18:48:46 -07:00
|
|
|
EAPI Eina_Bool
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_server_connected_get(const Ecore_Con *obj)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2016-05-11 05:00:57 -07:00
|
|
|
return efl_network_connected_get((Ecore_Con *)obj);
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
EOLIAN static Eina_Bool
|
2016-05-11 05:00:57 -07:00
|
|
|
_efl_network_server_efl_network_connected_get(Eo *obj EINA_UNUSED, Efl_Network_Server_Data *svr)
|
2006-03-29 22:48:45 -08:00
|
|
|
{
|
2014-08-22 08:06:27 -07:00
|
|
|
return !svr->connecting;
|
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2016-01-12 22:19:07 -08:00
|
|
|
EOLIAN static const Eina_List *
|
2016-02-04 23:09:53 -08:00
|
|
|
_efl_network_server_clients_get(Eo *obj EINA_UNUSED, Efl_Network_Server_Data *svr)
|
2014-08-22 08:06:27 -07:00
|
|
|
{
|
2006-03-29 22:48:45 -08:00
|
|
|
return svr->clients;
|
|
|
|
}
|
|
|
|
|
2014-08-28 06:17:16 -07:00
|
|
|
EOLIAN static void
|
2016-02-04 23:09:53 -08:00
|
|
|
_efl_network_server_connection_type_set(Eo *obj, Efl_Network_Server_Data *svr, Ecore_Con_Type type)
|
2014-08-28 06:17:16 -07:00
|
|
|
{
|
|
|
|
EO_CONSTRUCTOR_CHECK_RETURN(obj);
|
|
|
|
|
|
|
|
svr->type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static Ecore_Con_Type
|
2016-02-04 23:09:53 -08:00
|
|
|
_efl_network_server_connection_type_get(Eo *obj EINA_UNUSED, Efl_Network_Server_Data *svr)
|
2014-08-28 06:17:16 -07:00
|
|
|
{
|
|
|
|
return svr->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static void
|
2016-02-04 23:09:53 -08:00
|
|
|
_efl_network_server_name_set(Eo *obj EINA_UNUSED, Efl_Network_Server_Data *svr, const char *name)
|
2014-08-28 06:17:16 -07:00
|
|
|
{
|
|
|
|
EO_CONSTRUCTOR_CHECK_RETURN(obj);
|
|
|
|
|
|
|
|
if (svr->name)
|
|
|
|
free(svr->name);
|
|
|
|
|
|
|
|
svr->name = strdup(name);
|
|
|
|
}
|
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
EOLIAN static const char *
|
2016-02-04 23:09:53 -08:00
|
|
|
_efl_network_server_name_get(Eo *obj EINA_UNUSED, Efl_Network_Server_Data *svr)
|
2010-08-26 22:16:00 -07:00
|
|
|
{
|
|
|
|
return svr->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI int
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_server_port_get(const Ecore_Con *obj)
|
|
|
|
{
|
2016-05-11 05:00:57 -07:00
|
|
|
return efl_network_port_get((Ecore_Con *)obj);
|
2014-08-22 08:06:27 -07:00
|
|
|
}
|
|
|
|
|
2014-08-28 06:17:16 -07:00
|
|
|
EOLIAN static void
|
2016-05-11 05:00:57 -07:00
|
|
|
_efl_network_server_efl_network_port_set(Eo *obj EINA_UNUSED, Efl_Network_Server_Data *svr, int port)
|
2014-08-28 06:17:16 -07:00
|
|
|
{
|
|
|
|
EO_CONSTRUCTOR_CHECK_RETURN(obj);
|
|
|
|
|
|
|
|
svr->port = port;
|
|
|
|
}
|
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
EOLIAN static int
|
2016-05-11 05:00:57 -07:00
|
|
|
_efl_network_server_efl_network_port_get(Eo *obj EINA_UNUSED, Efl_Network_Server_Data *svr)
|
2010-08-26 22:16:00 -07:00
|
|
|
{
|
|
|
|
return svr->port;
|
|
|
|
}
|
|
|
|
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI int
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_server_send(Ecore_Con *obj, const void *data, int size)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2016-05-11 05:00:57 -07:00
|
|
|
return efl_network_send((Ecore_Con *)obj, data, size);
|
2014-08-22 08:06:27 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
EOLIAN static int
|
2016-05-11 05:00:57 -07:00
|
|
|
_efl_network_server_efl_network_send(Eo *obj EINA_UNUSED, Efl_Network_Server_Data *svr, const void *data, int size)
|
2014-08-22 08:06:27 -07:00
|
|
|
{
|
2011-12-21 02:02:30 -08:00
|
|
|
EINA_SAFETY_ON_TRUE_RETURN_VAL(svr->delete_me, 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
|
|
|
|
2011-07-16 06:07:39 -07:00
|
|
|
if (!svr->buf)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2011-07-16 06:07:39 -07:00
|
|
|
svr->buf = eina_binbuf_new();
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(svr->buf, 0);
|
2011-12-10 00:14:50 -08:00
|
|
|
#ifdef TCP_CORK
|
|
|
|
if ((svr->fd >= 0) && ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK))
|
|
|
|
{
|
|
|
|
int state = 1;
|
|
|
|
if (setsockopt(svr->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
|
|
|
|
/* realistically this isn't anything serious so we can just log and continue */
|
|
|
|
ERR("corking failed! %s", strerror(errno));
|
|
|
|
}
|
|
|
|
#endif
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
2014-04-04 03:35:16 -07:00
|
|
|
if (!eina_binbuf_append_length(svr->buf, data, size))
|
|
|
|
ERR("eina_binbuf_append_length() failed");
|
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
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
EOLIAN static void
|
2016-02-04 23:09:53 -08:00
|
|
|
_efl_network_server_client_limit_set(Eo *obj EINA_UNUSED, Efl_Network_Server_Data *svr,
|
2013-12-19 21:07:50 -08:00
|
|
|
int client_limit,
|
|
|
|
char reject_excess_clients)
|
2005-04-28 21:51:31 -07:00
|
|
|
{
|
|
|
|
svr->client_limit = client_limit;
|
|
|
|
svr->reject_excess_clients = reject_excess_clients;
|
|
|
|
}
|
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
EOLIAN static void
|
2016-02-04 23:09:53 -08:00
|
|
|
_efl_network_server_client_limit_get(Eo *obj EINA_UNUSED, Efl_Network_Server_Data *svr,
|
2014-08-22 08:06:27 -07:00
|
|
|
int *client_limit,
|
|
|
|
char *reject_excess_clients)
|
|
|
|
{
|
|
|
|
if (client_limit) *client_limit = svr->client_limit;
|
|
|
|
if (reject_excess_clients) *reject_excess_clients = svr->reject_excess_clients;
|
|
|
|
}
|
|
|
|
|
2010-07-28 15:32:39 -07:00
|
|
|
EAPI const char *
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_server_ip_get(const Ecore_Con *obj)
|
2006-03-19 23:45:58 -08:00
|
|
|
{
|
2016-05-11 05:00:57 -07:00
|
|
|
return efl_network_ip_get(obj);
|
2014-08-22 08:06:27 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
EOLIAN static const char *
|
2016-05-11 05:00:57 -07:00
|
|
|
_efl_network_server_efl_network_ip_get(Eo *obj EINA_UNUSED, Efl_Network_Server_Data *svr)
|
2014-08-22 08:06:27 -07:00
|
|
|
{
|
2006-03-19 23:45:58 -08:00
|
|
|
return svr->ip;
|
|
|
|
}
|
|
|
|
|
2010-09-21 21:48:09 -07:00
|
|
|
EAPI double
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_server_uptime_get(const Ecore_Con *obj)
|
2010-09-21 21:48:09 -07:00
|
|
|
{
|
2016-05-11 05:00:57 -07:00
|
|
|
return efl_network_uptime_get(obj);
|
2014-08-22 08:06:27 -07:00
|
|
|
}
|
2010-09-21 21:48:09 -07:00
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
EOLIAN static double
|
2016-05-11 05:00:57 -07:00
|
|
|
_efl_network_server_efl_network_uptime_get(Eo *obj EINA_UNUSED, Efl_Network_Server_Data *svr)
|
2014-08-22 08:06:27 -07:00
|
|
|
{
|
2010-09-21 21:48:09 -07:00
|
|
|
return ecore_time_get() - svr->start_time;
|
|
|
|
}
|
2010-11-03 10:58:37 -07:00
|
|
|
|
2007-02-16 10:12:38 -08:00
|
|
|
EAPI void
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_server_flush(Ecore_Con *obj)
|
2007-02-16 10:12:38 -08:00
|
|
|
{
|
2016-05-11 05:00:57 -07:00
|
|
|
efl_network_flush((Ecore_Con *)obj);
|
2014-08-22 08:06:27 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
EOLIAN static void
|
2016-05-11 05:00:57 -07:00
|
|
|
_efl_network_server_efl_network_flush(Eo *obj, Efl_Network_Server_Data *svr EINA_UNUSED)
|
2014-08-22 08:06:27 -07:00
|
|
|
{
|
|
|
|
_ecore_con_server_flush(obj);
|
2007-02-16 10:12:38 -08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI int
|
2014-08-22 05:14:59 -07:00
|
|
|
ecore_con_client_send(Ecore_Con *obj, const void *data, int size)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2016-05-11 05:00:57 -07:00
|
|
|
return efl_network_send((Ecore_Con *)obj, data, size);
|
2014-08-22 05:14:59 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
EOLIAN static int
|
2016-05-11 05:00:57 -07:00
|
|
|
_efl_network_client_efl_network_send(Eo *obj EINA_UNUSED, Efl_Network_Client_Data *cl, const void *data, int size)
|
2014-08-22 05:14:59 -07:00
|
|
|
{
|
2016-02-04 23:09:53 -08:00
|
|
|
Efl_Network_Server_Data *host_server = NULL;
|
2011-12-21 02:02:30 -08:00
|
|
|
EINA_SAFETY_ON_TRUE_RETURN_VAL(cl->delete_me, 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
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
if (cl->host_server)
|
2016-08-15 06:44:41 -07:00
|
|
|
host_server = efl_data_scope_get(cl->host_server, EFL_NETWORK_CLIENT_CLASS);
|
2014-08-22 08:06:27 -07:00
|
|
|
|
|
|
|
|
|
|
|
if (cl->host_server && ((host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP))
|
2014-08-26 22:49:47 -07:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = (int)sendto(host_server->fd, data, size, 0,
|
|
|
|
(struct sockaddr *)cl->client_addr,
|
|
|
|
cl->client_addr_len);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
else
|
2008-10-09 05:30:19 -07:00
|
|
|
{
|
2014-01-03 09:57:56 -08:00
|
|
|
if (!cl->buf)
|
2011-12-10 00:14:50 -08:00
|
|
|
{
|
2014-01-03 09:57:56 -08:00
|
|
|
cl->buf = eina_binbuf_new();
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(cl->buf, 0);
|
|
|
|
#ifdef TCP_CORK
|
2014-09-04 01:57:19 -07:00
|
|
|
if ((cl->fd >= 0) && (host_server) &&
|
2014-08-27 01:16:17 -07:00
|
|
|
((host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK))
|
2014-01-03 09:57:56 -08:00
|
|
|
{
|
|
|
|
int state = 1;
|
|
|
|
if (setsockopt(cl->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
|
|
|
|
/* realistically this isn't anything serious so we can just log and continue */
|
|
|
|
ERR("corking failed! %s", strerror(errno));
|
|
|
|
}
|
2011-12-10 00:14:50 -08:00
|
|
|
#endif
|
2014-01-03 09:57:56 -08:00
|
|
|
}
|
2014-04-04 03:35:16 -07:00
|
|
|
if (!eina_binbuf_append_length(cl->buf, data, size))
|
|
|
|
ERR("eina_binbuf_append_length() failed");
|
2003-09-23 01:09:32 -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
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
EOLIAN static Ecore_Con_Server *
|
2016-02-12 12:02:01 -08:00
|
|
|
_efl_network_client_server_get(Eo *obj EINA_UNUSED, Efl_Network_Client_Data *cl)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2010-09-18 12:26:05 -07:00
|
|
|
return cl->host_server;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
EOLIAN static Eina_Bool
|
2016-05-11 05:00:57 -07:00
|
|
|
_efl_network_client_efl_network_connected_get(Eo *obj EINA_UNUSED, Efl_Network_Client_Data *cl)
|
2010-11-05 17:17:04 -07:00
|
|
|
{
|
2011-12-21 02:02:30 -08:00
|
|
|
return !cl->delete_me;
|
2010-11-05 17:17:04 -07:00
|
|
|
}
|
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
EAPI Eina_Bool
|
|
|
|
ecore_con_client_connected_get(const Ecore_Con *obj)
|
2010-09-21 21:48:09 -07:00
|
|
|
{
|
2016-05-11 05:00:57 -07:00
|
|
|
return efl_network_connected_get((Ecore_Con *)obj);
|
2014-08-22 05:14:59 -07:00
|
|
|
}
|
2010-09-21 21:48:09 -07:00
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
EOLIAN static void
|
2016-05-11 05:00:57 -07:00
|
|
|
_efl_network_client_efl_network_timeout_set(Eo *obj, Efl_Network_Client_Data *cl, double timeout)
|
2014-08-22 05:14:59 -07:00
|
|
|
{
|
2010-09-21 21:48:09 -07:00
|
|
|
cl->disconnect_time = timeout;
|
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
_ecore_con_cl_timer_update(obj);
|
2010-09-21 21:48:09 -07:00
|
|
|
}
|
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
EAPI void
|
|
|
|
ecore_con_client_timeout_set(Ecore_Con *obj, double timeout)
|
2010-09-21 21:48:09 -07:00
|
|
|
{
|
2016-05-11 05:00:57 -07:00
|
|
|
efl_network_timeout_set((Ecore_Con *)obj, timeout);
|
2014-08-22 05:14:59 -07:00
|
|
|
}
|
2010-09-21 21:48:09 -07:00
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
EOLIAN static double
|
2016-05-11 05:00:57 -07:00
|
|
|
_efl_network_client_efl_network_timeout_get(Eo *obj EINA_UNUSED, Efl_Network_Client_Data *cl)
|
2014-08-22 05:14:59 -07:00
|
|
|
{
|
2010-09-21 21:48:09 -07:00
|
|
|
return cl->disconnect_time;
|
|
|
|
}
|
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
EAPI double
|
|
|
|
ecore_con_client_timeout_get(const Ecore_Con *obj)
|
|
|
|
{
|
2016-05-11 05:00:57 -07:00
|
|
|
return efl_network_timeout_get((Ecore_Con *)obj);
|
2014-08-22 05:14:59 -07:00
|
|
|
}
|
|
|
|
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI void *
|
2014-08-22 05:14:59 -07:00
|
|
|
ecore_con_client_del(Ecore_Con_Client *obj)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2014-08-22 05:14:59 -07:00
|
|
|
if (!obj) return NULL;
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Client_Data *cl = efl_data_scope_get(obj, EFL_NETWORK_CLIENT_CLASS);
|
2012-12-24 01:35:56 -08:00
|
|
|
if (!cl) return NULL;
|
2012-05-24 00:49:30 -07:00
|
|
|
|
2015-01-30 05:16:59 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
WSASendDisconnect(cl->fd, NULL);
|
|
|
|
#endif
|
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
_ecore_con_client_kill(obj);
|
2012-06-06 02:49:24 -07:00
|
|
|
return cl->data;
|
2012-05-24 00:49:30 -07:00
|
|
|
}
|
|
|
|
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI void
|
2014-08-22 05:14:59 -07:00
|
|
|
ecore_con_client_data_set(Ecore_Con_Client *obj,
|
2013-12-19 21:07:50 -08:00
|
|
|
const void *data)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Client_Data *cl = efl_data_scope_get(obj, EFL_NETWORK_CLIENT_CLASS);
|
2014-08-22 05:14:59 -07:00
|
|
|
if (!cl)
|
|
|
|
return;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
cl->data = (void *)data;
|
|
|
|
}
|
|
|
|
|
2006-01-06 09:58:12 -08:00
|
|
|
EAPI void *
|
2014-08-22 05:14:59 -07:00
|
|
|
ecore_con_client_data_get(Ecore_Con_Client *obj)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Client_Data *cl = efl_data_scope_get(obj, EFL_NETWORK_CLIENT_CLASS);
|
2014-08-22 05:14:59 -07:00
|
|
|
if (!cl)
|
|
|
|
return NULL;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
return cl->data;
|
|
|
|
}
|
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
EOLIAN static const char *
|
2016-05-11 05:00:57 -07:00
|
|
|
_efl_network_client_efl_network_ip_get(Eo *obj EINA_UNUSED, Efl_Network_Client_Data *cl)
|
2006-03-19 23:45:58 -08:00
|
|
|
{
|
2010-11-16 13:32:50 -08:00
|
|
|
if (!cl->ip)
|
2011-09-29 14:05:20 -07:00
|
|
|
cl->ip = _ecore_con_pretty_ip(cl->client_addr);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2006-03-19 23:45:58 -08:00
|
|
|
return cl->ip;
|
|
|
|
}
|
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
EAPI const char *
|
|
|
|
ecore_con_client_ip_get(const Ecore_Con *obj)
|
|
|
|
{
|
2016-05-11 05:00:57 -07:00
|
|
|
return efl_network_ip_get(obj);
|
2014-08-22 05:14:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static int
|
2016-05-11 05:00:57 -07:00
|
|
|
_efl_network_client_efl_network_port_get(Eo *obj EINA_UNUSED, Efl_Network_Client_Data *cl)
|
2011-02-10 23:38:27 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *sd = efl_data_scope_get(cl->host_server, EFL_NETWORK_SERVER_CLASS);
|
2015-05-14 09:19:57 -07:00
|
|
|
|
|
|
|
if (sd->type != ECORE_CON_REMOTE_TCP &&
|
|
|
|
sd->type != ECORE_CON_REMOTE_MCAST &&
|
|
|
|
sd->type != ECORE_CON_REMOTE_UDP &&
|
|
|
|
sd->type != ECORE_CON_REMOTE_BROADCAST &&
|
|
|
|
sd->type != ECORE_CON_REMOTE_NODELAY)
|
|
|
|
return -1;
|
|
|
|
|
2011-02-10 23:38:27 -08:00
|
|
|
if (cl->client_addr->sa_family == AF_INET)
|
2013-12-19 21:07:50 -08:00
|
|
|
return ((struct sockaddr_in *)cl->client_addr)->sin_port;
|
2011-09-29 14:04:54 -07:00
|
|
|
#ifdef HAVE_IPV6
|
2013-12-19 21:07:50 -08:00
|
|
|
return ((struct sockaddr_in6 *)cl->client_addr)->sin6_port;
|
2011-09-29 14:04:54 -07:00
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
2011-02-10 23:38:27 -08:00
|
|
|
}
|
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
EAPI int
|
|
|
|
ecore_con_client_port_get(const Ecore_Con *obj)
|
2010-09-21 21:48:09 -07:00
|
|
|
{
|
2016-05-11 05:00:57 -07:00
|
|
|
return efl_network_port_get((Ecore_Con *)obj);
|
2014-08-22 05:14:59 -07:00
|
|
|
}
|
2010-09-21 21:48:09 -07:00
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
EOLIAN static double
|
2016-05-11 05:00:57 -07:00
|
|
|
_efl_network_client_efl_network_uptime_get(Eo *obj EINA_UNUSED, Efl_Network_Client_Data *cl)
|
2014-08-22 05:14:59 -07:00
|
|
|
{
|
2010-09-21 21:48:09 -07:00
|
|
|
return ecore_time_get() - cl->start_time;
|
|
|
|
}
|
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
EAPI double
|
|
|
|
ecore_con_client_uptime_get(const Ecore_Con *obj)
|
2007-02-16 10:12:38 -08:00
|
|
|
{
|
2016-05-11 05:00:57 -07:00
|
|
|
return efl_network_uptime_get(obj);
|
2014-08-22 05:14:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static void
|
2016-05-11 05:00:57 -07:00
|
|
|
_efl_network_client_efl_network_flush(Eo *obj, Efl_Network_Client_Data *cl EINA_UNUSED)
|
2014-08-22 05:14:59 -07:00
|
|
|
{
|
|
|
|
_ecore_con_client_flush(obj);
|
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
EAPI void
|
|
|
|
ecore_con_client_flush(Ecore_Con *obj)
|
|
|
|
{
|
2016-05-11 05:00:57 -07:00
|
|
|
efl_network_flush((Ecore_Con *)obj);
|
2007-02-16 10:12:38 -08:00
|
|
|
}
|
|
|
|
|
2011-09-12 01:30:22 -07:00
|
|
|
EAPI int
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_server_fd_get(const Ecore_Con *obj)
|
|
|
|
{
|
2016-05-11 05:00:57 -07:00
|
|
|
return efl_network_fd_get((Ecore_Con *)obj);
|
2014-08-22 08:06:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static int
|
2016-05-11 05:00:57 -07:00
|
|
|
_efl_network_server_efl_network_fd_get(Eo *obj EINA_UNUSED, Efl_Network_Server_Data *svr)
|
2011-09-12 01:30:22 -07:00
|
|
|
{
|
|
|
|
if (svr->created) return -1;
|
2012-09-13 00:04:11 -07:00
|
|
|
if (svr->delete_me) return -1;
|
2011-09-12 01:30:22 -07:00
|
|
|
return ecore_main_fd_handler_fd_get(svr->fd_handler);
|
|
|
|
}
|
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
EOLIAN static int
|
2016-05-11 05:00:57 -07:00
|
|
|
_efl_network_client_efl_network_fd_get(Eo *obj EINA_UNUSED, Efl_Network_Client_Data *cl)
|
2011-09-12 01:30:22 -07:00
|
|
|
{
|
|
|
|
return ecore_main_fd_handler_fd_get(cl->fd_handler);
|
|
|
|
}
|
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
EAPI int
|
|
|
|
ecore_con_client_fd_get(const Ecore_Con *obj)
|
|
|
|
{
|
2016-05-11 05:00:57 -07:00
|
|
|
return efl_network_fd_get((Ecore_Con *)obj);
|
2014-08-22 05:14:59 -07:00
|
|
|
}
|
|
|
|
|
2010-07-28 17:27:15 -07:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2011-12-05 19:32:16 -08:00
|
|
|
void
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_event_proxy_bind(Ecore_Con_Server *obj)
|
2011-12-05 19:32:16 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2013-12-19 21:07:50 -08:00
|
|
|
Ecore_Con_Event_Proxy_Bind *e;
|
|
|
|
int ev = ECORE_CON_EVENT_PROXY_BIND;
|
2011-12-05 19:32:16 -08:00
|
|
|
|
2013-12-19 21:07:50 -08:00
|
|
|
e = ecore_con_event_proxy_bind_alloc();
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
2011-12-05 19:32:16 -08:00
|
|
|
|
2013-12-19 21:07:50 -08:00
|
|
|
svr->event_count = eina_list_append(svr->event_count, e);
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_server_timer_update(obj);
|
|
|
|
e->server = obj;
|
2013-12-19 21:07:50 -08:00
|
|
|
e->ip = svr->proxyip;
|
|
|
|
e->port = svr->proxyport;
|
|
|
|
ecore_event_add(ev, e,
|
|
|
|
_ecore_con_event_server_add_free, NULL);
|
2011-12-05 19:32:16 -08:00
|
|
|
_ecore_con_event_count++;
|
|
|
|
}
|
|
|
|
|
2011-02-10 11:17:30 -08:00
|
|
|
void
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_event_server_add(Ecore_Con_Server *obj)
|
2011-02-10 11:17:30 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2013-12-19 21:07:50 -08:00
|
|
|
/* we got our server! */
|
|
|
|
Ecore_Con_Event_Server_Add *e;
|
|
|
|
int ev = ECORE_CON_EVENT_SERVER_ADD;
|
|
|
|
|
|
|
|
e = ecore_con_event_server_add_alloc();
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
|
|
|
svr->connecting = EINA_FALSE;
|
|
|
|
svr->start_time = ecore_time_get();
|
|
|
|
svr->event_count = eina_list_append(svr->event_count, e);
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_server_timer_update(obj);
|
|
|
|
e->server = obj;
|
2013-12-19 21:07:50 -08:00
|
|
|
if (svr->upgrade) ev = ECORE_CON_EVENT_SERVER_UPGRADE;
|
|
|
|
ecore_event_add(ev, e,
|
|
|
|
_ecore_con_event_server_add_free, NULL);
|
2016-08-29 16:13:22 -07:00
|
|
|
efl_event_callback_call(obj, EFL_NETWORK_EVENT_CONNECTION_UPGRADED, NULL);
|
2011-11-10 18:44:16 -08:00
|
|
|
_ecore_con_event_count++;
|
2011-02-10 11:17:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_event_server_del(Ecore_Con_Server *obj)
|
2011-02-10 11:17:30 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2013-12-19 21:07:50 -08:00
|
|
|
Ecore_Con_Event_Server_Del *e;
|
|
|
|
|
|
|
|
svr->delete_me = EINA_TRUE;
|
|
|
|
INF("svr %p is dead", svr);
|
|
|
|
e = ecore_con_event_server_del_alloc();
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
|
|
|
svr->event_count = eina_list_append(svr->event_count, e);
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_server_timer_update(obj);
|
|
|
|
e->server = obj;
|
2013-12-19 21:07:50 -08:00
|
|
|
if (svr->ecs)
|
|
|
|
{
|
|
|
|
svr->ecs_state = svr->ecs->lookup ? ECORE_CON_PROXY_STATE_RESOLVED : ECORE_CON_PROXY_STATE_DONE;
|
|
|
|
eina_stringshare_replace(&svr->proxyip, NULL);
|
|
|
|
svr->proxyport = 0;
|
|
|
|
}
|
|
|
|
ecore_event_add(ECORE_CON_EVENT_SERVER_DEL, e,
|
|
|
|
_ecore_con_event_server_del_free, NULL);
|
2011-11-10 18:44:16 -08:00
|
|
|
_ecore_con_event_count++;
|
2011-02-10 11:17:30 -08:00
|
|
|
}
|
|
|
|
|
2011-09-13 16:03:26 -07:00
|
|
|
void
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_event_server_write(Ecore_Con_Server *obj, int num)
|
2011-09-13 16:03:26 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2011-09-13 16:03:26 -07:00
|
|
|
Ecore_Con_Event_Server_Write *e;
|
|
|
|
|
2011-11-06 04:26:00 -08:00
|
|
|
e = ecore_con_event_server_write_alloc();
|
2011-09-13 16:03:26 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
2011-12-05 20:48:55 -08:00
|
|
|
INF("Wrote %d bytes", num);
|
2011-11-10 18:44:16 -08:00
|
|
|
svr->event_count = eina_list_append(svr->event_count, e);
|
2014-08-22 08:06:27 -07:00
|
|
|
e->server = obj;
|
2011-09-13 16:03:26 -07:00
|
|
|
e->size = num;
|
|
|
|
ecore_event_add(ECORE_CON_EVENT_SERVER_WRITE, e,
|
|
|
|
(Ecore_End_Cb)_ecore_con_event_server_write_free, NULL);
|
2011-11-10 18:44:16 -08:00
|
|
|
_ecore_con_event_count++;
|
2011-09-13 16:03:26 -07:00
|
|
|
}
|
|
|
|
|
2011-02-10 11:17:30 -08:00
|
|
|
void
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_event_server_data(Ecore_Con_Server *obj, unsigned char *buf, int num, Eina_Bool duplicate)
|
2011-02-10 11:17:30 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2011-02-10 11:17:30 -08:00
|
|
|
Ecore_Con_Event_Server_Data *e;
|
2011-04-20 07:15:33 -07:00
|
|
|
|
2011-11-06 04:26:00 -08:00
|
|
|
e = ecore_con_event_server_data_alloc();
|
2011-12-09 23:34:45 -08:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
2011-04-20 07:15:33 -07:00
|
|
|
|
2011-11-10 18:44:16 -08:00
|
|
|
svr->event_count = eina_list_append(svr->event_count, e);
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_server_timer_update(obj);
|
|
|
|
e->server = obj;
|
2011-05-14 10:52:30 -07:00
|
|
|
if (duplicate)
|
2011-02-10 11:17:30 -08:00
|
|
|
{
|
2011-05-14 10:52:30 -07:00
|
|
|
e->data = malloc(num);
|
|
|
|
if (!e->data)
|
|
|
|
{
|
2011-11-06 04:26:00 -08:00
|
|
|
ERR("server data allocation failure !");
|
|
|
|
_ecore_con_event_server_data_free(NULL, e);
|
2011-05-14 10:52:30 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
memcpy(e->data, buf, num);
|
2011-02-10 11:17:30 -08:00
|
|
|
}
|
2011-05-14 10:52:30 -07:00
|
|
|
else
|
|
|
|
e->data = buf;
|
2011-02-10 11:17:30 -08:00
|
|
|
e->size = num;
|
|
|
|
ecore_event_add(ECORE_CON_EVENT_SERVER_DATA, e,
|
|
|
|
_ecore_con_event_server_data_free, NULL);
|
2014-08-22 08:38:25 -07:00
|
|
|
{
|
2015-04-21 04:03:33 -07:00
|
|
|
Ecore_Con_Event_Data_Received event_info = { NULL, 0 };
|
2014-08-22 08:38:25 -07:00
|
|
|
event_info.data = e->data;
|
|
|
|
event_info.size = e->size;
|
2016-08-29 16:13:22 -07:00
|
|
|
efl_event_callback_call(obj, EFL_NETWORK_EVENT_DATA_RECEIVED, &event_info);
|
2014-08-22 08:38:25 -07:00
|
|
|
}
|
2011-11-10 18:44:16 -08:00
|
|
|
_ecore_con_event_count++;
|
2011-02-10 11:17:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-08-22 05:14:59 -07:00
|
|
|
ecore_con_event_client_add(Ecore_Con_Client *obj)
|
2011-02-10 11:17:30 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Client_Data *cl = efl_data_scope_get(obj, EFL_NETWORK_CLIENT_CLASS);
|
2011-02-10 11:17:30 -08:00
|
|
|
Ecore_Con_Event_Client_Add *e;
|
2011-06-15 11:58:34 -07:00
|
|
|
int ev = ECORE_CON_EVENT_CLIENT_ADD;
|
2011-02-10 11:17:30 -08:00
|
|
|
|
2011-11-06 04:26:00 -08:00
|
|
|
e = ecore_con_event_client_add_alloc();
|
2011-02-10 11:17:30 -08:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *host_server = efl_data_scope_get(cl->host_server, EFL_NETWORK_SERVER_CLASS);
|
2014-08-22 08:06:27 -07:00
|
|
|
|
2011-11-10 18:44:16 -08:00
|
|
|
cl->event_count = eina_list_append(cl->event_count, e);
|
2014-08-22 08:06:27 -07:00
|
|
|
host_server->event_count = eina_list_append(host_server->event_count, e);
|
2014-08-22 05:14:59 -07:00
|
|
|
_ecore_con_cl_timer_update(obj);
|
2013-05-24 05:06:08 -07:00
|
|
|
cl->start_time = ecore_time_get();
|
2014-08-22 05:14:59 -07:00
|
|
|
e->client = obj;
|
2011-06-15 11:58:34 -07:00
|
|
|
if (cl->upgrade) ev = ECORE_CON_EVENT_CLIENT_UPGRADE;
|
|
|
|
ecore_event_add(ev, e,
|
2011-02-10 11:17:30 -08:00
|
|
|
(Ecore_End_Cb)_ecore_con_event_client_add_free, cl->host_server);
|
2016-08-29 16:13:22 -07:00
|
|
|
efl_event_callback_call(obj, EFL_NETWORK_EVENT_CONNECTION_UPGRADED, NULL);
|
2011-11-10 18:44:16 -08:00
|
|
|
_ecore_con_event_count++;
|
2011-02-10 11:17:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-08-22 05:14:59 -07:00
|
|
|
ecore_con_event_client_del(Ecore_Con_Client *obj)
|
2011-02-10 11:17:30 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Client_Data *cl = efl_data_scope_get(obj, EFL_NETWORK_CLIENT_CLASS);
|
2013-12-19 21:07:50 -08:00
|
|
|
Ecore_Con_Event_Client_Del *e;
|
2011-02-10 11:17:30 -08:00
|
|
|
|
2013-12-19 21:07:50 -08:00
|
|
|
if (!cl) return;
|
|
|
|
cl->delete_me = EINA_TRUE;
|
|
|
|
INF("cl %p is dead", cl);
|
|
|
|
e = ecore_con_event_client_del_alloc();
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
cl->event_count = eina_list_append(cl->event_count, e);
|
2011-02-10 11:17:30 -08:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *host_server = efl_data_scope_get(cl->host_server, EFL_NETWORK_SERVER_CLASS);
|
2014-08-22 08:06:27 -07:00
|
|
|
|
|
|
|
host_server->event_count = eina_list_append(host_server->event_count, e);
|
2014-08-22 05:14:59 -07:00
|
|
|
_ecore_con_cl_timer_update(obj);
|
|
|
|
e->client = obj;
|
2013-12-19 21:07:50 -08:00
|
|
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
|
|
|
|
(Ecore_End_Cb)_ecore_con_event_client_del_free, cl->host_server);
|
2011-11-10 18:44:16 -08:00
|
|
|
_ecore_con_event_count++;
|
2011-02-10 11:17:30 -08:00
|
|
|
}
|
|
|
|
|
2011-09-13 16:03:26 -07:00
|
|
|
void
|
2014-08-22 05:14:59 -07:00
|
|
|
ecore_con_event_client_write(Ecore_Con_Client *obj, int num)
|
2011-09-13 16:03:26 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Client_Data *cl = efl_data_scope_get(obj, EFL_NETWORK_CLIENT_CLASS);
|
2011-09-13 16:03:26 -07:00
|
|
|
Ecore_Con_Event_Client_Write *e;
|
2011-11-06 04:26:00 -08:00
|
|
|
|
|
|
|
e = ecore_con_event_client_write_alloc();
|
2011-09-13 16:03:26 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *host_server = efl_data_scope_get(cl->host_server, EFL_NETWORK_SERVER_CLASS);
|
2014-08-22 08:06:27 -07:00
|
|
|
|
2011-11-10 18:44:16 -08:00
|
|
|
cl->event_count = eina_list_append(cl->event_count, e);
|
2014-08-22 08:06:27 -07:00
|
|
|
host_server->event_count = eina_list_append(host_server->event_count, e);
|
2014-08-22 05:14:59 -07:00
|
|
|
e->client = obj;
|
2011-09-13 16:03:26 -07:00
|
|
|
e->size = num;
|
|
|
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_WRITE, e,
|
|
|
|
(Ecore_End_Cb)_ecore_con_event_client_write_free, cl->host_server);
|
2011-11-10 18:44:16 -08:00
|
|
|
_ecore_con_event_count++;
|
2011-09-13 16:03:26 -07:00
|
|
|
}
|
|
|
|
|
2011-02-10 11:17:30 -08:00
|
|
|
void
|
2014-08-22 05:14:59 -07:00
|
|
|
ecore_con_event_client_data(Ecore_Con_Client *obj, unsigned char *buf, int num, Eina_Bool duplicate)
|
2011-02-10 11:17:30 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Client_Data *cl = efl_data_scope_get(obj, EFL_NETWORK_CLIENT_CLASS);
|
2011-02-10 11:17:30 -08:00
|
|
|
Ecore_Con_Event_Client_Data *e;
|
2011-11-06 04:26:00 -08:00
|
|
|
|
|
|
|
e = ecore_con_event_client_data_alloc();
|
2011-02-10 11:17:30 -08:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *host_server = efl_data_scope_get(cl->host_server, EFL_NETWORK_SERVER_CLASS);
|
2014-08-22 08:06:27 -07:00
|
|
|
|
2011-11-10 18:44:16 -08:00
|
|
|
cl->event_count = eina_list_append(cl->event_count, e);
|
2014-08-22 08:06:27 -07:00
|
|
|
host_server->event_count = eina_list_append(host_server->event_count, e);
|
2014-08-22 05:14:59 -07:00
|
|
|
_ecore_con_cl_timer_update(obj);
|
|
|
|
e->client = obj;
|
2013-11-18 03:48:00 -08:00
|
|
|
if ((duplicate) && (num > 0))
|
2011-02-10 11:17:30 -08:00
|
|
|
{
|
2011-05-14 10:52:30 -07:00
|
|
|
e->data = malloc(num);
|
|
|
|
if (!e->data)
|
|
|
|
{
|
2011-11-06 04:26:00 -08:00
|
|
|
ERR("client data allocation failure !");
|
|
|
|
_ecore_con_event_client_data_free(cl->host_server, e);
|
2011-05-14 10:52:30 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
memcpy(e->data, buf, num);
|
2011-02-10 11:17:30 -08:00
|
|
|
}
|
2011-05-14 10:52:30 -07:00
|
|
|
else
|
|
|
|
e->data = buf;
|
2011-02-10 11:17:30 -08:00
|
|
|
e->size = num;
|
|
|
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_DATA, e,
|
|
|
|
(Ecore_End_Cb)_ecore_con_event_client_data_free, cl->host_server);
|
2014-08-22 06:33:26 -07:00
|
|
|
{
|
2015-04-21 04:03:33 -07:00
|
|
|
Ecore_Con_Event_Data_Received event_info = { NULL, 0 };
|
2014-08-22 06:33:26 -07:00
|
|
|
event_info.data = e->data;
|
|
|
|
event_info.size = e->size;
|
2016-08-29 16:13:22 -07:00
|
|
|
efl_event_callback_call(obj, EFL_NETWORK_EVENT_DATA_RECEIVED, &event_info);
|
2014-08-22 06:33:26 -07:00
|
|
|
}
|
2011-11-10 18:44:16 -08:00
|
|
|
_ecore_con_event_count++;
|
2011-02-10 11:17:30 -08:00
|
|
|
}
|
|
|
|
|
2011-01-21 02:01:04 -08:00
|
|
|
void
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_server_infos_del(Ecore_Con_Server *obj, void *info)
|
2011-01-21 02:01:04 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2011-01-21 02:01:04 -08:00
|
|
|
svr->infos = eina_list_remove(svr->infos, info);
|
|
|
|
}
|
|
|
|
|
2011-02-10 00:49:23 -08:00
|
|
|
void
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_event_server_error(Ecore_Con_Server *obj, char *error, Eina_Bool duplicate)
|
2011-02-10 00:49:23 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2011-02-10 00:49:23 -08:00
|
|
|
Ecore_Con_Event_Server_Error *e;
|
|
|
|
|
2011-11-06 04:26:00 -08:00
|
|
|
e = ecore_con_event_server_error_alloc();
|
2011-02-10 00:49:23 -08:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
e->server = obj;
|
2011-12-09 21:09:47 -08:00
|
|
|
e->error = duplicate ? strdup(error) : error;
|
2013-01-04 00:45:31 -08:00
|
|
|
DBG("%s", error);
|
2011-11-10 18:44:16 -08:00
|
|
|
svr->event_count = eina_list_append(svr->event_count, e);
|
2011-02-10 00:49:23 -08:00
|
|
|
ecore_event_add(ECORE_CON_EVENT_SERVER_ERROR, e, (Ecore_End_Cb)_ecore_con_event_server_error_free, NULL);
|
2016-08-29 16:13:22 -07:00
|
|
|
efl_event_callback_call(obj, EFL_NETWORK_EVENT_CONNECTION_ERROR, e->error);
|
2011-11-10 18:44:16 -08:00
|
|
|
_ecore_con_event_count++;
|
2011-02-10 00:49:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-08-22 05:14:59 -07:00
|
|
|
ecore_con_event_client_error(Ecore_Con_Client *obj, const char *error)
|
2011-02-10 00:49:23 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Client_Data *cl = efl_data_scope_get(obj, EFL_NETWORK_CLIENT_CLASS);
|
2011-02-10 00:49:23 -08:00
|
|
|
Ecore_Con_Event_Client_Error *e;
|
|
|
|
|
2011-11-06 04:26:00 -08:00
|
|
|
e = ecore_con_event_client_error_alloc();
|
2011-02-10 00:49:23 -08:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *host_server = efl_data_scope_get(cl->host_server, EFL_NETWORK_SERVER_CLASS);
|
2014-08-22 08:06:27 -07:00
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
e->client = obj;
|
2011-02-10 00:49:23 -08:00
|
|
|
e->error = strdup(error);
|
2013-01-04 00:45:31 -08:00
|
|
|
DBG("%s", error);
|
2011-11-10 18:44:16 -08:00
|
|
|
cl->event_count = eina_list_append(cl->event_count, e);
|
2014-08-22 08:06:27 -07:00
|
|
|
host_server->event_count = eina_list_append(host_server->event_count, e);
|
2011-02-10 11:17:30 -08:00
|
|
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_ERROR, e, (Ecore_End_Cb)_ecore_con_event_client_error_free, cl->host_server);
|
2016-08-29 16:13:22 -07:00
|
|
|
efl_event_callback_call(obj, EFL_NETWORK_EVENT_CONNECTION_ERROR, e->error);
|
2011-11-10 18:44:16 -08:00
|
|
|
_ecore_con_event_count++;
|
2011-02-10 00:49:23 -08:00
|
|
|
}
|
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
static void
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_server_free(Ecore_Con_Server *obj)
|
|
|
|
{
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_del(obj);
|
2014-08-22 08:06:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static void
|
2016-08-10 07:23:04 -07:00
|
|
|
_efl_network_server_efl_object_destructor(Eo *obj, Efl_Network_Server_Data *svr)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2014-08-22 05:14:59 -07:00
|
|
|
Ecore_Con_Client *cl_obj;
|
2006-05-18 20:52:24 -07:00
|
|
|
double t_start, t;
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2014-08-29 02:07:14 -07:00
|
|
|
if (svr->event_count) goto end;
|
2011-11-19 16:28:48 -08:00
|
|
|
|
2011-01-21 02:01:04 -08:00
|
|
|
while (svr->infos)
|
|
|
|
{
|
|
|
|
ecore_con_info_data_clear(svr->infos->data);
|
|
|
|
svr->infos = eina_list_remove_list(svr->infos, svr->infos);
|
|
|
|
}
|
2010-11-11 12:20:44 -08:00
|
|
|
|
2006-05-18 20:52:24 -07:00
|
|
|
t_start = ecore_time_get();
|
2011-12-21 02:02:30 -08:00
|
|
|
while (svr->buf && (!svr->delete_me))
|
2006-05-18 20:52:24 -07:00
|
|
|
{
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_server_flush(obj);
|
2010-07-26 23:30:27 -07:00
|
|
|
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
|
|
|
|
2011-05-14 10:52:30 -07:00
|
|
|
#ifdef _WIN32
|
2014-08-26 03:07:43 -07:00
|
|
|
ecore_con_local_win32_server_del(obj);
|
2011-05-14 10:52:30 -07:00
|
|
|
#endif
|
2014-08-29 02:07:14 -07:00
|
|
|
if (svr->event_count) goto end;
|
2011-05-14 10:52:30 -07:00
|
|
|
|
2011-07-16 06:07:39 -07:00
|
|
|
if (svr->buf)
|
|
|
|
eina_binbuf_free(svr->buf);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
EINA_LIST_FREE(svr->clients, cl_obj)
|
2011-11-10 18:44:16 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Client_Data *cl = efl_data_scope_get(cl_obj, EFL_NETWORK_CLIENT_CLASS);
|
2011-11-10 18:44:16 -08:00
|
|
|
Ecore_Con_Event_Server_Add *ev;
|
|
|
|
|
|
|
|
/* some pointer hacks here to prevent double frees if people are being stupid */
|
|
|
|
EINA_LIST_FREE(cl->event_count, ev)
|
|
|
|
ev->server = NULL;
|
2011-12-21 02:02:30 -08:00
|
|
|
cl->delete_me = EINA_TRUE;
|
2011-12-02 19:50:20 -08:00
|
|
|
INF("cl %p is dead", cl);
|
2014-08-22 05:14:59 -07:00
|
|
|
_ecore_con_client_free(cl_obj);
|
2011-11-10 18:44:16 -08:00
|
|
|
}
|
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
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_ssl_server_shutdown(obj);
|
2011-11-10 18:44:16 -08:00
|
|
|
free(svr->name);
|
2015-06-24 21:18:22 -07:00
|
|
|
svr->name = NULL;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2011-11-10 18:44:16 -08:00
|
|
|
free(svr->path);
|
2015-06-24 21:18:22 -07:00
|
|
|
svr->path = NULL;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2011-11-10 18:44:16 -08:00
|
|
|
eina_stringshare_del(svr->ip);
|
2011-12-07 17:14:55 -08:00
|
|
|
eina_stringshare_del(svr->verify_name);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2011-12-05 19:32:16 -08:00
|
|
|
if (svr->ecs_buf) eina_binbuf_free(svr->ecs_buf);
|
|
|
|
if (svr->ecs_recvbuf) eina_binbuf_free(svr->ecs_recvbuf);
|
|
|
|
|
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
|
|
|
|
2014-08-11 04:48:03 -07:00
|
|
|
if (svr->fd >= 0)
|
2010-12-15 20:38:37 -08:00
|
|
|
close(svr->fd);
|
|
|
|
|
2011-06-17 04:16:50 -07:00
|
|
|
if (svr->until_deletion)
|
|
|
|
ecore_timer_del(svr->until_deletion);
|
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
servers = eina_list_remove(servers, obj);
|
2010-11-11 11:53:21 -08:00
|
|
|
svr->data = NULL;
|
2014-08-22 08:06:27 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_destructor(efl_super(obj, EFL_NETWORK_SERVER_CLASS));
|
2015-06-24 21:18:22 -07:00
|
|
|
end:
|
|
|
|
return;
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-22 05:14:59 -07:00
|
|
|
_ecore_con_client_free(Ecore_Con_Client *obj)
|
|
|
|
{
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_del(obj);
|
2014-08-22 05:14:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EOLIAN static void
|
2016-08-10 07:23:04 -07:00
|
|
|
_efl_network_client_efl_object_destructor(Eo *obj, Efl_Network_Client_Data *cl)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2006-05-18 20:52:24 -07:00
|
|
|
double t_start, t;
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2011-11-10 18:44:16 -08:00
|
|
|
if (cl->event_count) return;
|
2010-12-08 22:43:58 -08:00
|
|
|
|
2006-05-18 20:52:24 -07:00
|
|
|
t_start = ecore_time_get();
|
2011-12-21 02:02:30 -08:00
|
|
|
while ((cl->buf) && (!cl->delete_me))
|
2006-05-18 20:52:24 -07:00
|
|
|
{
|
2014-08-22 05:14:59 -07:00
|
|
|
_ecore_con_client_flush(obj);
|
2010-07-26 23:30:27 -07:00
|
|
|
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
|
|
|
}
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *host_server = efl_data_scope_get(cl->host_server, EFL_NETWORK_SERVER_CLASS);
|
2014-08-22 08:06:27 -07:00
|
|
|
|
2016-04-05 00:32:25 -07:00
|
|
|
if (host_server)
|
|
|
|
{
|
|
|
|
host_server->clients = eina_list_remove(host_server->clients, obj);
|
|
|
|
--host_server->client_count;
|
|
|
|
}
|
2011-05-14 10:52:30 -07:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2014-08-26 03:07:43 -07:00
|
|
|
ecore_con_local_win32_client_del(obj);
|
2011-05-14 10:52:30 -07:00
|
|
|
#endif
|
|
|
|
|
2011-11-19 16:28:48 -08:00
|
|
|
if (cl->event_count) return;
|
|
|
|
|
2012-02-24 03:21:12 -08:00
|
|
|
if (cl->buf) eina_binbuf_free(cl->buf);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2016-04-05 00:32:25 -07:00
|
|
|
if (host_server && (host_server->type & ECORE_CON_SSL))
|
2014-08-22 05:14:59 -07:00
|
|
|
ecore_con_ssl_client_shutdown(obj);
|
2010-09-21 21:48:09 -07:00
|
|
|
|
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
|
|
|
|
2014-08-11 04:48:03 -07:00
|
|
|
if (cl->fd >= 0)
|
2010-12-15 20:38:37 -08:00
|
|
|
close(cl->fd);
|
|
|
|
|
2011-11-10 18:44:16 -08:00
|
|
|
free(cl->client_addr);
|
2010-12-02 22:14:30 -08:00
|
|
|
cl->client_addr = NULL;
|
|
|
|
|
2011-06-17 04:16:50 -07:00
|
|
|
if (cl->until_deletion)
|
|
|
|
ecore_timer_del(cl->until_deletion);
|
|
|
|
|
2011-11-10 18:44:16 -08:00
|
|
|
eina_stringshare_del(cl->ip);
|
2010-11-11 11:53:21 -08:00
|
|
|
cl->data = NULL;
|
2014-08-22 05:14:59 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_destructor(efl_super(obj, EFL_NETWORK_CLIENT_CLASS));
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2011-06-17 04:16:50 -07:00
|
|
|
static Eina_Bool
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_server_timer(Ecore_Con_Server *obj)
|
2011-06-17 04:16:50 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_server_del(obj);
|
2011-06-17 04:16:50 -07:00
|
|
|
|
2011-07-07 11:18:53 -07:00
|
|
|
svr->until_deletion = NULL;
|
2011-06-17 04:16:50 -07:00
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_server_timer_update(Ecore_Con_Server *obj)
|
2011-06-17 04:16:50 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2011-06-17 04:16:50 -07:00
|
|
|
if (svr->disconnect_time)
|
|
|
|
{
|
|
|
|
if (svr->disconnect_time > 0)
|
|
|
|
{
|
|
|
|
if (svr->until_deletion)
|
2013-05-24 02:51:09 -07:00
|
|
|
{
|
|
|
|
ecore_timer_interval_set(svr->until_deletion, svr->disconnect_time);
|
|
|
|
ecore_timer_reset(svr->until_deletion);
|
|
|
|
}
|
2011-06-17 04:16:50 -07:00
|
|
|
else
|
2014-08-22 08:06:27 -07:00
|
|
|
svr->until_deletion = ecore_timer_add(svr->disconnect_time, (Ecore_Task_Cb)_ecore_con_server_timer, obj);
|
2011-06-17 04:16:50 -07:00
|
|
|
}
|
|
|
|
else if (svr->until_deletion)
|
|
|
|
{
|
|
|
|
ecore_timer_del(svr->until_deletion);
|
|
|
|
svr->until_deletion = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (svr->until_deletion)
|
|
|
|
{
|
|
|
|
ecore_timer_del(svr->until_deletion);
|
|
|
|
svr->until_deletion = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-21 21:48:09 -07:00
|
|
|
static Eina_Bool
|
2014-08-22 05:14:59 -07:00
|
|
|
_ecore_con_client_timer(Ecore_Con_Client *obj)
|
2010-09-21 21:48:09 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Client_Data *cl = efl_data_scope_get(obj, EFL_NETWORK_CLIENT_CLASS);
|
2014-08-22 05:14:59 -07:00
|
|
|
ecore_con_client_del(obj);
|
2010-09-21 21:48:09 -07:00
|
|
|
|
2011-07-07 11:18:53 -07:00
|
|
|
cl->until_deletion = NULL;
|
2010-09-21 21:48:09 -07:00
|
|
|
return ECORE_CALLBACK_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-22 05:14:59 -07:00
|
|
|
_ecore_con_cl_timer_update(Ecore_Con_Client *obj)
|
2010-09-21 21:48:09 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Client_Data *cl = efl_data_scope_get(obj, EFL_NETWORK_CLIENT_CLASS);
|
2010-09-21 21:48:09 -07:00
|
|
|
if (cl->disconnect_time)
|
|
|
|
{
|
|
|
|
if (cl->disconnect_time > 0)
|
|
|
|
{
|
|
|
|
if (cl->until_deletion)
|
2013-05-24 02:51:09 -07:00
|
|
|
{
|
|
|
|
ecore_timer_interval_set(cl->until_deletion, cl->disconnect_time);
|
|
|
|
ecore_timer_reset(cl->until_deletion);
|
|
|
|
}
|
2010-09-21 21:48:09 -07:00
|
|
|
else
|
2014-12-30 02:17:32 -08:00
|
|
|
cl->until_deletion = ecore_timer_add(cl->disconnect_time, (Ecore_Task_Cb)_ecore_con_client_timer, obj);
|
2010-09-21 21:48:09 -07:00
|
|
|
}
|
|
|
|
else if (cl->until_deletion)
|
|
|
|
{
|
|
|
|
ecore_timer_del(cl->until_deletion);
|
|
|
|
cl->until_deletion = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *host_server = efl_data_scope_get(cl->host_server, EFL_NETWORK_SERVER_CLASS);
|
2014-08-22 08:06:27 -07:00
|
|
|
|
2016-04-05 00:32:25 -07:00
|
|
|
if (host_server && host_server->client_disconnect_time > 0)
|
2010-09-21 21:48:09 -07:00
|
|
|
{
|
|
|
|
if (cl->until_deletion)
|
2013-05-24 04:53:07 -07:00
|
|
|
{
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_timer_interval_set(cl->until_deletion, host_server->client_disconnect_time);
|
2013-05-24 04:53:07 -07:00
|
|
|
ecore_timer_reset(cl->until_deletion);
|
|
|
|
}
|
2010-09-21 21:48:09 -07:00
|
|
|
else
|
2014-12-30 02:17:32 -08:00
|
|
|
cl->until_deletion = ecore_timer_add(host_server->client_disconnect_time, (Ecore_Task_Cb)_ecore_con_client_timer, obj);
|
2010-09-21 21:48:09 -07:00
|
|
|
}
|
|
|
|
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
|
2013-12-19 21:07:50 -08:00
|
|
|
_ecore_con_cb_tcp_listen(void *data,
|
2010-11-03 10:58:37 -07:00
|
|
|
Ecore_Con_Info *net_info)
|
2008-10-09 05:30:19 -07:00
|
|
|
{
|
2014-08-22 08:06:27 -07:00
|
|
|
Ecore_Con_Server *obj = data;
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2008-10-09 05:30:19 -07:00
|
|
|
struct linger lin;
|
2011-12-09 21:17:34 -08:00
|
|
|
const char *memerr = NULL;
|
2015-01-30 01:51:52 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
u_long mode = 1;
|
|
|
|
#endif
|
2008-10-09 05:30:19 -07:00
|
|
|
|
2011-12-09 21:09:47 -08:00
|
|
|
errno = 0;
|
2011-02-10 00:49:23 -08:00
|
|
|
if (!net_info) /* error message has already been handled */
|
2012-07-02 02:24:02 -07:00
|
|
|
{
|
|
|
|
svr->delete_me = EINA_TRUE;
|
|
|
|
goto error;
|
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2013-03-09 22:49:54 -08:00
|
|
|
#ifdef HAVE_SYSTEMD
|
|
|
|
if (svr->type & ECORE_CON_SOCKET_ACTIVATE && sd_fd_index < sd_fd_max)
|
|
|
|
{
|
|
|
|
if (sd_is_socket_inet(SD_LISTEN_FDS_START + sd_fd_index,
|
2013-12-19 21:07:50 -08:00
|
|
|
net_info->info.ai_family,
|
|
|
|
net_info->info.ai_socktype,
|
|
|
|
1,
|
|
|
|
svr->port) <= 0)
|
|
|
|
{
|
|
|
|
ERR("Your systemd unit seems to provide fd in the wrong order for Socket activation.");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
svr->fd = SD_LISTEN_FDS_START + sd_fd_index++;
|
|
|
|
|
|
|
|
/* I am wondering if that's really going to work as the bind is already done */
|
|
|
|
if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
|
|
|
|
|
|
|
|
lin.l_onoff = 1;
|
|
|
|
lin.l_linger = 0;
|
|
|
|
if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, (const void *)&lin,
|
|
|
|
sizeof(struct linger)) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY)
|
|
|
|
{
|
|
|
|
int flag = 1;
|
|
|
|
|
|
|
|
if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag,
|
|
|
|
sizeof(int)) < 0)
|
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
goto fd_ready;
|
2013-03-09 22:49:54 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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);
|
2015-01-30 01:51:52 -08:00
|
|
|
#ifdef _WIN32
|
2015-01-30 02:04:19 -08:00
|
|
|
if (svr->fd == INVALID_SOCKET) goto error;
|
|
|
|
|
2015-01-30 01:51:52 -08:00
|
|
|
if (ioctlsocket(svr->fd, FIONBIO, &mode)) goto error;
|
|
|
|
#else
|
2015-01-30 02:04:19 -08:00
|
|
|
if (svr->fd < 0) goto error;
|
|
|
|
|
2011-12-09 21:09:47 -08:00
|
|
|
if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
|
|
|
|
if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
|
2015-01-30 01:51:52 -08:00
|
|
|
#endif
|
2011-04-20 07:15:33 -07:00
|
|
|
|
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)
|
2011-12-09 21:09:47 -08:00
|
|
|
goto error;
|
2011-04-20 07:15:33 -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
|
|
|
{
|
2013-12-19 21:07:50 -08: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)
|
2011-02-10 00:49:23 -08:00
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
2009-11-20 02:58:19 -08:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2015-01-30 05:25:53 -08:00
|
|
|
if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) != 0)
|
2011-12-09 21:09:47 -08:00
|
|
|
goto error;
|
|
|
|
|
2015-01-30 05:25:53 -08:00
|
|
|
if (listen(svr->fd, 4096) != 0) goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2013-03-09 22:49:54 -08:00
|
|
|
#ifdef HAVE_SYSTEMD
|
2013-12-19 21:07:50 -08:00
|
|
|
fd_ready:
|
2013-03-09 22:49:54 -08:00
|
|
|
#endif
|
2010-09-17 23:06:05 -07:00
|
|
|
svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_svr_tcp_handler, obj, NULL, NULL);
|
2010-07-26 23:30:27 -07:00
|
|
|
if (!svr->fd_handler)
|
2011-02-10 00:49:23 -08:00
|
|
|
{
|
2011-12-09 21:17:34 -08:00
|
|
|
memerr = "Memory allocation failure";
|
|
|
|
goto error;
|
2011-02-10 00:49:23 -08:00
|
|
|
}
|
2008-10-09 05:30:19 -07:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
error:
|
2014-08-22 08:06:27 -07:00
|
|
|
if (errno || memerr) ecore_con_event_server_error(obj, memerr ? : strerror(errno));
|
|
|
|
ecore_con_ssl_server_shutdown(obj);
|
|
|
|
_ecore_con_server_kill(obj);
|
2008-10-09 05:30:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-12-19 21:07:50 -08:00
|
|
|
_ecore_con_cb_udp_listen(void *data,
|
2010-11-03 10:58:37 -07:00
|
|
|
Ecore_Con_Info *net_info)
|
2008-10-09 05:30:19 -07:00
|
|
|
{
|
2014-08-22 08:06:27 -07:00
|
|
|
Ecore_Con_Server *obj = data;
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2008-10-09 05:30:19 -07:00
|
|
|
Ecore_Con_Type type;
|
|
|
|
struct ip_mreq mreq;
|
2011-09-29 14:04:54 -07:00
|
|
|
#ifdef HAVE_IPV6
|
2008-10-09 05:30:19 -07:00
|
|
|
struct ipv6_mreq mreq6;
|
2011-09-29 14:04:54 -07:00
|
|
|
#endif
|
2008-10-09 05:30:19 -07:00
|
|
|
const int on = 1;
|
2011-12-09 21:17:34 -08:00
|
|
|
const char *memerr = NULL;
|
2015-01-30 01:51:52 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
u_long mode = 1;
|
|
|
|
#endif
|
2008-10-09 05:30:19 -07:00
|
|
|
|
|
|
|
type = svr->type;
|
|
|
|
type &= ECORE_CON_TYPE;
|
|
|
|
|
2011-12-09 21:09:47 -08:00
|
|
|
errno = 0;
|
2011-02-10 00:49:23 -08:00
|
|
|
if (!net_info) /* error message has already been handled */
|
2012-07-02 02:24:02 -07:00
|
|
|
{
|
|
|
|
svr->delete_me = EINA_TRUE;
|
|
|
|
goto error;
|
|
|
|
}
|
2013-03-09 22:49:54 -08:00
|
|
|
#ifdef HAVE_SYSTEMD
|
|
|
|
if (svr->type & ECORE_CON_SOCKET_ACTIVATE && sd_fd_index < sd_fd_max)
|
|
|
|
{
|
|
|
|
if (sd_is_socket_inet(SD_LISTEN_FDS_START + sd_fd_index,
|
2013-12-19 21:07:50 -08:00
|
|
|
net_info->info.ai_family,
|
|
|
|
net_info->info.ai_socktype,
|
|
|
|
-1,
|
|
|
|
svr->port) <= 0)
|
|
|
|
{
|
|
|
|
ERR("Your systemd unit seems to provide fd in the wrong order for Socket activation.");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
svr->fd = SD_LISTEN_FDS_START + sd_fd_index++;
|
|
|
|
|
|
|
|
if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof(on)) != 0)
|
|
|
|
goto error;
|
|
|
|
if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
|
|
|
|
|
|
|
|
goto fd_ready;
|
2013-03-09 22:49:54 -08:00
|
|
|
}
|
|
|
|
#endif
|
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);
|
2015-01-30 02:04:19 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (svr->fd == INVALID_SOCKET) goto error;
|
|
|
|
|
|
|
|
if (ioctlsocket(svr->fd, FIONBIO, &mode)) goto error;
|
|
|
|
#else
|
2011-12-09 21:09:47 -08:00
|
|
|
if (svr->fd < 0) goto error;
|
2008-10-09 05:30:19 -07:00
|
|
|
|
2015-01-30 02:04:19 -08:00
|
|
|
if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
|
|
|
|
if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
|
|
|
|
#endif
|
|
|
|
|
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))
|
2011-12-09 21:09:47 -08: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)
|
2011-12-09 21:09:47 -08:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
}
|
2011-09-29 14:04:54 -07:00
|
|
|
#ifdef HAVE_IPV6
|
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))
|
2011-12-09 21:09:47 -08:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
mreq6.ipv6mr_interface = htonl(INADDR_ANY);
|
2016-01-05 14:23:04 -08:00
|
|
|
if (setsockopt(svr->fd, IPPROTO_IPV6, IPV6_JOIN_GROUP,
|
2010-11-03 10:58:37 -07:00
|
|
|
(const void *)&mreq6, sizeof(mreq6)) != 0)
|
2011-12-09 21:09:47 -08:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
}
|
2011-09-29 14:04:54 -07:00
|
|
|
#endif
|
2008-10-09 05:30:19 -07:00
|
|
|
}
|
|
|
|
|
2011-02-10 00:49:23 -08:00
|
|
|
if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof(on)) != 0)
|
2011-12-09 21:09:47 -08:00
|
|
|
goto error;
|
2015-01-30 01:51:52 -08:00
|
|
|
|
2011-02-10 00:49:23 -08:00
|
|
|
if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
|
2011-12-09 21:09:47 -08:00
|
|
|
goto error;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2013-03-09 22:49:54 -08:00
|
|
|
#ifdef HAVE_SYSTEMD
|
2013-12-19 21:07:50 -08:00
|
|
|
fd_ready:
|
2013-03-09 22:49:54 -08:00
|
|
|
#endif
|
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,
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_svr_udp_handler, obj, NULL, NULL);
|
2010-07-26 23:30:27 -07:00
|
|
|
if (!svr->fd_handler)
|
2011-02-10 00:49:23 -08:00
|
|
|
{
|
2011-12-09 21:17:34 -08:00
|
|
|
memerr = "Memory allocation failure";
|
|
|
|
goto error;
|
2011-02-10 00:49:23 -08:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-11-16 13:32:50 -08:00
|
|
|
svr->ip = eina_stringshare_add(net_info->ip);
|
2008-10-09 05:30:19 -07:00
|
|
|
|
|
|
|
return;
|
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
error:
|
2014-08-22 08:06:27 -07:00
|
|
|
if (errno || memerr) ecore_con_event_server_error(obj, memerr ? : strerror(errno));
|
|
|
|
ecore_con_ssl_server_shutdown(obj);
|
|
|
|
_ecore_con_server_kill(obj);
|
2008-10-09 05:30:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-12-19 21:07:50 -08:00
|
|
|
_ecore_con_cb_tcp_connect(void *data,
|
2010-11-03 10:58:37 -07:00
|
|
|
Ecore_Con_Info *net_info)
|
2008-10-06 02:41:39 -07:00
|
|
|
{
|
2014-08-22 08:06:27 -07:00
|
|
|
Ecore_Con_Server *obj = data;
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2010-07-26 23:30:27 -07:00
|
|
|
int res;
|
|
|
|
int curstate = 0;
|
2011-12-09 21:17:34 -08:00
|
|
|
const char *memerr = NULL;
|
2015-01-30 01:51:52 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
u_long mode = 1;
|
|
|
|
#endif
|
2008-10-06 02:41:39 -07:00
|
|
|
|
2011-12-09 21:09:47 -08:00
|
|
|
errno = 0;
|
2011-02-10 00:49:23 -08:00
|
|
|
if (!net_info) /* error message has already been handled */
|
2012-07-02 02:24:02 -07:00
|
|
|
{
|
|
|
|
svr->delete_me = EINA_TRUE;
|
|
|
|
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);
|
2015-01-30 01:51:52 -08:00
|
|
|
#ifdef _WIN32
|
2015-01-30 02:04:19 -08:00
|
|
|
if (svr->fd == INVALID_SOCKET) goto error;
|
|
|
|
|
2015-01-30 01:51:52 -08:00
|
|
|
if (ioctlsocket(svr->fd, FIONBIO, &mode)) goto error;
|
|
|
|
#else
|
2015-01-30 02:04:19 -08:00
|
|
|
if (svr->fd < 0) goto error;
|
|
|
|
|
2011-12-09 21:09:47 -08:00
|
|
|
if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
|
|
|
|
if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
|
2015-01-30 01:51:52 -08:00
|
|
|
#endif
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2011-02-10 00:49:23 -08:00
|
|
|
if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate, sizeof(curstate)) < 0)
|
2011-12-09 21:09:47 -08: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
|
|
|
|
2011-02-10 00:49:23 -08:00
|
|
|
if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)) < 0)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2015-01-30 01:51:52 -08:00
|
|
|
if (WSAGetLastError() != WSAEWOULDBLOCK)
|
2011-12-09 21:09:47 -08:00
|
|
|
{
|
|
|
|
char *err;
|
|
|
|
err = evil_format_message(WSAGetLastError());
|
2014-08-26 03:07:43 -07:00
|
|
|
_ecore_con_event_server_error(obj, err, EINA_FALSE);
|
|
|
|
ecore_con_ssl_server_shutdown(obj);
|
|
|
|
_ecore_con_server_kill(obj);
|
2011-12-09 21:09:47 -08:00
|
|
|
return;
|
|
|
|
}
|
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
|
|
|
{
|
2011-12-09 21:09:47 -08:00
|
|
|
if (errno != EINPROGRESS) goto error;
|
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,
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_cl_handler, obj, NULL, NULL);
|
2008-10-06 02:41:39 -07:00
|
|
|
}
|
|
|
|
else
|
2014-10-08 02:53:15 -07:00
|
|
|
{
|
|
|
|
ecore_con_event_server_add(obj);
|
|
|
|
svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
|
|
|
|
_ecore_con_cl_handler, obj, 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;
|
2011-12-05 20:48:55 -08:00
|
|
|
DBG("%s ssl handshake", svr->ecs_state ? "Queuing" : "Beginning");
|
2014-08-22 08:06:27 -07:00
|
|
|
if ((!svr->ecs_state) && ecore_con_ssl_server_init(obj))
|
2010-09-23 21:15:42 -07:00
|
|
|
goto error;
|
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (!svr->fd_handler)
|
2011-02-10 00:49:23 -08:00
|
|
|
{
|
2011-12-09 21:17:34 -08:00
|
|
|
memerr = "Memory allocation failure";
|
|
|
|
goto error;
|
2011-02-10 00:49:23 -08:00
|
|
|
}
|
2008-10-06 02:41:39 -07:00
|
|
|
|
2011-12-09 21:17:34 -08:00
|
|
|
if ((!svr->ecs) || (svr->ecs->lookup))
|
2011-12-05 19:32:16 -08:00
|
|
|
svr->ip = eina_stringshare_add(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:
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_event_server_error(obj,
|
2013-12-19 21:07:50 -08:00
|
|
|
memerr ? : errno ? strerror(errno) : "DNS error");
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_ssl_server_shutdown(obj);
|
|
|
|
_ecore_con_server_kill(obj);
|
2008-10-06 02:41:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-12-19 21:07:50 -08:00
|
|
|
_ecore_con_cb_udp_connect(void *data,
|
2010-11-03 10:58:37 -07:00
|
|
|
Ecore_Con_Info *net_info)
|
2008-10-06 02:41:39 -07:00
|
|
|
{
|
2014-08-22 08:06:27 -07:00
|
|
|
Ecore_Con_Server *obj = data;
|
2010-07-26 23:30:27 -07:00
|
|
|
int curstate = 0;
|
|
|
|
int broadcast = 1;
|
2011-12-09 21:17:34 -08:00
|
|
|
const char *memerr = NULL;
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2015-01-30 01:51:52 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
u_long mode = 1;
|
|
|
|
#endif
|
2008-10-06 02:41:39 -07:00
|
|
|
|
2011-12-09 21:09:47 -08:00
|
|
|
errno = 0;
|
2011-02-10 00:49:23 -08:00
|
|
|
if (!net_info) /* error message has already been handled */
|
2012-07-02 02:24:02 -07:00
|
|
|
{
|
|
|
|
svr->delete_me = EINA_TRUE;
|
|
|
|
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);
|
2015-01-30 01:51:52 -08:00
|
|
|
#ifdef _WIN32
|
2015-01-30 02:04:19 -08:00
|
|
|
if (svr->fd == INVALID_SOCKET) goto error;
|
|
|
|
|
2015-01-30 01:51:52 -08:00
|
|
|
if (ioctlsocket(svr->fd, FIONBIO, &mode)) goto error;
|
|
|
|
#else
|
2015-01-30 02:04:19 -08:00
|
|
|
if (svr->fd < 0) goto error;
|
|
|
|
|
2011-12-09 21:09:47 -08:00
|
|
|
if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
|
|
|
|
if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
|
2015-01-30 01:51:52 -08:00
|
|
|
#endif
|
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)
|
2011-02-10 00:49:23 -08:00
|
|
|
{
|
|
|
|
goto error;
|
|
|
|
}
|
2009-08-12 04:24:33 -07:00
|
|
|
}
|
2011-12-09 21:17:34 -08:00
|
|
|
if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR,
|
|
|
|
(const void *)&curstate, sizeof(curstate)) < 0)
|
2011-12-09 21:09:47 -08: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)
|
2011-12-09 21:09:47 -08: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,
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_cl_udp_handler, obj, NULL, NULL);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
|
|
|
if (!svr->fd_handler)
|
2011-02-10 00:49:23 -08:00
|
|
|
{
|
2011-12-09 21:17:34 -08:00
|
|
|
memerr = "Memory allocation failure";
|
|
|
|
goto error;
|
2011-02-10 00:49:23 -08:00
|
|
|
}
|
2009-08-12 04:24:33 -07:00
|
|
|
|
2011-12-09 21:17:34 -08:00
|
|
|
if ((!svr->ecs) || (svr->ecs->lookup))
|
2011-12-05 19:32:16 -08:00
|
|
|
svr->ip = eina_stringshare_add(net_info->ip);
|
2008-10-09 05:30:19 -07:00
|
|
|
|
2008-10-06 02:41:39 -07:00
|
|
|
return;
|
|
|
|
|
2010-07-26 23:30:27 -07:00
|
|
|
error:
|
2014-08-22 08:06:27 -07:00
|
|
|
if (errno || memerr) ecore_con_event_server_error(obj, memerr ? : strerror(errno));
|
|
|
|
ecore_con_ssl_server_shutdown(obj);
|
|
|
|
_ecore_con_server_kill(obj);
|
2008-10-06 02:41:39 -07:00
|
|
|
}
|
|
|
|
|
2008-10-01 08:27:52 -07:00
|
|
|
static Ecore_Con_State
|
2014-08-22 08:06:27 -07:00
|
|
|
svr_try_connect_plain(Ecore_Con_Server *obj)
|
2004-04-03 07:03:33 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2010-07-26 23:30:27 -07:00
|
|
|
int res;
|
|
|
|
int so_err = 0;
|
2011-03-03 13:05:28 -08:00
|
|
|
socklen_t 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-17 01:31:15 -08:00
|
|
|
so_err = WSAGetLastError();
|
2010-02-20 10:01:50 -08:00
|
|
|
|
2011-12-21 02:02:30 -08:00
|
|
|
if ((so_err == WSAEINPROGRESS) && !svr->delete_me)
|
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-17 01:31:15 -08:00
|
|
|
so_err = errno;
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2011-12-21 02:02:30 -08:00
|
|
|
if ((so_err == EINPROGRESS) && !svr->delete_me)
|
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
|
|
|
|
2010-11-17 01:31:15 -08:00
|
|
|
if (so_err)
|
2004-04-14 01:51:19 -07:00
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
/* we lost our server! */
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_event_server_error(obj, strerror(so_err));
|
2016-06-13 01:31:51 -07:00
|
|
|
DBG("Connection lost: %s", strerror(so_err));
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_server_kill(obj);
|
2010-11-17 01:31:15 -08:00
|
|
|
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
|
|
|
{
|
2013-12-19 21:07:50 -08:00
|
|
|
if (svr->ecs)
|
|
|
|
{
|
2014-08-22 08:06:27 -07:00
|
|
|
if (ecore_con_socks_svr_init(obj))
|
2013-12-19 21:07:50 -08:00
|
|
|
return ECORE_CON_INPROGRESS;
|
|
|
|
}
|
|
|
|
else
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_event_server_add(obj);
|
2004-04-14 01:51:19 -07:00
|
|
|
}
|
2008-10-01 08:27:52 -07:00
|
|
|
|
2013-03-14 04:48:05 -07:00
|
|
|
if (svr->fd_handler)
|
|
|
|
{
|
|
|
|
if (svr->buf)
|
|
|
|
ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE);
|
|
|
|
else
|
|
|
|
ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
|
|
|
|
}
|
2010-09-17 23:06:05 -07:00
|
|
|
|
2011-12-21 02:02:30 -08:00
|
|
|
if (!svr->delete_me)
|
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-11-16 13:32:50 -08:00
|
|
|
static const char *
|
2011-09-29 14:05:20 -07:00
|
|
|
_ecore_con_pretty_ip(struct sockaddr *client_addr)
|
2010-01-31 03:58:37 -08:00
|
|
|
{
|
2011-09-29 14:04:54 -07:00
|
|
|
#ifndef HAVE_IPV6
|
|
|
|
char ipbuf[INET_ADDRSTRLEN + 1];
|
|
|
|
#else
|
2010-01-31 03:58:37 -08:00
|
|
|
char ipbuf[INET6_ADDRSTRLEN + 1];
|
2011-09-29 14:05:20 -07:00
|
|
|
#endif
|
|
|
|
int family = client_addr->sa_family;
|
|
|
|
void *src;
|
2010-01-31 03:58:37 -08:00
|
|
|
|
2013-12-19 21:07:50 -08:00
|
|
|
switch (family)
|
2010-01-31 03:58:37 -08:00
|
|
|
{
|
2013-12-19 21:07:50 -08:00
|
|
|
case AF_INET:
|
|
|
|
src = &(((struct sockaddr_in *)client_addr)->sin_addr);
|
|
|
|
break;
|
|
|
|
|
2011-09-29 14:05:20 -07:00
|
|
|
#ifdef HAVE_IPV6
|
2013-12-19 21:07:50 -08:00
|
|
|
case AF_INET6:
|
|
|
|
src = &(((struct sockaddr_in6 *)client_addr)->sin6_addr);
|
|
|
|
|
|
|
|
if (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)src))
|
|
|
|
{
|
|
|
|
family = AF_INET;
|
|
|
|
src = (char *)src + 12;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-09-29 14:04:54 -07:00
|
|
|
#endif
|
2013-12-19 21:07:50 -08:00
|
|
|
default:
|
|
|
|
return eina_stringshare_add("0.0.0.0");
|
|
|
|
}
|
2010-01-31 03:58:37 -08:00
|
|
|
|
2011-09-29 14:05:20 -07:00
|
|
|
if (!inet_ntop(family, src, ipbuf, sizeof(ipbuf)))
|
2010-11-16 13:32:50 -08:00
|
|
|
return eina_stringshare_add("0.0.0.0");
|
2010-01-31 03:58:37 -08:00
|
|
|
|
2011-02-10 00:49:23 -08:00
|
|
|
ipbuf[sizeof(ipbuf) - 1] = 0;
|
2010-11-16 13:32:50 -08:00
|
|
|
return eina_stringshare_add(ipbuf);
|
2010-01-31 03:58:37 -08:00
|
|
|
}
|
|
|
|
|
2010-06-24 09:15:56 -07:00
|
|
|
static Eina_Bool
|
2013-12-19 21:07:50 -08:00
|
|
|
_ecore_con_svr_tcp_handler(void *data,
|
2012-11-25 01:55:32 -08:00
|
|
|
Ecore_Fd_Handler *fd_handler EINA_UNUSED)
|
2008-10-30 08:26:11 -07:00
|
|
|
{
|
2014-08-22 08:06:27 -07:00
|
|
|
Ecore_Con_Server *svr_obj = data;
|
2014-08-22 05:14:59 -07:00
|
|
|
Ecore_Con_Client *obj = NULL;
|
2010-11-16 13:32:50 -08:00
|
|
|
unsigned char client_addr[256];
|
2011-04-29 00:34:12 -07:00
|
|
|
unsigned int client_addr_len;
|
2011-12-09 21:25:30 -08:00
|
|
|
const char *clerr = NULL;
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(svr_obj, EFL_NETWORK_SERVER_CLASS);
|
2015-01-30 01:51:52 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
u_long mode = 1;
|
|
|
|
#endif
|
2008-10-30 08:26:11 -07:00
|
|
|
|
2011-12-21 02:02:30 -08: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 */
|
2011-04-29 00:22:53 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
obj = efl_add(EFL_NETWORK_CLIENT_CLASS, NULL);
|
|
|
|
Efl_Network_Client_Data *cl = efl_data_scope_get(obj, EFL_NETWORK_CLIENT_CLASS);
|
2011-04-29 00:22:53 -07:00
|
|
|
if (!cl)
|
|
|
|
{
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_event_server_error(svr_obj, "Memory allocation failure when attempting to add a new client");
|
2011-04-29 00:22:53 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
|
|
|
}
|
2014-08-22 08:06:27 -07:00
|
|
|
cl->host_server = svr_obj;
|
2011-04-29 00:22:53 -07:00
|
|
|
|
2011-04-29 00:34:12 -07:00
|
|
|
client_addr_len = sizeof(client_addr);
|
2010-11-16 13:32:50 -08:00
|
|
|
memset(&client_addr, 0, client_addr_len);
|
2011-04-29 00:22:53 -07:00
|
|
|
cl->fd = accept(svr->fd, (struct sockaddr *)&client_addr, (socklen_t *)&client_addr_len);
|
2015-01-30 02:04:19 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (cl->fd == INVALID_SOCKET) goto error;
|
|
|
|
#else
|
2011-12-09 21:25:30 -08:00
|
|
|
if (cl->fd < 0) goto error;
|
2015-01-30 02:04:19 -08:00
|
|
|
#endif
|
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))
|
2011-02-10 00:49:23 -08:00
|
|
|
{
|
2011-12-09 21:25:30 -08:00
|
|
|
clerr = "Maximum client limit reached";
|
|
|
|
goto error;
|
2011-02-10 00:49:23 -08:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2015-01-30 01:51:52 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (ioctlsocket(cl->fd, FIONBIO, &mode)) goto error;
|
|
|
|
#else
|
2011-12-09 21:25:30 -08:00
|
|
|
if (fcntl(cl->fd, F_SETFL, O_NONBLOCK) < 0) goto error;
|
|
|
|
if (fcntl(cl->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
|
2015-01-30 01:51:52 -08:00
|
|
|
#endif
|
2010-10-13 09:40:52 -07:00
|
|
|
cl->fd_handler = ecore_main_fd_handler_add(cl->fd, ECORE_FD_READ,
|
2014-08-22 05:14:59 -07:00
|
|
|
_ecore_con_svr_cl_handler, obj, NULL, NULL);
|
2011-12-09 21:25:30 -08:00
|
|
|
if (!cl->fd_handler) goto error;
|
2010-10-13 09:40:52 -07:00
|
|
|
|
2011-06-15 11:58:34 -07:00
|
|
|
if ((!svr->upgrade) && (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;
|
2014-08-22 05:14:59 -07:00
|
|
|
if (ecore_con_ssl_client_init(obj))
|
2011-12-09 21:25:30 -08:00
|
|
|
goto error;
|
2010-09-23 21:15:42 -07:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-11-16 13:32:50 -08:00
|
|
|
cl->client_addr = malloc(client_addr_len);
|
|
|
|
if (!cl->client_addr)
|
2011-02-10 00:49:23 -08:00
|
|
|
{
|
2011-12-09 21:25:30 -08:00
|
|
|
clerr = "Memory allocation failure when attempting to add a new client";
|
|
|
|
goto error;
|
2011-02-10 00:49:23 -08:00
|
|
|
}
|
2010-11-16 13:32:50 -08:00
|
|
|
cl->client_addr_len = client_addr_len;
|
|
|
|
memcpy(cl->client_addr, &client_addr, client_addr_len);
|
2011-04-20 07:15:33 -07:00
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
svr->clients = eina_list_append(svr->clients, obj);
|
2010-09-20 12:31:11 -07:00
|
|
|
svr->client_count++;
|
2011-04-20 07:15:33 -07:00
|
|
|
|
2010-09-23 21:15:42 -07:00
|
|
|
if ((!cl->delete_me) && (!cl->handshaking))
|
2014-08-22 05:14:59 -07:00
|
|
|
ecore_con_event_client_add(obj);
|
2011-04-20 07:15:33 -07:00
|
|
|
|
2010-06-24 09:15:56 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2010-09-17 23:06:05 -07:00
|
|
|
|
2011-12-09 21:25:30 -08:00
|
|
|
error:
|
|
|
|
if (cl->fd_handler) ecore_main_fd_handler_del(cl->fd_handler);
|
|
|
|
if (cl->fd >= 0) close(cl->fd);
|
2012-09-06 00:34:00 -07:00
|
|
|
{
|
|
|
|
Ecore_Event *ev;
|
|
|
|
|
|
|
|
EINA_LIST_FREE(cl->event_count, ev)
|
|
|
|
{
|
|
|
|
svr->event_count = eina_list_remove(svr->event_count, ev);
|
|
|
|
ecore_event_del(ev);
|
|
|
|
}
|
|
|
|
}
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_del(obj);
|
2014-08-22 08:06:27 -07:00
|
|
|
if (clerr || errno) ecore_con_event_server_error(svr_obj, clerr ? : strerror(errno));
|
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
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_cl_read(Ecore_Con_Server *obj)
|
2010-09-17 23:06:05 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2011-12-09 23:34:45 -08:00
|
|
|
int num = 0;
|
2011-12-09 14:35:12 -08:00
|
|
|
Eina_Bool lost_server = EINA_TRUE;
|
2011-12-09 23:34:45 -08:00
|
|
|
unsigned char buf[READBUFSIZ];
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2011-12-05 19:32:16 -08:00
|
|
|
DBG("svr=%p", svr);
|
|
|
|
|
2010-10-02 14:13:56 -07:00
|
|
|
/* only possible with non-ssl connections */
|
2014-08-22 08:06:27 -07:00
|
|
|
if (svr->connecting && (svr_try_connect_plain(obj) != ECORE_CON_CONNECTED))
|
2013-12-19 21:07:50 -08:00
|
|
|
return;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2011-12-05 20:48:55 -08:00
|
|
|
if (svr->handshaking && (!svr->ecs_state))
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2010-11-03 12:08:31 -07:00
|
|
|
DBG("Continuing ssl handshake");
|
2014-08-22 08:06:27 -07:00
|
|
|
if (!ecore_con_ssl_server_init(obj))
|
2013-12-19 21:07:50 -08:00
|
|
|
lost_server = EINA_FALSE;
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_server_timer_update(obj);
|
2010-11-03 12:08:31 -07:00
|
|
|
}
|
2011-12-09 23:34:45 -08:00
|
|
|
|
2011-12-05 20:48:55 -08:00
|
|
|
if (svr->ecs_state || !(svr->type & ECORE_CON_SSL))
|
2010-11-03 12:08:31 -07:00
|
|
|
{
|
2011-12-09 23:34:45 -08:00
|
|
|
errno = 0;
|
2015-01-30 05:01:50 -08:00
|
|
|
num = recv(svr->fd, (char *)buf, sizeof(buf), 0);
|
|
|
|
|
2010-12-17 00:44:53 -08:00
|
|
|
/* 0 is not a valid return value for a tcp socket */
|
2015-01-30 05:30:22 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
if ((num > 0) || ((num < 0) && (WSAGetLastError() == WSAEWOULDBLOCK)))
|
|
|
|
#else
|
2011-12-09 23:34:45 -08:00
|
|
|
if ((num > 0) || ((num < 0) && (errno == EAGAIN)))
|
2015-01-30 05:30:22 -08:00
|
|
|
#endif
|
2013-12-19 21:07:50 -08:00
|
|
|
lost_server = EINA_FALSE;
|
2011-12-09 23:34:45 -08:00
|
|
|
else if (num < 0)
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_event_server_error(obj, strerror(errno));
|
2010-11-03 12:08:31 -07:00
|
|
|
}
|
2010-11-03 12:38:00 -07:00
|
|
|
else
|
|
|
|
{
|
2014-08-22 08:06:27 -07:00
|
|
|
num = ecore_con_ssl_server_read(obj, buf, sizeof(buf));
|
2010-12-17 01:02:44 -08:00
|
|
|
/* this is not an actual 0 return, 0 here just means non-fatal error such as EAGAIN */
|
2011-12-09 23:34:45 -08:00
|
|
|
if (num >= 0)
|
2013-12-19 21:07:50 -08:00
|
|
|
lost_server = EINA_FALSE;
|
2010-11-03 12:38:00 -07:00
|
|
|
}
|
2011-04-20 07:15:33 -07:00
|
|
|
|
2010-12-15 23:43:48 -08:00
|
|
|
if ((!svr->delete_me) && (num > 0))
|
2011-12-05 19:32:16 -08:00
|
|
|
{
|
|
|
|
if (svr->ecs_state)
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_socks_read(obj, buf, num);
|
2011-12-05 19:32:16 -08:00
|
|
|
else
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_event_server_data(obj, buf, num, EINA_TRUE);
|
2011-12-05 19:32:16 -08:00
|
|
|
}
|
2004-03-31 08:47:45 -08:00
|
|
|
|
2011-12-09 23:34:45 -08:00
|
|
|
if (lost_server)
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_server_kill(obj);
|
2010-09-17 23:06:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
2013-12-19 21:07:50 -08:00
|
|
|
_ecore_con_cl_handler(void *data,
|
2010-11-03 10:58:37 -07:00
|
|
|
Ecore_Fd_Handler *fd_handler)
|
2010-09-17 23:06:05 -07:00
|
|
|
{
|
2014-08-22 08:06:27 -07:00
|
|
|
Ecore_Con_Server *obj = data;
|
2010-09-29 16:53:00 -07:00
|
|
|
Eina_Bool want_read, want_write;
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2010-09-17 23:06:05 -07:00
|
|
|
|
2011-12-21 02:02:30 -08: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
|
|
|
|
|
|
|
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);
|
|
|
|
|
2011-12-05 19:32:16 -08:00
|
|
|
if ((!svr->ecs_state) && 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;
|
2015-01-30 05:01:50 -08:00
|
|
|
len = recv(svr->fd, (char *)buf, sizeof(buf), MSG_DONTWAIT | MSG_PEEK);
|
2010-11-03 10:58:37 -07:00
|
|
|
DBG("%zu bytes in buffer", len);
|
|
|
|
}
|
2010-09-29 07:52:36 -07:00
|
|
|
#endif
|
2014-08-22 08:06:27 -07:00
|
|
|
if (ecore_con_ssl_server_init(obj))
|
2010-09-23 21:15:42 -07:00
|
|
|
{
|
2016-06-13 01:31:51 -07:00
|
|
|
DBG("ssl handshaking failed!");
|
2010-10-28 03:59:30 -07:00
|
|
|
svr->handshaking = EINA_FALSE;
|
2010-09-23 22:57:03 -07:00
|
|
|
}
|
2010-10-01 18:32:54 -07:00
|
|
|
else if (!svr->ssl_state)
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_event_server_add(obj);
|
2011-12-05 19:32:16 -08:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
|
|
|
}
|
2012-02-14 21:53:50 -08:00
|
|
|
if (svr->ecs && svr->ecs_state && (svr->ecs_state < ECORE_CON_PROXY_STATE_READ) && (!svr->ecs_buf))
|
2011-12-05 19:32:16 -08:00
|
|
|
{
|
2012-02-14 21:53:50 -08:00
|
|
|
if (svr->ecs_state < ECORE_CON_PROXY_STATE_INIT)
|
2010-09-23 22:57:03 -07:00
|
|
|
{
|
2011-12-05 19:32:16 -08:00
|
|
|
INF("PROXY STATE++");
|
|
|
|
svr->ecs_state++;
|
2010-09-23 21:15:42 -07:00
|
|
|
}
|
2014-08-22 08:06:27 -07:00
|
|
|
if (ecore_con_socks_svr_init(obj)) return ECORE_CALLBACK_RENEW;
|
2010-09-23 21:15:42 -07:00
|
|
|
}
|
2011-12-05 19:32:16 -08:00
|
|
|
if (want_read)
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_cl_read(obj);
|
2010-11-03 10:58:37 -07:00
|
|
|
else if (want_write) /* only possible with non-ssl connections */
|
|
|
|
{
|
2014-08-22 08:06:27 -07:00
|
|
|
if (svr->connecting && (!svr_try_connect_plain(obj)) && (!svr->ecs_state))
|
2010-11-03 10:58:37 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_server_flush(obj);
|
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
|
2013-12-19 21:07:50 -08:00
|
|
|
_ecore_con_cl_udp_handler(void *data,
|
2010-11-03 10:58:37 -07:00
|
|
|
Ecore_Fd_Handler *fd_handler)
|
2008-09-25 03:14:31 -07:00
|
|
|
{
|
2010-11-03 12:08:31 -07:00
|
|
|
unsigned char buf[READBUFSIZ];
|
|
|
|
int num;
|
2014-08-22 08:06:27 -07:00
|
|
|
Ecore_Con_Server *obj = data;
|
2010-11-03 12:08:31 -07:00
|
|
|
Eina_Bool want_read, want_write;
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2010-11-03 12:08:31 -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);
|
2008-09-25 03:14:31 -07:00
|
|
|
|
2012-10-04 07:56:22 -07:00
|
|
|
if (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)
|
|
|
|
{
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_server_flush(obj);
|
2010-11-03 12:08:31 -07:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
|
|
|
}
|
|
|
|
|
2015-01-30 05:01:50 -08:00
|
|
|
num = recv(svr->fd, (char *)buf, READBUFSIZ, 0);
|
2010-11-03 12:08:31 -07:00
|
|
|
|
2010-12-17 00:15:52 -08:00
|
|
|
if ((!svr->delete_me) && (num > 0))
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_event_server_data(obj, buf, num, EINA_TRUE);
|
2010-11-03 12:08:31 -07:00
|
|
|
|
2010-12-16 05:16:40 -08:00
|
|
|
if (num < 0 && (errno != EAGAIN) && (errno != EINTR))
|
2011-02-10 00:49:23 -08:00
|
|
|
{
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_event_server_error(obj, strerror(errno));
|
|
|
|
_ecore_con_server_kill(obj);
|
2011-02-10 00:49:23 -08:00
|
|
|
}
|
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
|
2013-12-19 21:07:50 -08:00
|
|
|
_ecore_con_svr_udp_handler(void *data,
|
2010-11-03 10:58:37 -07:00
|
|
|
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];
|
2011-03-03 13:05:28 -08:00
|
|
|
socklen_t client_addr_len = sizeof(client_addr);
|
2010-11-03 12:08:31 -07:00
|
|
|
int num;
|
2014-08-22 08:06:27 -07:00
|
|
|
Ecore_Con_Server *svr_obj = data;
|
2014-08-22 05:14:59 -07:00
|
|
|
Ecore_Con_Client *obj = NULL;
|
2015-01-30 05:11:56 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
u_long mode = 1;
|
|
|
|
#endif
|
2008-09-17 08:08:48 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(svr_obj, EFL_NETWORK_SERVER_CLASS);
|
2011-12-21 02:02:30 -08: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-11-03 12:08:31 -07:00
|
|
|
if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
|
2013-08-05 04:39:19 -07:00
|
|
|
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;
|
|
|
|
|
2010-02-20 10:01:50 -08:00
|
|
|
#ifdef _WIN32
|
2015-01-30 01:51:52 -08:00
|
|
|
if (!ioctlsocket(svr->fd, FIONBIO, &mode))
|
2011-03-03 13:05:28 -08:00
|
|
|
num = recvfrom(svr->fd, (char *)buf, sizeof(buf), 0,
|
2013-12-19 21:07:50 -08:00
|
|
|
(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,
|
2013-12-19 21:07:50 -08:00
|
|
|
(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-12-16 05:16:40 -08:00
|
|
|
if (num < 0 && (errno != EAGAIN) && (errno != EINTR))
|
2010-11-03 12:08:31 -07:00
|
|
|
{
|
2014-08-22 08:06:27 -07:00
|
|
|
ecore_con_event_server_error(svr_obj, strerror(errno));
|
2010-11-03 12:08:31 -07:00
|
|
|
if (!svr->delete_me)
|
2011-11-10 18:44:16 -08:00
|
|
|
ecore_con_event_client_del(NULL);
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_server_kill(svr_obj);
|
2010-11-03 12:08:31 -07:00
|
|
|
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 */
|
2016-08-15 06:44:41 -07:00
|
|
|
obj = efl_add(EFL_NETWORK_CLIENT_CLASS, NULL);
|
|
|
|
Efl_Network_Client_Data *cl = efl_data_scope_get(obj, EFL_NETWORK_CLIENT_CLASS);
|
2010-11-03 12:08:31 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(cl, ECORE_CALLBACK_RENEW);
|
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
cl->host_server = svr_obj;
|
2015-11-20 08:46:38 -08:00
|
|
|
cl->fd = -1;
|
2010-11-16 13:32:50 -08:00
|
|
|
cl->client_addr = malloc(client_addr_len);
|
2010-11-05 18:22:50 -07:00
|
|
|
if (!cl->client_addr)
|
2010-11-03 12:08:31 -07:00
|
|
|
{
|
|
|
|
free(cl);
|
|
|
|
return ECORE_CALLBACK_RENEW;
|
|
|
|
}
|
|
|
|
cl->client_addr_len = client_addr_len;
|
|
|
|
|
|
|
|
memcpy(cl->client_addr, &client_addr, client_addr_len);
|
2014-08-22 05:14:59 -07:00
|
|
|
svr->clients = eina_list_append(svr->clients, obj);
|
2010-11-03 12:08:31 -07:00
|
|
|
svr->client_count++;
|
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
ecore_con_event_client_add(obj);
|
|
|
|
ecore_con_event_client_data(obj, buf, num, EINA_TRUE);
|
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
|
2014-08-22 05:14:59 -07:00
|
|
|
_ecore_con_svr_cl_read(Ecore_Con_Client *obj)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Client_Data *cl = efl_data_scope_get(obj, EFL_NETWORK_CLIENT_CLASS);
|
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
|
|
|
|
2011-05-14 10:52:30 -07:00
|
|
|
DBG("cl=%p", cl);
|
|
|
|
|
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
|
|
|
|
*/
|
2014-08-22 05:14:59 -07:00
|
|
|
if (ecore_con_ssl_client_init(obj))
|
2010-11-03 12:08:31 -07:00
|
|
|
lost_client = EINA_FALSE;
|
2010-09-24 21:22:10 -07:00
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
_ecore_con_cl_timer_update(obj);
|
2010-11-03 12:08:31 -07:00
|
|
|
}
|
2010-09-24 20:02:10 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *host_server = efl_data_scope_get(cl->host_server, EFL_NETWORK_SERVER_CLASS);
|
2014-08-22 08:06:27 -07:00
|
|
|
if (!(host_server->type & ECORE_CON_SSL) && (!cl->upgrade))
|
2010-11-03 12:08:31 -07:00
|
|
|
{
|
2015-01-30 05:01:50 -08:00
|
|
|
num = recv(cl->fd, (char *)buf, sizeof(buf), 0);
|
|
|
|
|
2010-12-17 00:44:53 -08:00
|
|
|
/* 0 is not a valid return value for a tcp socket */
|
2010-12-17 04:09:14 -08:00
|
|
|
if ((num > 0) || ((num < 0) && ((errno == EAGAIN) || (errno == EINTR))))
|
2010-11-03 10:58:37 -07:00
|
|
|
lost_client = EINA_FALSE;
|
2011-02-15 12:17:48 -08:00
|
|
|
else if (num < 0)
|
2014-08-22 05:14:59 -07:00
|
|
|
ecore_con_event_client_error(obj, strerror(errno));
|
2010-11-03 12:08:31 -07:00
|
|
|
}
|
2010-11-03 12:38:00 -07:00
|
|
|
else
|
|
|
|
{
|
2014-08-22 05:14:59 -07:00
|
|
|
num = ecore_con_ssl_client_read(obj, buf, sizeof(buf));
|
2010-12-17 01:02:44 -08:00
|
|
|
/* this is not an actual 0 return, 0 here just means non-fatal error such as EAGAIN */
|
2010-12-15 23:43:48 -08:00
|
|
|
if (num >= 0)
|
2010-11-03 12:38:00 -07:00
|
|
|
lost_client = EINA_FALSE;
|
|
|
|
}
|
2010-09-17 22:30:16 -07:00
|
|
|
|
2010-12-15 23:43:48 -08:00
|
|
|
if ((!cl->delete_me) && (num > 0))
|
2014-08-22 05:14:59 -07:00
|
|
|
ecore_con_event_client_data(obj, buf, num, EINA_TRUE);
|
2010-12-15 23:43:48 -08:00
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
if (lost_client) _ecore_con_client_kill(obj);
|
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
|
2013-12-19 21:07:50 -08:00
|
|
|
_ecore_con_svr_cl_handler(void *data,
|
2010-11-03 10:58:37 -07:00
|
|
|
Ecore_Fd_Handler *fd_handler)
|
2010-09-17 22:30:16 -07:00
|
|
|
{
|
2014-08-22 05:14:59 -07:00
|
|
|
Ecore_Con_Client *obj = data;
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Client_Data *cl = efl_data_scope_get(obj, EFL_NETWORK_CLIENT_CLASS);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
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
|
|
|
{
|
2014-08-22 05:14:59 -07:00
|
|
|
if (ecore_con_ssl_client_init(obj))
|
2010-09-23 21:15:42 -07:00
|
|
|
{
|
2016-06-13 01:31:51 -07:00
|
|
|
DBG("ssl handshaking failed!");
|
2014-08-22 05:14:59 -07:00
|
|
|
_ecore_con_client_kill(obj);
|
2011-12-09 21:42:32 -08:00
|
|
|
return ECORE_CALLBACK_RENEW;
|
2010-09-23 21:15:42 -07:00
|
|
|
}
|
2010-10-01 18:32:54 -07:00
|
|
|
else if (!cl->ssl_state)
|
2014-08-22 05:14:59 -07:00
|
|
|
ecore_con_event_client_add(obj);
|
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))
|
2014-08-22 05:14:59 -07:00
|
|
|
_ecore_con_svr_cl_read(obj);
|
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))
|
2014-08-22 05:14:59 -07:00
|
|
|
_ecore_con_client_flush(obj);
|
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
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_server_flush(Ecore_Con_Server *obj)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2014-04-04 03:35:16 -07:00
|
|
|
int count;
|
|
|
|
size_t num;
|
2013-02-08 00:35:27 -08:00
|
|
|
size_t buf_len;
|
2014-04-04 03:35:16 -07:00
|
|
|
size_t *buf_offset;
|
2012-10-09 01:27:38 -07:00
|
|
|
const unsigned char *buf;
|
2013-02-08 00:35:27 -08:00
|
|
|
Eina_Binbuf *buf_p;
|
2003-09-23 01:09:32 -07:00
|
|
|
|
2011-12-05 20:48:55 -08:00
|
|
|
DBG("(svr=%p,buf=%p)", svr, svr->buf);
|
2013-03-14 04:48:05 -07:00
|
|
|
if (!svr->fd_handler) return;
|
2011-05-14 10:52:30 -07:00
|
|
|
#ifdef _WIN32
|
2014-08-26 03:07:43 -07:00
|
|
|
if (ecore_con_local_win32_server_flush(obj))
|
2011-05-14 10:52:30 -07:00
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2013-03-14 04:48:05 -07:00
|
|
|
if ((!svr->buf) && (!svr->ecs_buf))
|
2011-02-10 11:17:30 -08:00
|
|
|
{
|
|
|
|
ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
|
|
|
|
return;
|
|
|
|
}
|
2004-04-02 10:32:55 -08:00
|
|
|
|
2013-02-08 00:35:27 -08:00
|
|
|
if (svr->buf)
|
|
|
|
{
|
|
|
|
buf_p = svr->buf;
|
|
|
|
buf_offset = &(svr->write_buf_offset);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buf_p = svr->ecs_buf;
|
|
|
|
buf_offset = &(svr->ecs_buf_offset);
|
|
|
|
}
|
|
|
|
buf = eina_binbuf_string_get(buf_p);
|
|
|
|
buf_len = eina_binbuf_length_get(buf_p);
|
|
|
|
num = buf_len - *buf_offset;
|
2010-12-09 13:02:53 -08:00
|
|
|
|
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
|
|
|
|
*/
|
2010-12-09 13:02:53 -08:00
|
|
|
/* we thank Tommy[D] for needing to check negative buffer sizes
|
|
|
|
* here because his system is amazing.
|
|
|
|
*/
|
|
|
|
if (num <= 0) return;
|
2007-08-26 04:17:21 -07:00
|
|
|
|
2011-12-05 20:48:55 -08:00
|
|
|
if ((!svr->ecs_state) && svr->handshaking)
|
2010-09-24 21:22:10 -07:00
|
|
|
{
|
2010-09-28 20:52:32 -07:00
|
|
|
DBG("Continuing ssl handshake");
|
2014-08-22 08:06:27 -07:00
|
|
|
if (ecore_con_ssl_server_init(obj))
|
|
|
|
_ecore_con_server_kill(obj);
|
|
|
|
_ecore_con_server_timer_update(obj);
|
2010-09-24 21:22:10 -07:00
|
|
|
return;
|
|
|
|
}
|
2010-09-24 20:02:10 -07:00
|
|
|
|
2011-12-05 20:48:55 -08:00
|
|
|
if (svr->ecs_state || (!(svr->type & ECORE_CON_SSL)))
|
2015-01-30 02:21:03 -08:00
|
|
|
count = send(svr->fd, (const char *)buf + *buf_offset, num, 0);
|
2008-10-30 08:26:11 -07:00
|
|
|
else
|
2014-08-22 08:06:27 -07:00
|
|
|
count = ecore_con_ssl_server_write(obj, buf + *buf_offset, num);
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2015-01-30 02:21:03 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (count == SOCKET_ERROR)
|
2010-09-28 21:06:28 -07:00
|
|
|
{
|
2015-01-30 02:21:03 -08:00
|
|
|
switch (WSAGetLastError())
|
2013-12-19 21:07:50 -08:00
|
|
|
{
|
2015-01-30 02:21:03 -08:00
|
|
|
case WSAEINTR:
|
|
|
|
case WSAEINPROGRESS:
|
|
|
|
case WSAEWOULDBLOCK:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
LPTSTR s;
|
|
|
|
|
|
|
|
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
2015-01-30 05:09:34 -08:00
|
|
|
FORMAT_MESSAGE_FROM_SYSTEM,
|
|
|
|
NULL, WSAGetLastError(),
|
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
|
|
(LPTSTR)&s, 0, NULL);
|
2015-01-30 05:11:56 -08:00
|
|
|
ecore_con_event_server_error(obj, (char *)s);
|
2015-01-30 02:21:03 -08:00
|
|
|
free(s);
|
2015-01-30 05:11:56 -08:00
|
|
|
_ecore_con_server_kill(obj);
|
2015-01-30 02:21:03 -08:00
|
|
|
}
|
2013-12-19 21:07:50 -08:00
|
|
|
}
|
2010-09-28 21:06:28 -07:00
|
|
|
}
|
2015-01-30 02:21:03 -08:00
|
|
|
#else
|
|
|
|
if (count < 0)
|
|
|
|
{
|
|
|
|
if ((errno != EAGAIN) && (errno != EINTR))
|
|
|
|
{
|
2015-01-30 05:11:56 -08:00
|
|
|
ecore_con_event_server_error(obj, strerror(errno));
|
|
|
|
_ecore_con_server_kill(obj);
|
2015-01-30 02:21:03 -08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-04-02 10:32:55 -08:00
|
|
|
|
2014-08-22 08:06:27 -07:00
|
|
|
if (count && (!svr->ecs_state)) ecore_con_event_server_write(obj, count);
|
2013-02-08 00:35:27 -08:00
|
|
|
|
|
|
|
if (!eina_binbuf_remove(buf_p, 0, count))
|
|
|
|
*buf_offset += count;
|
2011-12-05 19:32:16 -08:00
|
|
|
else
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2013-02-08 00:35:27 -08:00
|
|
|
*buf_offset = 0;
|
|
|
|
buf_len -= count;
|
|
|
|
}
|
|
|
|
if (*buf_offset >= buf_len)
|
|
|
|
{
|
|
|
|
*buf_offset = 0;
|
|
|
|
eina_binbuf_free(buf_p);
|
|
|
|
|
2011-12-05 19:32:16 -08:00
|
|
|
if (svr->ecs_buf)
|
|
|
|
{
|
|
|
|
svr->ecs_buf = NULL;
|
|
|
|
INF("PROXY STATE++");
|
|
|
|
svr->ecs_state++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
svr->buf = NULL;
|
2011-12-10 00:14:50 -08:00
|
|
|
#ifdef TCP_CORK
|
|
|
|
if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK)
|
|
|
|
{
|
|
|
|
int state = 0;
|
|
|
|
if (setsockopt(svr->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
|
|
|
|
/* realistically this isn't anything serious so we can just log and continue */
|
|
|
|
ERR("uncorking failed! %s", strerror(errno));
|
|
|
|
}
|
|
|
|
#endif
|
2011-12-05 19:32:16 -08:00
|
|
|
}
|
2010-07-26 23:30:27 -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);
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
2014-04-11 02:50:47 -07:00
|
|
|
else if (((unsigned int)count < num) && svr->fd_handler)
|
2010-11-04 08:01:05 -07:00
|
|
|
ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE);
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-22 05:14:59 -07:00
|
|
|
_ecore_con_client_flush(Ecore_Con_Client *obj)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Client_Data *cl = efl_data_scope_get(obj, EFL_NETWORK_CLIENT_CLASS);
|
2014-04-04 03:35:16 -07:00
|
|
|
int count = 0;
|
|
|
|
size_t num = 0;
|
2003-09-23 01:09:32 -07:00
|
|
|
|
2013-03-14 04:48:05 -07:00
|
|
|
if (!cl->fd_handler) return;
|
2011-05-14 10:52:30 -07:00
|
|
|
#ifdef _WIN32
|
2014-08-26 03:07:43 -07:00
|
|
|
if (ecore_con_local_win32_client_flush(obj))
|
2011-05-14 10:52:30 -07:00
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2013-03-14 04:48:05 -07:00
|
|
|
if (!cl->buf)
|
2011-02-10 11:17:30 -08:00
|
|
|
{
|
|
|
|
ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ);
|
|
|
|
return;
|
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2010-09-24 21:22:10 -07:00
|
|
|
if (cl->handshaking)
|
|
|
|
{
|
2014-08-22 05:14:59 -07:00
|
|
|
if (ecore_con_ssl_client_init(obj))
|
2010-09-24 21:22:10 -07:00
|
|
|
count = -1;
|
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
_ecore_con_cl_timer_update(obj);
|
2010-09-24 21:22:10 -07:00
|
|
|
}
|
2010-09-24 20:02:10 -07:00
|
|
|
|
|
|
|
if (!count)
|
|
|
|
{
|
2012-07-16 03:30:31 -07:00
|
|
|
if (!cl->buf) return;
|
2011-07-16 06:07:39 -07:00
|
|
|
num = eina_binbuf_length_get(cl->buf) - cl->buf_offset;
|
2010-12-09 13:04:22 -08:00
|
|
|
if (num <= 0) return;
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *host_server = efl_data_scope_get(cl->host_server, EFL_NETWORK_SERVER_CLASS);
|
2014-08-22 08:06:27 -07:00
|
|
|
if (!(host_server->type & ECORE_CON_SSL) && (!cl->upgrade))
|
2015-01-30 05:11:56 -08:00
|
|
|
count = send(cl->fd, (char *)eina_binbuf_string_get(cl->buf) + cl->buf_offset, num, 0);
|
2010-09-24 20:02:10 -07:00
|
|
|
else
|
2014-08-22 05:14:59 -07:00
|
|
|
count = ecore_con_ssl_client_write(obj, eina_binbuf_string_get(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-12-11 08:51:29 -08:00
|
|
|
if ((errno != EAGAIN) && (errno != EINTR) && (!cl->delete_me))
|
|
|
|
{
|
2014-08-22 05:14:59 -07:00
|
|
|
ecore_con_event_client_error(obj, strerror(errno));
|
|
|
|
_ecore_con_client_kill(obj);
|
2010-12-11 08:51:29 -08: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
|
|
|
|
2014-08-22 05:14:59 -07:00
|
|
|
if (count) ecore_con_event_client_write(obj, count);
|
2012-03-13 06:44:18 -07:00
|
|
|
cl->buf_offset += count, num -= count;
|
2011-07-16 06:07:39 -07:00
|
|
|
if (cl->buf_offset >= eina_binbuf_length_get(cl->buf))
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2010-07-26 23:30:27 -07:00
|
|
|
cl->buf_offset = 0;
|
2011-07-16 06:07:39 -07:00
|
|
|
eina_binbuf_free(cl->buf);
|
2010-07-26 23:30:27 -07:00
|
|
|
cl->buf = NULL;
|
2011-12-10 00:14:50 -08:00
|
|
|
#ifdef TCP_CORK
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *host_server = efl_data_scope_get(cl->host_server, EFL_NETWORK_SERVER_CLASS);
|
2014-08-22 08:06:27 -07:00
|
|
|
if ((host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_CORK)
|
2011-12-10 00:14:50 -08:00
|
|
|
{
|
|
|
|
int state = 0;
|
|
|
|
if (setsockopt(cl->fd, IPPROTO_TCP, TCP_CORK, (char *)&state, sizeof(int)) < 0)
|
|
|
|
/* realistically this isn't anything serious so we can just log and continue */
|
|
|
|
ERR("uncorking failed! %s", strerror(errno));
|
|
|
|
}
|
|
|
|
#endif
|
2010-07-26 23:30:27 -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);
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
2014-04-11 02:26:18 -07:00
|
|
|
else if (cl->fd_handler)
|
2010-11-04 08:01:05 -07:00
|
|
|
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
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_event_client_add_free(Ecore_Con_Server *obj,
|
2013-12-19 21:07:50 -08:00
|
|
|
void *ev)
|
2006-03-19 21:53:12 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2006-03-19 21:53:12 -08:00
|
|
|
Ecore_Con_Event_Client_Add *e;
|
|
|
|
|
|
|
|
e = ev;
|
2011-11-10 18:44:16 -08:00
|
|
|
if (e->client)
|
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Client_Data *cl = efl_data_scope_get(e->client, EFL_NETWORK_CLIENT_CLASS);
|
2013-01-02 22:56:42 -08:00
|
|
|
Eina_Bool svrfreed = EINA_FALSE;
|
2013-12-19 21:07:50 -08:00
|
|
|
|
2015-06-24 21:18:22 -07:00
|
|
|
if ((svr) && (cl))
|
2011-11-10 18:44:16 -08:00
|
|
|
{
|
2015-06-24 21:18:22 -07:00
|
|
|
cl->event_count = eina_list_remove(cl->event_count, e);
|
|
|
|
if (cl->host_server)
|
2013-01-02 22:56:42 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *host_server = efl_data_scope_get(cl->host_server, EFL_NETWORK_SERVER_CLASS);
|
2015-06-24 21:18:22 -07:00
|
|
|
if (host_server)
|
|
|
|
host_server->event_count = eina_list_remove(host_server->event_count, ev);
|
|
|
|
if ((!svr->event_count) && (svr->delete_me))
|
|
|
|
{
|
|
|
|
_ecore_con_server_free(obj);
|
|
|
|
svrfreed = EINA_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!svrfreed)
|
|
|
|
{
|
|
|
|
if ((!cl->event_count) && (cl->delete_me))
|
|
|
|
ecore_con_client_del(e->client);
|
2013-01-02 22:56:42 -08:00
|
|
|
}
|
2011-11-10 18:44:16 -08:00
|
|
|
}
|
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2011-11-06 04:26:00 -08:00
|
|
|
ecore_con_event_client_add_free(e);
|
2011-11-10 18:44:16 -08:00
|
|
|
_ecore_con_event_count--;
|
|
|
|
if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
|
|
|
|
ecore_con_mempool_shutdown();
|
2006-03-19 21:53:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_event_client_del_free(Ecore_Con_Server *obj,
|
2013-12-19 21:07:50 -08:00
|
|
|
void *ev)
|
2006-03-19 21:53:12 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2006-03-19 21:53:12 -08:00
|
|
|
Ecore_Con_Event_Client_Del *e;
|
|
|
|
|
|
|
|
e = ev;
|
2011-11-10 18:44:16 -08:00
|
|
|
if (e->client)
|
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Client_Data *cl = efl_data_scope_get(e->client, EFL_NETWORK_CLIENT_CLASS);
|
2013-01-02 22:56:42 -08:00
|
|
|
Eina_Bool svrfreed = EINA_FALSE;
|
2013-12-19 21:07:50 -08:00
|
|
|
|
2015-06-24 21:18:22 -07:00
|
|
|
if ((svr) && (cl))
|
2011-11-10 18:44:16 -08:00
|
|
|
{
|
2015-06-24 21:18:22 -07:00
|
|
|
cl->event_count = eina_list_remove(cl->event_count, e);
|
|
|
|
if (cl->host_server)
|
2013-01-02 22:56:42 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *host_server = efl_data_scope_get(cl->host_server, EFL_NETWORK_SERVER_CLASS);
|
2015-06-24 21:18:22 -07:00
|
|
|
if (host_server)
|
|
|
|
host_server->event_count = eina_list_remove(host_server->event_count, ev);
|
|
|
|
if ((!svr->event_count) && (svr->delete_me))
|
|
|
|
{
|
|
|
|
_ecore_con_server_free(obj);
|
|
|
|
svrfreed = EINA_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!svrfreed)
|
|
|
|
{
|
|
|
|
if (!cl->event_count)
|
|
|
|
_ecore_con_client_free(e->client);
|
2013-01-02 22:56:42 -08:00
|
|
|
}
|
2011-11-10 18:44:16 -08:00
|
|
|
}
|
|
|
|
}
|
2011-11-06 04:26:00 -08:00
|
|
|
ecore_con_event_client_del_free(e);
|
2011-11-10 18:44:16 -08:00
|
|
|
_ecore_con_event_count--;
|
|
|
|
if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
|
|
|
|
ecore_con_mempool_shutdown();
|
2006-03-19 21:53:12 -08:00
|
|
|
}
|
|
|
|
|
2011-09-13 16:03:26 -07:00
|
|
|
static void
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_event_client_write_free(Ecore_Con_Server *obj,
|
2011-09-13 16:03:26 -07:00
|
|
|
Ecore_Con_Event_Client_Write *e)
|
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2011-11-10 18:44:16 -08:00
|
|
|
if (e->client)
|
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Client_Data *cl = efl_data_scope_get(e->client, EFL_NETWORK_CLIENT_CLASS);
|
2013-01-02 22:56:42 -08:00
|
|
|
Eina_Bool svrfreed = EINA_FALSE;
|
2013-12-19 21:07:50 -08:00
|
|
|
|
2015-06-24 21:18:22 -07:00
|
|
|
if ((svr) && (cl))
|
2011-11-10 18:44:16 -08:00
|
|
|
{
|
2015-06-24 21:18:22 -07:00
|
|
|
cl->event_count = eina_list_remove(cl->event_count, e);
|
|
|
|
if (cl->host_server)
|
2013-01-02 22:56:42 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *host_server = efl_data_scope_get(cl->host_server, EFL_NETWORK_SERVER_CLASS);
|
2015-06-24 21:18:22 -07:00
|
|
|
if (host_server)
|
|
|
|
host_server->event_count = eina_list_remove(host_server->event_count, e);
|
|
|
|
if ((!svr->event_count) && (svr->delete_me))
|
|
|
|
{
|
|
|
|
_ecore_con_server_free(obj);
|
|
|
|
svrfreed = EINA_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!svrfreed)
|
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *host_server = efl_data_scope_get(cl->host_server, EFL_NETWORK_SERVER_CLASS);
|
2015-06-24 21:18:22 -07:00
|
|
|
if (((!cl->event_count) && (cl->delete_me)) ||
|
|
|
|
((cl->host_server &&
|
|
|
|
((host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP ||
|
|
|
|
(host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_MCAST))))
|
|
|
|
ecore_con_client_del(e->client);
|
2013-01-02 22:56:42 -08:00
|
|
|
}
|
2011-11-10 18:44:16 -08:00
|
|
|
}
|
|
|
|
}
|
2011-11-06 04:26:00 -08:00
|
|
|
ecore_con_event_client_write_free(e);
|
2011-11-10 18:44:16 -08:00
|
|
|
_ecore_con_event_count--;
|
|
|
|
if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
|
|
|
|
ecore_con_mempool_shutdown();
|
2011-09-13 16:03:26 -07:00
|
|
|
}
|
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
static void
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_event_client_data_free(Ecore_Con_Server *obj,
|
2013-12-19 21:07:50 -08:00
|
|
|
void *ev)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2003-09-23 01:09:32 -07:00
|
|
|
Ecore_Con_Event_Client_Data *e;
|
|
|
|
|
|
|
|
e = ev;
|
2011-11-10 18:44:16 -08:00
|
|
|
if (e->client)
|
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Client_Data *cl = efl_data_scope_get(e->client, EFL_NETWORK_CLIENT_CLASS);
|
2013-01-02 22:56:42 -08:00
|
|
|
Eina_Bool svrfreed = EINA_FALSE;
|
2013-12-19 21:07:50 -08:00
|
|
|
|
2015-06-24 21:18:22 -07:00
|
|
|
if ((svr) && (cl))
|
2013-01-02 22:56:42 -08:00
|
|
|
{
|
2015-06-24 21:18:22 -07:00
|
|
|
cl->event_count = eina_list_remove(cl->event_count, e);
|
|
|
|
if (cl->host_server)
|
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *host_server = efl_data_scope_get(cl->host_server, EFL_NETWORK_SERVER_CLASS);
|
2015-06-24 21:18:22 -07:00
|
|
|
if (host_server)
|
|
|
|
host_server->event_count = eina_list_remove(host_server->event_count, ev);
|
|
|
|
}
|
|
|
|
if ((!svr->event_count) && (svr->delete_me))
|
|
|
|
{
|
|
|
|
_ecore_con_server_free(obj);
|
|
|
|
svrfreed = EINA_TRUE;
|
|
|
|
}
|
|
|
|
if (!svrfreed)
|
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *host_server = efl_data_scope_get(cl->host_server, EFL_NETWORK_SERVER_CLASS);
|
2015-06-24 21:18:22 -07:00
|
|
|
if (((!cl->event_count) && (cl->delete_me)) ||
|
|
|
|
((cl->host_server &&
|
|
|
|
((host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP ||
|
|
|
|
(host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_MCAST))))
|
|
|
|
ecore_con_client_del(e->client);
|
|
|
|
}
|
2013-01-02 22:56:42 -08:00
|
|
|
}
|
2011-11-10 18:44:16 -08:00
|
|
|
}
|
|
|
|
free(e->data);
|
2011-11-06 04:26:00 -08:00
|
|
|
ecore_con_event_client_data_free(e);
|
2011-11-10 18:44:16 -08:00
|
|
|
_ecore_con_event_count--;
|
|
|
|
if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
|
|
|
|
ecore_con_mempool_shutdown();
|
2006-03-19 21:53:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-11-25 01:55:32 -08:00
|
|
|
_ecore_con_event_server_add_free(void *data EINA_UNUSED,
|
2013-12-19 21:07:50 -08:00
|
|
|
void *ev)
|
2006-03-19 21:53:12 -08:00
|
|
|
{
|
|
|
|
Ecore_Con_Event_Server_Add *e;
|
|
|
|
|
|
|
|
e = ev;
|
2011-11-10 18:44:16 -08:00
|
|
|
if (e->server)
|
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(e->server, EFL_NETWORK_SERVER_CLASS);
|
2015-06-24 21:18:22 -07:00
|
|
|
if (svr)
|
|
|
|
{
|
|
|
|
svr->event_count = eina_list_remove(svr->event_count, ev);
|
|
|
|
if ((!svr->event_count) && (svr->delete_me))
|
|
|
|
_ecore_con_server_free(e->server);
|
|
|
|
}
|
2011-11-10 18:44:16 -08:00
|
|
|
}
|
2011-11-06 04:26:00 -08:00
|
|
|
ecore_con_event_server_add_free(e);
|
2011-11-10 18:44:16 -08:00
|
|
|
_ecore_con_event_count--;
|
|
|
|
if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
|
|
|
|
ecore_con_mempool_shutdown();
|
2006-03-19 21:53:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-11-25 01:55:32 -08:00
|
|
|
_ecore_con_event_server_del_free(void *data EINA_UNUSED,
|
2013-12-19 21:07:50 -08:00
|
|
|
void *ev)
|
2006-03-19 21:53:12 -08:00
|
|
|
{
|
|
|
|
Ecore_Con_Event_Server_Del *e;
|
|
|
|
|
|
|
|
e = ev;
|
2011-11-10 18:44:16 -08:00
|
|
|
if (e->server)
|
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(e->server, EFL_NETWORK_SERVER_CLASS);
|
2015-06-24 21:18:22 -07:00
|
|
|
if (svr)
|
|
|
|
{
|
|
|
|
svr->event_count = eina_list_remove(svr->event_count, ev);
|
|
|
|
if (!svr->event_count)
|
|
|
|
_ecore_con_server_free(e->server);
|
|
|
|
}
|
2011-11-10 18:44:16 -08:00
|
|
|
}
|
2011-11-06 04:26:00 -08:00
|
|
|
ecore_con_event_server_del_free(e);
|
2011-11-10 18:44:16 -08:00
|
|
|
_ecore_con_event_count--;
|
|
|
|
if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
|
|
|
|
ecore_con_mempool_shutdown();
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
|
|
|
|
2011-09-13 16:03:26 -07:00
|
|
|
static void
|
2012-11-25 01:55:32 -08:00
|
|
|
_ecore_con_event_server_write_free(void *data EINA_UNUSED,
|
2011-09-13 16:03:26 -07:00
|
|
|
Ecore_Con_Event_Server_Write *e)
|
|
|
|
{
|
2011-11-10 18:44:16 -08:00
|
|
|
if (e->server)
|
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(e->server, EFL_NETWORK_SERVER_CLASS);
|
2015-06-24 21:18:22 -07:00
|
|
|
if (svr)
|
|
|
|
{
|
|
|
|
svr->event_count = eina_list_remove(svr->event_count, e);
|
|
|
|
if ((!svr->event_count) && (svr->delete_me))
|
|
|
|
_ecore_con_server_free(e->server);
|
|
|
|
}
|
2011-11-10 18:44:16 -08:00
|
|
|
}
|
2011-11-06 04:26:00 -08:00
|
|
|
ecore_con_event_server_write_free(e);
|
2011-11-10 18:44:16 -08:00
|
|
|
_ecore_con_event_count--;
|
|
|
|
if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
|
|
|
|
ecore_con_mempool_shutdown();
|
2011-09-13 16:03:26 -07:00
|
|
|
}
|
|
|
|
|
2003-09-23 01:09:32 -07:00
|
|
|
static void
|
2012-11-25 01:55:32 -08:00
|
|
|
_ecore_con_event_server_data_free(void *data EINA_UNUSED,
|
2013-12-19 21:07:50 -08:00
|
|
|
void *ev)
|
2003-09-23 01:09:32 -07:00
|
|
|
{
|
|
|
|
Ecore_Con_Event_Server_Data *e;
|
|
|
|
|
|
|
|
e = ev;
|
2011-11-10 18:44:16 -08:00
|
|
|
if (e->server)
|
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(e->server, EFL_NETWORK_SERVER_CLASS);
|
2015-06-24 21:18:22 -07:00
|
|
|
if (svr)
|
|
|
|
{
|
|
|
|
svr->event_count = eina_list_remove(svr->event_count, ev);
|
|
|
|
if ((!svr->event_count) && (svr->delete_me))
|
|
|
|
_ecore_con_server_free(e->server);
|
|
|
|
}
|
2011-11-10 18:44:16 -08:00
|
|
|
}
|
2011-02-10 11:17:30 -08:00
|
|
|
|
2011-11-10 18:44:16 -08:00
|
|
|
free(e->data);
|
2011-11-06 04:26:00 -08:00
|
|
|
ecore_con_event_server_data_free(e);
|
2011-11-10 18:44:16 -08:00
|
|
|
_ecore_con_event_count--;
|
|
|
|
if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
|
|
|
|
ecore_con_mempool_shutdown();
|
2011-02-10 11:17:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-11-25 01:55:32 -08:00
|
|
|
_ecore_con_event_server_error_free(void *data EINA_UNUSED, Ecore_Con_Event_Server_Error *e)
|
2011-02-10 11:17:30 -08:00
|
|
|
{
|
2011-11-10 18:44:16 -08:00
|
|
|
if (e->server)
|
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(e->server, EFL_NETWORK_SERVER_CLASS);
|
2015-06-24 21:18:22 -07:00
|
|
|
if (svr)
|
|
|
|
{
|
|
|
|
svr->event_count = eina_list_remove(svr->event_count, e);
|
|
|
|
if ((!svr->event_count) && (svr->delete_me))
|
|
|
|
_ecore_con_server_free(e->server);
|
|
|
|
}
|
2011-11-10 18:44:16 -08:00
|
|
|
}
|
|
|
|
free(e->error);
|
2011-11-06 04:26:00 -08:00
|
|
|
ecore_con_event_server_error_free(e);
|
2011-11-10 18:44:16 -08:00
|
|
|
_ecore_con_event_count--;
|
|
|
|
if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
|
|
|
|
ecore_con_mempool_shutdown();
|
2011-02-10 11:17:30 -08:00
|
|
|
}
|
2010-07-26 23:30:27 -07:00
|
|
|
|
2011-02-10 11:17:30 -08:00
|
|
|
static void
|
2014-08-22 08:06:27 -07:00
|
|
|
_ecore_con_event_client_error_free(Ecore_Con_Server *obj, Ecore_Con_Event_Client_Error *e)
|
2011-02-10 11:17:30 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2011-11-10 18:44:16 -08:00
|
|
|
if (e->client)
|
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Client_Data *cl = efl_data_scope_get(e->client, EFL_NETWORK_CLIENT_CLASS);
|
2013-01-02 22:56:42 -08:00
|
|
|
Eina_Bool svrfreed = EINA_FALSE;
|
2013-12-19 21:07:50 -08:00
|
|
|
|
2015-06-24 21:18:22 -07:00
|
|
|
if ((svr) && (cl))
|
2011-11-10 18:44:16 -08:00
|
|
|
{
|
2015-06-24 21:18:22 -07:00
|
|
|
if (eina_list_data_find(svr->clients, e->client))
|
2013-01-02 22:56:42 -08:00
|
|
|
{
|
2015-06-24 21:18:22 -07:00
|
|
|
cl->event_count = eina_list_remove(cl->event_count, e);
|
|
|
|
if ((!cl->event_count) && (cl->delete_me))
|
|
|
|
{
|
|
|
|
_ecore_con_client_free(e->client);
|
|
|
|
svrfreed = EINA_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
svr->event_count = eina_list_remove(svr->event_count, e);
|
|
|
|
if (!svrfreed)
|
|
|
|
{
|
|
|
|
if ((!svr->event_count) && (svr->delete_me))
|
|
|
|
_ecore_con_server_free(obj);
|
2013-01-02 22:56:42 -08:00
|
|
|
}
|
|
|
|
}
|
2011-11-10 18:44:16 -08:00
|
|
|
}
|
|
|
|
free(e->error);
|
2011-11-06 04:26:00 -08:00
|
|
|
ecore_con_event_client_error_free(e);
|
2011-11-10 18:44:16 -08:00
|
|
|
_ecore_con_event_count--;
|
|
|
|
if ((!_ecore_con_event_count) && (!_ecore_con_init_count))
|
|
|
|
ecore_con_mempool_shutdown();
|
2003-09-23 01:09:32 -07:00
|
|
|
}
|
2010-07-22 04:32:55 -07:00
|
|
|
|
|
|
|
static void
|
2013-12-19 21:07:50 -08:00
|
|
|
_ecore_con_lookup_done(void *data,
|
2010-11-03 10:58:37 -07:00
|
|
|
Ecore_Con_Info *infos)
|
2010-07-22 04:32:55 -07:00
|
|
|
{
|
2014-08-22 08:06:27 -07:00
|
|
|
Ecore_Con_Server *obj = data;
|
2010-07-22 04:32:55 -07:00
|
|
|
Ecore_Con_Lookup *lk;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
|
2015-06-24 21:18:22 -07:00
|
|
|
if (!svr) return;
|
2010-07-22 04:32:55 -07:00
|
|
|
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(lk);
|
|
|
|
}
|
2010-11-03 10:58:37 -07:00
|
|
|
|
2016-05-11 05:00:57 -07:00
|
|
|
#include "efl_network.eo.c"
|
2016-02-12 12:02:01 -08:00
|
|
|
#include "efl_network_client.eo.c"
|
2016-02-04 23:09:53 -08:00
|
|
|
#include "efl_network_server.eo.c"
|
2016-01-04 12:35:37 -08:00
|
|
|
#include "efl_network_connector.eo.c"
|
efl.net: socket, server and dialer for TCP.
Efl.Net.Server defines how to accept new connections, doing the
bind(), listen() and accept() for protocols such as TCP.
Efl.Net.Dialer defines to to reach a server.
Both are based on Efl.Net.Socket as communication interface that is
based on Efl.Io.Reader, Efl.Io.Writer and Efl.Io.Closer, thus being
usable with code such as Efl.Io.Copier.
The Server will emit an event "client,add" with the established
Socket, which is a child and can be closed by both the server or the
user.
The Dialer extends the Socket and allows for creating one given an
address, that will be resolved and connected.
TCP is the initial implementation so we an validate the
interfaces. UDP, Unix-Local and SSL will come later as derivate
classes.
The examples are documented and should cover the basic principles:
- efl_io_copier_example can accept "tcp://IP:PORT" and will work as a
"netcat", can send data from socket, file or stdin to a socket,
file, stdout or stderr.
- efl_net_server_example listens for connections and can either reply
"Hello World!" and take some data or work as an echo-server,
looping back all received data to the user.
More complex interactions that require a "chat" between client and
server will be covered with new classes later, such as a queue that
empties itself once data is read.
2016-08-17 21:53:16 -07:00
|
|
|
|
|
|
|
Eina_Bool
|
|
|
|
efl_net_ip_port_fmt(char *buf, int buflen, const struct sockaddr *addr)
|
|
|
|
{
|
|
|
|
char p[INET6_ADDRSTRLEN];
|
|
|
|
const void *mem;
|
|
|
|
unsigned short port;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
if (addr->sa_family == AF_INET)
|
|
|
|
{
|
|
|
|
const struct sockaddr_in *a = (const struct sockaddr_in *)addr;
|
|
|
|
mem = &a->sin_addr;
|
|
|
|
port = ntohs(a->sin_port);
|
|
|
|
}
|
|
|
|
else if (addr->sa_family == AF_INET6)
|
|
|
|
{
|
|
|
|
const struct sockaddr_in6 *a = (const struct sockaddr_in6 *)addr;
|
|
|
|
mem = &a->sin6_addr;
|
|
|
|
port = ntohs(a->sin6_port);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("unsupported address family: %d", addr->sa_family);
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!inet_ntop(addr->sa_family, mem, p, sizeof(p)))
|
|
|
|
{
|
|
|
|
ERR("inet_ntop(%d, %p, %p, %zd): %s",
|
|
|
|
addr->sa_family, mem, p, sizeof(p), strerror(errno));
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addr->sa_family == AF_INET)
|
|
|
|
r = snprintf(buf, buflen, "%s:%hu", p, port);
|
|
|
|
else
|
|
|
|
r = snprintf(buf, buflen, "[%s]:%hu", p, port);
|
|
|
|
|
|
|
|
if (r < 0)
|
|
|
|
{
|
|
|
|
ERR("could not snprintf(): %s", strerror(errno));
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
else if (r > buflen)
|
|
|
|
{
|
|
|
|
ERR("buffer is too small: %d, required %d", buflen, r);
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
2016-08-24 08:34:59 -07:00
|
|
|
|
|
|
|
int
|
|
|
|
efl_net_socket4(int domain, int type, int protocol, Eina_Bool close_on_exec)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
#ifdef SOCK_CLOEXEC
|
|
|
|
if (close_on_exec) type |= SOCK_CLOEXEC;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
fd = socket(domain, type, protocol);
|
|
|
|
if (fd < 0) return fd;
|
|
|
|
|
|
|
|
#ifndef SOCK_CLOEXEC
|
|
|
|
if (close_on_exec)
|
|
|
|
{
|
|
|
|
if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
|
|
|
|
{
|
|
|
|
int errno_bkp = errno;
|
|
|
|
ERR("fcntl(%d, F_SETFD, FD_CLOEXEC): %s", fd, strerror(errno));
|
|
|
|
close(fd);
|
|
|
|
errno = errno_bkp;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|