forked from enlightenment/efl
implement full event-driven error messaging api for all non-curl ecore_con
docs are in the header, happy birthday cedric SVN revision: 56894
This commit is contained in:
parent
54baacb790
commit
daafddb571
|
@ -22,4 +22,10 @@
|
||||||
|
|
||||||
2011-02-10 Mike Blumenkrantz
|
2011-02-10 Mike Blumenkrantz
|
||||||
|
|
||||||
* added some more possibly useless safety checks to ecore_con_ares
|
* Added some more possibly useless safety checks to ecore_con_ares
|
||||||
|
|
||||||
|
2011-02-10 Mike Blumenkrantz
|
||||||
|
|
||||||
|
* Implement event-driven error message api for all non-curl ecore_con
|
||||||
|
+ECORE_CON_EVENT_CLIENT_ERROR, ECORE_CON_EVENT_SERVER_ERROR events
|
||||||
|
+Ecore_Con_Event_Server_Error, Ecore_Con_Event_Client_Error types
|
||||||
|
|
|
@ -147,6 +147,12 @@ typedef struct _Ecore_Con_Event_Client_Add Ecore_Con_Event_Client_Add;
|
||||||
*/
|
*/
|
||||||
typedef struct _Ecore_Con_Event_Client_Del Ecore_Con_Event_Client_Del;
|
typedef struct _Ecore_Con_Event_Client_Del Ecore_Con_Event_Client_Del;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef Ecore_Con_Event_Client_Error
|
||||||
|
* Used as the @p data param for the corresponding event
|
||||||
|
*/
|
||||||
|
typedef struct _Ecore_Con_Event_Client_Error Ecore_Con_Event_Client_Error;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef Ecore_Con_Event_Server_Add
|
* @typedef Ecore_Con_Event_Server_Add
|
||||||
* Used as the @p data param for the corresponding event
|
* Used as the @p data param for the corresponding event
|
||||||
|
@ -159,6 +165,12 @@ typedef struct _Ecore_Con_Event_Server_Add Ecore_Con_Event_Server_Add;
|
||||||
*/
|
*/
|
||||||
typedef struct _Ecore_Con_Event_Server_Del Ecore_Con_Event_Server_Del;
|
typedef struct _Ecore_Con_Event_Server_Del Ecore_Con_Event_Server_Del;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef Ecore_Con_Event_Server_Error
|
||||||
|
* Used as the @p data param for the corresponding event
|
||||||
|
*/
|
||||||
|
typedef struct _Ecore_Con_Event_Server_Error Ecore_Con_Event_Server_Error;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef Ecore_Con_Event_Client_Data
|
* @typedef Ecore_Con_Event_Client_Data
|
||||||
* Used as the @p data param for the corresponding event
|
* Used as the @p data param for the corresponding event
|
||||||
|
@ -207,6 +219,16 @@ struct _Ecore_Con_Event_Client_Del
|
||||||
Ecore_Con_Client *client; /** the client that was lost */
|
Ecore_Con_Client *client; /** the client that was lost */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @struct _Ecore_Con_Event_Client_Error
|
||||||
|
* Used as the @p data param for the @ref ECORE_CON_EVENT_CLIENT_ERROR event
|
||||||
|
*/
|
||||||
|
struct _Ecore_Con_Event_Client_Error
|
||||||
|
{
|
||||||
|
Ecore_Con_Client *client; /** the client for which an error occurred */
|
||||||
|
char *error; /**< the error string describing what happened */
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @struct _Ecore_Con_Event_Server_Add
|
* @struct _Ecore_Con_Event_Server_Add
|
||||||
* Used as the @p data param for the @ref ECORE_CON_EVENT_SERVER_ADD event
|
* Used as the @p data param for the @ref ECORE_CON_EVENT_SERVER_ADD event
|
||||||
|
@ -225,6 +247,16 @@ struct _Ecore_Con_Event_Server_Del
|
||||||
Ecore_Con_Server *server; /** the client that was lost */
|
Ecore_Con_Server *server; /** the client that was lost */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @struct _Ecore_Con_Event_Server_Error
|
||||||
|
* Used as the @p data param for the @ref ECORE_CON_EVENT_SERVER_ERROR event
|
||||||
|
*/
|
||||||
|
struct _Ecore_Con_Event_Server_Error
|
||||||
|
{
|
||||||
|
Ecore_Con_Server *server; /** the server for which an error occurred */
|
||||||
|
char *error; /**< the error string describing what happened */
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @struct _Ecore_Con_Event_Client_Data
|
* @struct _Ecore_Con_Event_Client_Data
|
||||||
* Used as the @p data param for the @ref ECORE_CON_EVENT_CLIENT_DATA event
|
* Used as the @p data param for the @ref ECORE_CON_EVENT_CLIENT_DATA event
|
||||||
|
@ -291,10 +323,14 @@ struct _Ecore_Con_Event_Url_Progress
|
||||||
EAPI extern int ECORE_CON_EVENT_CLIENT_ADD;
|
EAPI extern int ECORE_CON_EVENT_CLIENT_ADD;
|
||||||
/** A client has disconnected from the server */
|
/** A client has disconnected from the server */
|
||||||
EAPI extern int ECORE_CON_EVENT_CLIENT_DEL;
|
EAPI extern int ECORE_CON_EVENT_CLIENT_DEL;
|
||||||
|
/** A client experienced an error */
|
||||||
|
EAPI extern int ECORE_CON_EVENT_CLIENT_ERROR;
|
||||||
/** A server was created */
|
/** A server was created */
|
||||||
EAPI extern int ECORE_CON_EVENT_SERVER_ADD;
|
EAPI extern int ECORE_CON_EVENT_SERVER_ADD;
|
||||||
/** A server connection was lost */
|
/** A server connection was lost */
|
||||||
EAPI extern int ECORE_CON_EVENT_SERVER_DEL;
|
EAPI extern int ECORE_CON_EVENT_SERVER_DEL;
|
||||||
|
/** A server experienced an error */
|
||||||
|
EAPI extern int ECORE_CON_EVENT_SERVER_ERROR;
|
||||||
/** A client connected to the server has sent data */
|
/** A client connected to the server has sent data */
|
||||||
EAPI extern int ECORE_CON_EVENT_CLIENT_DATA;
|
EAPI extern int ECORE_CON_EVENT_CLIENT_DATA;
|
||||||
/** A server connection object has data */
|
/** A server connection object has data */
|
||||||
|
|
|
@ -43,6 +43,12 @@
|
||||||
#include "Ecore_Con.h"
|
#include "Ecore_Con.h"
|
||||||
#include "ecore_con_private.h"
|
#include "ecore_con_private.h"
|
||||||
|
|
||||||
|
static void _ecore_con_event_server_error_free(void *data __UNUSED__,
|
||||||
|
Ecore_Con_Event_Server_Error *e);
|
||||||
|
static void _ecore_con_event_client_error_free(void *data __UNUSED__,
|
||||||
|
Ecore_Con_Event_Client_Error *e);
|
||||||
|
|
||||||
|
|
||||||
static Eina_Bool _ecore_con_client_timer(Ecore_Con_Client *cl);
|
static Eina_Bool _ecore_con_client_timer(Ecore_Con_Client *cl);
|
||||||
static void _ecore_con_cl_timer_update(Ecore_Con_Client *cl);
|
static void _ecore_con_cl_timer_update(Ecore_Con_Client *cl);
|
||||||
|
|
||||||
|
@ -58,6 +64,7 @@ static void _ecore_con_cb_udp_listen(void *data,
|
||||||
static void _ecore_con_server_free(Ecore_Con_Server *svr);
|
static void _ecore_con_server_free(Ecore_Con_Server *svr);
|
||||||
static void _ecore_con_client_free(Ecore_Con_Client *cl);
|
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,
|
static Eina_Bool _ecore_con_svr_tcp_handler(void *data,
|
||||||
Ecore_Fd_Handler *fd_handler);
|
Ecore_Fd_Handler *fd_handler);
|
||||||
static Eina_Bool _ecore_con_cl_handler(void *data,
|
static Eina_Bool _ecore_con_cl_handler(void *data,
|
||||||
|
@ -100,6 +107,8 @@ EAPI int ECORE_CON_EVENT_SERVER_ADD = 0;
|
||||||
EAPI int ECORE_CON_EVENT_SERVER_DEL = 0;
|
EAPI int ECORE_CON_EVENT_SERVER_DEL = 0;
|
||||||
EAPI int ECORE_CON_EVENT_CLIENT_DATA = 0;
|
EAPI int ECORE_CON_EVENT_CLIENT_DATA = 0;
|
||||||
EAPI int ECORE_CON_EVENT_SERVER_DATA = 0;
|
EAPI int ECORE_CON_EVENT_SERVER_DATA = 0;
|
||||||
|
EAPI int ECORE_CON_EVENT_CLIENT_ERROR = 0;
|
||||||
|
EAPI int ECORE_CON_EVENT_SERVER_ERROR = 0;
|
||||||
|
|
||||||
static Eina_List *servers = NULL;
|
static Eina_List *servers = NULL;
|
||||||
static int _ecore_con_init_count = 0;
|
static int _ecore_con_init_count = 0;
|
||||||
|
@ -148,6 +157,8 @@ ecore_con_init(void)
|
||||||
ECORE_CON_EVENT_SERVER_DEL = 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_CLIENT_DATA = ecore_event_type_new();
|
||||||
ECORE_CON_EVENT_SERVER_DATA = ecore_event_type_new();
|
ECORE_CON_EVENT_SERVER_DATA = ecore_event_type_new();
|
||||||
|
ECORE_CON_EVENT_CLIENT_ERROR = ecore_event_type_new();
|
||||||
|
ECORE_CON_EVENT_SERVER_ERROR = ecore_event_type_new();
|
||||||
|
|
||||||
|
|
||||||
eina_magic_string_set(ECORE_MAGIC_CON_SERVER, "Ecore_Con_Server");
|
eina_magic_string_set(ECORE_MAGIC_CON_SERVER, "Ecore_Con_Server");
|
||||||
|
@ -1140,6 +1151,55 @@ ecore_con_server_infos_del(Ecore_Con_Server *svr, void *info)
|
||||||
svr->infos = eina_list_remove(svr->infos, info);
|
svr->infos = eina_list_remove(svr->infos, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ecore_con_event_server_error(Ecore_Con_Server *svr, const char *error)
|
||||||
|
{
|
||||||
|
Ecore_Con_Event_Server_Error *e;
|
||||||
|
|
||||||
|
e = calloc(1, sizeof(Ecore_Con_Event_Server_Error));
|
||||||
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
||||||
|
|
||||||
|
e->server = svr;
|
||||||
|
e->error = strdup(error);
|
||||||
|
svr->event_count++;
|
||||||
|
ecore_event_add(ECORE_CON_EVENT_SERVER_ERROR, e, (Ecore_End_Cb)_ecore_con_event_server_error_free, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ecore_con_event_client_error(Ecore_Con_Client *cl, const char *error)
|
||||||
|
{
|
||||||
|
Ecore_Con_Event_Client_Error *e;
|
||||||
|
|
||||||
|
e = calloc(1, sizeof(Ecore_Con_Event_Client_Error));
|
||||||
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
||||||
|
|
||||||
|
e->client = cl;
|
||||||
|
e->error = strdup(error);
|
||||||
|
cl->event_count++;
|
||||||
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_ERROR, e, (Ecore_End_Cb)_ecore_con_event_client_error_free, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_ecore_con_event_server_error_free(void *data __UNUSED__, Ecore_Con_Event_Server_Error *e)
|
||||||
|
{
|
||||||
|
e->server->event_count--;
|
||||||
|
if ((e->server->event_count <= 0) && (e->server->delete_me))
|
||||||
|
_ecore_con_server_free(e->server);
|
||||||
|
if (e->error) free(e->error);
|
||||||
|
free(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_ecore_con_event_client_error_free(void *data __UNUSED__, Ecore_Con_Event_Client_Error *e)
|
||||||
|
{
|
||||||
|
e->client->event_count--;
|
||||||
|
if ((e->client->event_count <= 0) && (e->client->delete_me))
|
||||||
|
_ecore_con_client_free(e->client);
|
||||||
|
if (e->error) free(e->error);
|
||||||
|
free(e);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_ecore_con_server_free(Ecore_Con_Server *svr)
|
_ecore_con_server_free(Ecore_Con_Server *svr)
|
||||||
{
|
{
|
||||||
|
@ -1356,46 +1416,69 @@ _ecore_con_cb_tcp_listen(void *data,
|
||||||
|
|
||||||
svr = data;
|
svr = data;
|
||||||
|
|
||||||
if (!net_info)
|
if (!net_info) /* error message has already been handled */
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
|
svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
|
||||||
net_info->info.ai_protocol);
|
net_info->info.ai_protocol);
|
||||||
if (svr->fd < 0)
|
if (svr->fd < 0)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
|
if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0)
|
if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
lin.l_onoff = 1;
|
lin.l_onoff = 1;
|
||||||
lin.l_linger = 0;
|
lin.l_linger = 0;
|
||||||
if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, (const void *)&lin,
|
if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, (const void *)&lin,
|
||||||
sizeof(struct linger)) < 0)
|
sizeof(struct linger)) < 0)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY)
|
if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY)
|
||||||
{
|
{
|
||||||
int flag = 1;
|
int flag = 1;
|
||||||
|
|
||||||
if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag,
|
if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag,
|
||||||
sizeof(int)) < 0)
|
sizeof(int)) < 0)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bind(svr->fd, net_info->info.ai_addr,
|
if (bind(svr->fd, net_info->info.ai_addr,
|
||||||
net_info->info.ai_addrlen) < 0)
|
net_info->info.ai_addrlen) < 0)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
if (listen(svr->fd, 4096) < 0)
|
if (listen(svr->fd, 4096) < 0)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
|
svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
|
||||||
_ecore_con_svr_tcp_handler, svr, NULL, NULL);
|
_ecore_con_svr_tcp_handler, svr, NULL, NULL);
|
||||||
if (!svr->fd_handler)
|
if (!svr->fd_handler)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, "Memory allocation failure");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -1418,13 +1501,16 @@ _ecore_con_cb_udp_listen(void *data,
|
||||||
type = svr->type;
|
type = svr->type;
|
||||||
type &= ECORE_CON_TYPE;
|
type &= ECORE_CON_TYPE;
|
||||||
|
|
||||||
if (!net_info)
|
if (!net_info) /* error message has already been handled */
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
|
svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
|
||||||
net_info->info.ai_protocol);
|
net_info->info.ai_protocol);
|
||||||
if (svr->fd < 0)
|
if (svr->fd < 0)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (type == ECORE_CON_REMOTE_MCAST)
|
if (type == ECORE_CON_REMOTE_MCAST)
|
||||||
{
|
{
|
||||||
|
@ -1432,45 +1518,69 @@ _ecore_con_cb_udp_listen(void *data,
|
||||||
{
|
{
|
||||||
if (!inet_pton(net_info->info.ai_family, net_info->ip,
|
if (!inet_pton(net_info->info.ai_family, net_info->ip,
|
||||||
&mreq.imr_multiaddr))
|
&mreq.imr_multiaddr))
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
|
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
|
||||||
if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
|
if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
|
||||||
(const void *)&mreq, sizeof(mreq)) != 0)
|
(const void *)&mreq, sizeof(mreq)) != 0)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (net_info->info.ai_family == AF_INET6)
|
else if (net_info->info.ai_family == AF_INET6)
|
||||||
{
|
{
|
||||||
if (!inet_pton(net_info->info.ai_family, net_info->ip,
|
if (!inet_pton(net_info->info.ai_family, net_info->ip,
|
||||||
&mreq6.ipv6mr_multiaddr))
|
&mreq6.ipv6mr_multiaddr))
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
mreq6.ipv6mr_interface = htonl(INADDR_ANY);
|
mreq6.ipv6mr_interface = htonl(INADDR_ANY);
|
||||||
if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
|
if (setsockopt(svr->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
|
||||||
(const void *)&mreq6, sizeof(mreq6)) != 0)
|
(const void *)&mreq6, sizeof(mreq6)) != 0)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on,
|
if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&on, sizeof(on)) != 0)
|
||||||
sizeof(on)) != 0)
|
{
|
||||||
goto error;
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
|
if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0)
|
if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (bind(svr->fd, net_info->info.ai_addr,
|
if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
|
||||||
net_info->info.ai_addrlen) < 0)
|
{
|
||||||
goto error;
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
svr->fd_handler =
|
svr->fd_handler =
|
||||||
ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
|
ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ,
|
||||||
_ecore_con_svr_udp_handler, svr, NULL, NULL);
|
_ecore_con_svr_udp_handler, svr, NULL, NULL);
|
||||||
if (!svr->fd_handler)
|
if (!svr->fd_handler)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, "Memory allocation failure");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
svr->ip = eina_stringshare_add(net_info->ip);
|
svr->ip = eina_stringshare_add(net_info->ip);
|
||||||
|
|
||||||
|
@ -1491,33 +1601,44 @@ _ecore_con_cb_tcp_connect(void *data,
|
||||||
|
|
||||||
svr = data;
|
svr = data;
|
||||||
|
|
||||||
if (!net_info)
|
if (!net_info) /* error message has already been handled */
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!svr) return;
|
|
||||||
|
|
||||||
svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
|
svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
|
||||||
net_info->info.ai_protocol);
|
net_info->info.ai_protocol);
|
||||||
if (svr->fd < 0)
|
if (svr->fd < 0)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
|
if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0)
|
if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate,
|
if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate, sizeof(curstate)) < 0)
|
||||||
sizeof(curstate)) < 0)
|
{
|
||||||
goto error;
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY)
|
if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_NODELAY)
|
||||||
{
|
{
|
||||||
int flag = 1;
|
int flag = 1;
|
||||||
|
|
||||||
if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag,
|
if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)) < 0)
|
||||||
sizeof(int)) < 0)
|
{
|
||||||
goto error;
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res = connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen);
|
res = connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen);
|
||||||
|
@ -1525,13 +1646,16 @@ _ecore_con_cb_tcp_connect(void *data,
|
||||||
if (res == SOCKET_ERROR)
|
if (res == SOCKET_ERROR)
|
||||||
{
|
{
|
||||||
if (WSAGetLastError() != WSAEINPROGRESS)
|
if (WSAGetLastError() != WSAEINPROGRESS)
|
||||||
goto error;
|
goto error; /* FIXME: strerror on windows? */
|
||||||
|
|
||||||
#else
|
#else
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
{
|
{
|
||||||
if (errno != EINPROGRESS)
|
if (errno != EINPROGRESS)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
svr->connecting = EINA_TRUE;
|
svr->connecting = EINA_TRUE;
|
||||||
|
@ -1553,7 +1677,10 @@ _ecore_con_cb_tcp_connect(void *data,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!svr->fd_handler)
|
if (!svr->fd_handler)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, "Memory allocation failure");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
svr->ip = eina_stringshare_add(net_info->ip);
|
svr->ip = eina_stringshare_add(net_info->ip);
|
||||||
|
|
||||||
|
@ -1573,39 +1700,60 @@ _ecore_con_cb_udp_connect(void *data,
|
||||||
int broadcast = 1;
|
int broadcast = 1;
|
||||||
svr = data;
|
svr = data;
|
||||||
|
|
||||||
if (!net_info)
|
if (!net_info) /* error message has already been handled */
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
|
svr->fd = socket(net_info->info.ai_family, net_info->info.ai_socktype,
|
||||||
net_info->info.ai_protocol);
|
net_info->info.ai_protocol);
|
||||||
if (svr->fd < 0)
|
if (svr->fd < 0)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
|
if (fcntl(svr->fd, F_SETFL, O_NONBLOCK) < 0)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0)
|
if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_BROADCAST)
|
if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_BROADCAST)
|
||||||
{
|
{
|
||||||
if (setsockopt(svr->fd, SOL_SOCKET, SO_BROADCAST,
|
if (setsockopt(svr->fd, SOL_SOCKET, SO_BROADCAST,
|
||||||
(const void *)&broadcast,
|
(const void *)&broadcast,
|
||||||
sizeof(broadcast)) < 0)
|
sizeof(broadcast)) < 0)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR,
|
else if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR,
|
||||||
(const void *)&curstate, sizeof(curstate)) < 0)
|
(const void *)&curstate, sizeof(curstate)) < 0)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
|
if (connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE,
|
svr->fd_handler = ecore_main_fd_handler_add(svr->fd, ECORE_FD_READ | ECORE_FD_WRITE,
|
||||||
_ecore_con_cl_udp_handler, svr, NULL, NULL);
|
_ecore_con_cl_udp_handler, svr, NULL, NULL);
|
||||||
|
|
||||||
if (!svr->fd_handler)
|
if (!svr->fd_handler)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, "Memory allocation failure");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
svr->ip = eina_stringshare_add(net_info->ip);
|
svr->ip = eina_stringshare_add(net_info->ip);
|
||||||
|
|
||||||
|
@ -1643,6 +1791,7 @@ svr_try_connect_plain(Ecore_Con_Server *svr)
|
||||||
if (so_err)
|
if (so_err)
|
||||||
{
|
{
|
||||||
/* we lost our server! */
|
/* we lost our server! */
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
ERR("Connection lost: %s", strerror(so_err));
|
ERR("Connection lost: %s", strerror(so_err));
|
||||||
_ecore_con_server_kill(svr);
|
_ecore_con_server_kill(svr);
|
||||||
return ECORE_CON_DISCONNECTED;
|
return ECORE_CON_DISCONNECTED;
|
||||||
|
@ -1699,7 +1848,7 @@ _ecore_con_pretty_ip(struct sockaddr *client_addr,
|
||||||
if (getnameinfo(client_addr, size, ipbuf, sizeof (ipbuf), NULL, 0, NI_NUMERICHOST))
|
if (getnameinfo(client_addr, size, ipbuf, sizeof (ipbuf), NULL, 0, NI_NUMERICHOST))
|
||||||
return eina_stringshare_add("0.0.0.0");
|
return eina_stringshare_add("0.0.0.0");
|
||||||
|
|
||||||
ipbuf[sizeof (ipbuf) - 1] = 0;
|
ipbuf[sizeof(ipbuf) - 1] = 0;
|
||||||
return eina_stringshare_add(ipbuf);
|
return eina_stringshare_add(ipbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1728,22 +1877,37 @@ _ecore_con_svr_tcp_handler(void *data,
|
||||||
memset(&client_addr, 0, client_addr_len);
|
memset(&client_addr, 0, client_addr_len);
|
||||||
new_fd = accept(svr->fd, (struct sockaddr *)&client_addr, (socklen_t *)&client_addr_len);
|
new_fd = accept(svr->fd, (struct sockaddr *)&client_addr, (socklen_t *)&client_addr_len);
|
||||||
if (new_fd < 0)
|
if (new_fd < 0)
|
||||||
/* error! */
|
{
|
||||||
return ECORE_CALLBACK_RENEW;
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
return ECORE_CALLBACK_RENEW;
|
||||||
|
}
|
||||||
|
|
||||||
if ((svr->client_limit >= 0) && (svr->reject_excess_clients) &&
|
if ((svr->client_limit >= 0) && (svr->reject_excess_clients) &&
|
||||||
(svr->client_count >= (unsigned int)svr->client_limit))
|
(svr->client_count >= (unsigned int)svr->client_limit))
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, "Maximum client limit reached");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
cl = calloc(1, sizeof(Ecore_Con_Client));
|
cl = calloc(1, sizeof(Ecore_Con_Client));
|
||||||
if (!cl)
|
if (!cl)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, "Memory allocation failure when attempting to add a new client");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
fcntl(new_fd, F_SETFL, O_NONBLOCK);
|
|
||||||
fcntl(new_fd, F_SETFD, FD_CLOEXEC);
|
|
||||||
cl->fd = new_fd;
|
cl->fd = new_fd;
|
||||||
cl->host_server = svr;
|
cl->host_server = svr;
|
||||||
|
if (fcntl(new_fd, F_SETFL, O_NONBLOCK) < 0)
|
||||||
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
if (fcntl(new_fd, F_SETFD, FD_CLOEXEC) < 0)
|
||||||
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
cl->fd_handler = ecore_main_fd_handler_add(cl->fd, ECORE_FD_READ,
|
cl->fd_handler = ecore_main_fd_handler_add(cl->fd, ECORE_FD_READ,
|
||||||
_ecore_con_svr_cl_handler, cl, NULL, NULL);
|
_ecore_con_svr_cl_handler, cl, NULL, NULL);
|
||||||
ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
|
ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
|
||||||
|
@ -1758,7 +1922,10 @@ _ecore_con_svr_tcp_handler(void *data,
|
||||||
|
|
||||||
cl->client_addr = malloc(client_addr_len);
|
cl->client_addr = malloc(client_addr_len);
|
||||||
if (!cl->client_addr)
|
if (!cl->client_addr)
|
||||||
goto error;
|
{
|
||||||
|
ecore_con_event_server_error(svr, "Memory allocation failure when attempting to add a new client");
|
||||||
|
return ECORE_CALLBACK_RENEW;
|
||||||
|
}
|
||||||
cl->client_addr_len = client_addr_len;
|
cl->client_addr_len = client_addr_len;
|
||||||
memcpy(cl->client_addr, &client_addr, client_addr_len);
|
memcpy(cl->client_addr, &client_addr, client_addr_len);
|
||||||
|
|
||||||
|
@ -1817,6 +1984,8 @@ _ecore_con_cl_read(Ecore_Con_Server *svr)
|
||||||
/* 0 is not a valid return value for a tcp socket */
|
/* 0 is not a valid return value for a tcp socket */
|
||||||
if ((num > 0) || ((num < 0) && (errno == EAGAIN)))
|
if ((num > 0) || ((num < 0) && (errno == EAGAIN)))
|
||||||
lost_server = EINA_FALSE;
|
lost_server = EINA_FALSE;
|
||||||
|
else
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1969,7 +2138,10 @@ _ecore_con_cl_udp_handler(void *data,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num < 0 && (errno != EAGAIN) && (errno != EINTR))
|
if (num < 0 && (errno != EAGAIN) && (errno != EINTR))
|
||||||
_ecore_con_server_kill(svr);
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
_ecore_con_server_kill(svr);
|
||||||
|
}
|
||||||
|
|
||||||
return ECORE_CALLBACK_RENEW;
|
return ECORE_CALLBACK_RENEW;
|
||||||
}
|
}
|
||||||
|
@ -2014,6 +2186,7 @@ _ecore_con_svr_udp_handler(void *data,
|
||||||
|
|
||||||
if (num < 0 && (errno != EAGAIN) && (errno != EINTR))
|
if (num < 0 && (errno != EAGAIN) && (errno != EINTR))
|
||||||
{
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
if (!svr->delete_me)
|
if (!svr->delete_me)
|
||||||
{
|
{
|
||||||
/* we lost our client! */
|
/* we lost our client! */
|
||||||
|
@ -2117,6 +2290,8 @@ _ecore_con_svr_cl_read(Ecore_Con_Client *cl)
|
||||||
/* 0 is not a valid return value for a tcp socket */
|
/* 0 is not a valid return value for a tcp socket */
|
||||||
if ((num > 0) || ((num < 0) && ((errno == EAGAIN) || (errno == EINTR))))
|
if ((num > 0) || ((num < 0) && ((errno == EAGAIN) || (errno == EINTR))))
|
||||||
lost_client = EINA_FALSE;
|
lost_client = EINA_FALSE;
|
||||||
|
else
|
||||||
|
ecore_con_event_client_error(cl, strerror(errno));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2266,7 +2441,10 @@ _ecore_con_server_flush(Ecore_Con_Server *svr)
|
||||||
if (count < 0)
|
if (count < 0)
|
||||||
{
|
{
|
||||||
if ((errno != EAGAIN) && (errno != EINTR))
|
if ((errno != EAGAIN) && (errno != EINTR))
|
||||||
_ecore_con_server_kill(svr);
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
_ecore_con_server_kill(svr);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2314,6 +2492,7 @@ _ecore_con_client_flush(Ecore_Con_Client *cl)
|
||||||
{
|
{
|
||||||
if ((errno != EAGAIN) && (errno != EINTR) && (!cl->delete_me))
|
if ((errno != EAGAIN) && (errno != EINTR) && (!cl->delete_me))
|
||||||
{
|
{
|
||||||
|
ecore_con_event_client_error(cl, strerror(errno));
|
||||||
/* we lost our client! */
|
/* we lost our client! */
|
||||||
Ecore_Con_Event_Client_Del *e;
|
Ecore_Con_Event_Client_Del *e;
|
||||||
|
|
||||||
|
|
|
@ -523,11 +523,12 @@ _ecore_con_info_ares_host_cb(Ecore_Con_CAres *arg,
|
||||||
case ARES_ENODATA: /* no data returned */
|
case ARES_ENODATA: /* no data returned */
|
||||||
case ARES_ECONNREFUSED: /* connection refused */
|
case ARES_ECONNREFUSED: /* connection refused */
|
||||||
case ARES_ETIMEOUT: /* connection timed out */
|
case ARES_ETIMEOUT: /* connection timed out */
|
||||||
|
ecore_con_event_server_error(arg->svr, ares_strerror(status));
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ERR("Unknown status returned by c-ares: %i assuming error",
|
ERR("Unknown status returned by c-ares: %i assuming error", status);
|
||||||
status);
|
ecore_con_event_server_error(arg->svr, ares_strerror(status));
|
||||||
goto on_error;
|
goto on_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -573,6 +574,7 @@ _ecore_con_info_ares_nameinfo(Ecore_Con_CAres *arg,
|
||||||
case ARES_ENOMEM:
|
case ARES_ENOMEM:
|
||||||
case ARES_EDESTRUCTION:
|
case ARES_EDESTRUCTION:
|
||||||
case ARES_EBADFLAGS:
|
case ARES_EBADFLAGS:
|
||||||
|
ecore_con_event_server_error(arg->svr, ares_strerror(status));
|
||||||
if (arg->data) arg->done_cb(arg->data, NULL);
|
if (arg->data) arg->done_cb(arg->data, NULL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,8 @@ void *alloca(size_t);
|
||||||
# include <netdb.h>
|
# include <netdb.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include "Ecore.h"
|
#include "Ecore.h"
|
||||||
#include "ecore_private.h"
|
#include "ecore_private.h"
|
||||||
#include "ecore_con_private.h"
|
#include "ecore_con_private.h"
|
||||||
|
@ -204,7 +206,10 @@ ecore_con_info_get(Ecore_Con_Server *svr,
|
||||||
int fd[2];
|
int fd[2];
|
||||||
|
|
||||||
if (pipe(fd) < 0)
|
if (pipe(fd) < 0)
|
||||||
return 0;
|
{
|
||||||
|
ecore_con_event_server_error(svr, strerror(errno));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
cbdata = calloc(1, sizeof(CB_Data));
|
cbdata = calloc(1, sizeof(CB_Data));
|
||||||
if (!cbdata)
|
if (!cbdata)
|
||||||
|
@ -222,6 +227,7 @@ ecore_con_info_get(Ecore_Con_Server *svr,
|
||||||
cbdata,
|
cbdata,
|
||||||
NULL, NULL)))
|
NULL, NULL)))
|
||||||
{
|
{
|
||||||
|
ecore_con_event_server_error(svr, "Memory allocation failure");
|
||||||
free(cbdata);
|
free(cbdata);
|
||||||
close(fd[0]);
|
close(fd[0]);
|
||||||
close(fd[1]);
|
close(fd[1]);
|
||||||
|
@ -376,6 +382,7 @@ _ecore_con_info_readdata(CB_Data *cbdata)
|
||||||
{
|
{
|
||||||
if (cbdata->data)
|
if (cbdata->data)
|
||||||
{
|
{
|
||||||
|
ecore_con_event_server_error(cbdata->data, strerror(errno));
|
||||||
cbdata->cb_done(cbdata->data, NULL);
|
cbdata->cb_done(cbdata->data, NULL);
|
||||||
ecore_con_server_infos_del(cbdata->data, cbdata);
|
ecore_con_server_infos_del(cbdata->data, cbdata);
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,6 +200,8 @@ struct _Ecore_Con_Lookup
|
||||||
|
|
||||||
/* from ecore_con.c */
|
/* from ecore_con.c */
|
||||||
void ecore_con_server_infos_del(Ecore_Con_Server *svr, void *info);
|
void ecore_con_server_infos_del(Ecore_Con_Server *svr, void *info);
|
||||||
|
void ecore_con_event_server_error(Ecore_Con_Server *svr, const char *error);
|
||||||
|
void ecore_con_event_client_error(Ecore_Con_Client *cl, const char *error);
|
||||||
|
|
||||||
/* from ecore_local.c */
|
/* from ecore_local.c */
|
||||||
int ecore_con_local_init(void);
|
int ecore_con_local_init(void);
|
||||||
|
|
|
@ -46,10 +46,18 @@ static int _client_connected = 0;
|
||||||
|
|
||||||
#if USE_GNUTLS
|
#if USE_GNUTLS
|
||||||
static void
|
static void
|
||||||
_gnutls_print_errors(int ret)
|
_gnutls_print_errors(void *conn, int type, int ret)
|
||||||
{
|
{
|
||||||
if (ret)
|
char buf[1024];
|
||||||
ERR("gnutls returned with error: %s - %s", gnutls_strerror_name(ret), gnutls_strerror(ret));
|
|
||||||
|
if (!ret) return;
|
||||||
|
|
||||||
|
snprintf(buf, sizeof(buf), "GNUTLS error: %s - %s", gnutls_strerror_name(ret), gnutls_strerror(ret));
|
||||||
|
ERR("%s", buf);
|
||||||
|
if (type == ECORE_CON_EVENT_CLIENT_ERROR)
|
||||||
|
ecore_con_event_client_error(conn, buf);
|
||||||
|
else
|
||||||
|
ecore_con_event_server_error(conn, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ISCOMFITOR
|
#ifdef ISCOMFITOR
|
||||||
|
@ -108,15 +116,22 @@ SSL_GNUTLS_PRINT_HANDSHAKE_STATUS(gnutls_handshake_description_t status)
|
||||||
#elif USE_OPENSSL
|
#elif USE_OPENSSL
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_openssl_print_errors(void)
|
_openssl_print_errors(void *conn, int type)
|
||||||
{
|
{
|
||||||
|
char buf[1024];
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
unsigned long err;
|
unsigned long err;
|
||||||
|
|
||||||
err = ERR_get_error();
|
err = ERR_get_error();
|
||||||
if (!err) break;
|
if (!err) break;
|
||||||
ERR("openssl error: %s", ERR_reason_error_string(err));
|
snprintf(buf, sizeof(buf), "OpenSSL error: %s", ERR_reason_error_string(err));
|
||||||
|
ERR("%s", buf);
|
||||||
|
if (type == ECORE_CON_EVENT_CLIENT_ERROR)
|
||||||
|
ecore_con_event_client_error(conn, buf);
|
||||||
|
else
|
||||||
|
ecore_con_event_server_error(conn, buf);
|
||||||
|
|
||||||
} while (1);
|
} while (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -480,7 +495,7 @@ _ecore_con_ssl_server_prepare_gnutls(Ecore_Con_Server *svr,
|
||||||
return ECORE_CON_SSL_ERROR_NONE;
|
return ECORE_CON_SSL_ERROR_NONE;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
_gnutls_print_errors(ret);
|
_gnutls_print_errors(svr, ECORE_CON_EVENT_SERVER_ERROR, ret);
|
||||||
_ecore_con_ssl_server_shutdown_gnutls(svr);
|
_ecore_con_ssl_server_shutdown_gnutls(svr);
|
||||||
return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
|
return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
|
||||||
}
|
}
|
||||||
|
@ -602,7 +617,7 @@ _ecore_con_ssl_server_init_gnutls(Ecore_Con_Server *svr)
|
||||||
return ECORE_CON_SSL_ERROR_NONE;
|
return ECORE_CON_SSL_ERROR_NONE;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
_gnutls_print_errors(ret);
|
_gnutls_print_errors(svr, ECORE_CON_EVENT_SERVER_ERROR, ret);
|
||||||
if ((ret == GNUTLS_E_WARNING_ALERT_RECEIVED) || (ret == GNUTLS_E_FATAL_ALERT_RECEIVED))
|
if ((ret == GNUTLS_E_WARNING_ALERT_RECEIVED) || (ret == GNUTLS_E_FATAL_ALERT_RECEIVED))
|
||||||
ERR("Also received alert: %s", gnutls_alert_get_name(gnutls_alert_get(svr->session)));
|
ERR("Also received alert: %s", gnutls_alert_get_name(gnutls_alert_get(svr->session)));
|
||||||
if (svr->session && (svr->ssl_state != ECORE_CON_SSL_STATE_DONE))
|
if (svr->session && (svr->ssl_state != ECORE_CON_SSL_STATE_DONE))
|
||||||
|
@ -904,7 +919,7 @@ _ecore_con_ssl_client_init_gnutls(Ecore_Con_Client *cl)
|
||||||
return ECORE_CON_SSL_ERROR_NONE;
|
return ECORE_CON_SSL_ERROR_NONE;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
_gnutls_print_errors(ret);
|
_gnutls_print_errors(cl, ECORE_CON_EVENT_CLIENT_ERROR, ret);
|
||||||
if ((ret == GNUTLS_E_WARNING_ALERT_RECEIVED) || (ret == GNUTLS_E_FATAL_ALERT_RECEIVED))
|
if ((ret == GNUTLS_E_WARNING_ALERT_RECEIVED) || (ret == GNUTLS_E_FATAL_ALERT_RECEIVED))
|
||||||
ERR("Also received alert: %s", gnutls_alert_get_name(gnutls_alert_get(cl->session)));
|
ERR("Also received alert: %s", gnutls_alert_get_name(gnutls_alert_get(cl->session)));
|
||||||
if (cl->session && (cl->ssl_state != ECORE_CON_SSL_STATE_DONE))
|
if (cl->session && (cl->ssl_state != ECORE_CON_SSL_STATE_DONE))
|
||||||
|
@ -1096,7 +1111,7 @@ error:
|
||||||
ERR("openssl error: dh_params could not generate a safe prime!");
|
ERR("openssl error: dh_params could not generate a safe prime!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
_openssl_print_errors();
|
_openssl_print_errors(svr, ECORE_CON_EVENT_SERVER_ERROR);
|
||||||
_ecore_con_ssl_server_shutdown_openssl(svr);
|
_ecore_con_ssl_server_shutdown_openssl(svr);
|
||||||
return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
|
return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
|
||||||
}
|
}
|
||||||
|
@ -1176,7 +1191,7 @@ _ecore_con_ssl_server_init_openssl(Ecore_Con_Server *svr)
|
||||||
return ECORE_CON_SSL_ERROR_NONE;
|
return ECORE_CON_SSL_ERROR_NONE;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
_openssl_print_errors();
|
_openssl_print_errors(svr, ECORE_CON_EVENT_SERVER_ERROR);
|
||||||
_ecore_con_ssl_server_shutdown_openssl(svr);
|
_ecore_con_ssl_server_shutdown_openssl(svr);
|
||||||
return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
|
return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
|
||||||
}
|
}
|
||||||
|
@ -1189,7 +1204,7 @@ _ecore_con_ssl_server_cafile_add_openssl(Ecore_Con_Server *svr,
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
_openssl_print_errors();
|
_openssl_print_errors(svr, ECORE_CON_EVENT_SERVER_ERROR);
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1213,7 +1228,7 @@ _ecore_con_ssl_server_crl_add_openssl(Ecore_Con_Server *svr,
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
_openssl_print_errors();
|
_openssl_print_errors(svr, ECORE_CON_EVENT_SERVER_ERROR);
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1238,7 +1253,7 @@ _ecore_con_ssl_server_privkey_add_openssl(Ecore_Con_Server *svr,
|
||||||
error:
|
error:
|
||||||
if (fp)
|
if (fp)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
_openssl_print_errors();
|
_openssl_print_errors(svr, ECORE_CON_EVENT_SERVER_ERROR);
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1263,7 +1278,7 @@ _ecore_con_ssl_server_cert_add_openssl(Ecore_Con_Server *svr,
|
||||||
error:
|
error:
|
||||||
if (fp)
|
if (fp)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
_openssl_print_errors();
|
_openssl_print_errors(svr, ECORE_CON_EVENT_SERVER_ERROR);
|
||||||
return EINA_FALSE;
|
return EINA_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1418,7 +1433,7 @@ _ecore_con_ssl_client_init_openssl(Ecore_Con_Client *cl)
|
||||||
return ECORE_CON_SSL_ERROR_NONE;
|
return ECORE_CON_SSL_ERROR_NONE;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
_openssl_print_errors();
|
_openssl_print_errors(cl, ECORE_CON_EVENT_CLIENT_ERROR);
|
||||||
_ecore_con_ssl_client_shutdown_openssl(cl);
|
_ecore_con_ssl_client_shutdown_openssl(cl);
|
||||||
return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
|
return ECORE_CON_SSL_ERROR_SERVER_INIT_FAILED;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue