use safety macros to check mallocs, remove some dead code, optimize read loops by removing them, refactor a lot of code to not be indented halfway across the screen
SVN revision: 54133
This commit is contained in:
parent
ddd151bf37
commit
3ffb7e4c16
|
@ -1177,8 +1177,8 @@ _ecore_con_client_free(Ecore_Con_Client *cl)
|
||||||
|
|
||||||
cl->dead = EINA_TRUE;
|
cl->dead = EINA_TRUE;
|
||||||
e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
|
e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
|
||||||
if (e)
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
||||||
{
|
|
||||||
cl->event_count++;
|
cl->event_count++;
|
||||||
_ecore_con_cl_timer_update(cl);
|
_ecore_con_cl_timer_update(cl);
|
||||||
e->client = cl;
|
e->client = cl;
|
||||||
|
@ -1186,7 +1186,6 @@ _ecore_con_client_free(Ecore_Con_Client *cl)
|
||||||
_ecore_con_event_client_del_free, NULL);
|
_ecore_con_event_client_del_free, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ECORE_MAGIC_SET(cl, ECORE_MAGIC_NONE);
|
ECORE_MAGIC_SET(cl, ECORE_MAGIC_NONE);
|
||||||
t_start = ecore_time_get();
|
t_start = ecore_time_get();
|
||||||
|
@ -1230,14 +1229,13 @@ _ecore_con_server_kill(Ecore_Con_Server *svr)
|
||||||
Ecore_Con_Event_Server_Del *e;
|
Ecore_Con_Event_Server_Del *e;
|
||||||
|
|
||||||
e = calloc(1, sizeof(Ecore_Con_Event_Server_Del));
|
e = calloc(1, sizeof(Ecore_Con_Event_Server_Del));
|
||||||
if (e)
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
||||||
{
|
|
||||||
svr->event_count++;
|
svr->event_count++;
|
||||||
e->server = svr;
|
e->server = svr;
|
||||||
ecore_event_add(ECORE_CON_EVENT_SERVER_DEL, e,
|
ecore_event_add(ECORE_CON_EVENT_SERVER_DEL, e,
|
||||||
_ecore_con_event_server_del_free, NULL);
|
_ecore_con_event_server_del_free, NULL);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
svr->dead = EINA_TRUE;
|
svr->dead = EINA_TRUE;
|
||||||
if (svr->fd_handler)
|
if (svr->fd_handler)
|
||||||
|
@ -1594,15 +1592,14 @@ svr_try_connect_plain(Ecore_Con_Server *svr)
|
||||||
|
|
||||||
svr->connecting = EINA_FALSE;
|
svr->connecting = EINA_FALSE;
|
||||||
e = calloc(1, sizeof(Ecore_Con_Event_Server_Add));
|
e = calloc(1, sizeof(Ecore_Con_Event_Server_Add));
|
||||||
if (e)
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, ECORE_CON_CONNECTED);
|
||||||
{
|
|
||||||
svr->event_count++;
|
svr->event_count++;
|
||||||
svr->start_time = ecore_time_get();
|
svr->start_time = ecore_time_get();
|
||||||
e->server = svr;
|
e->server = svr;
|
||||||
ecore_event_add(ECORE_CON_EVENT_SERVER_ADD, e,
|
ecore_event_add(ECORE_CON_EVENT_SERVER_ADD, e,
|
||||||
_ecore_con_event_server_add_free, NULL);
|
_ecore_con_event_server_add_free, NULL);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (svr->fd_handler && (!svr->write_buf))
|
if (svr->fd_handler && (!svr->write_buf))
|
||||||
ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
|
ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
|
||||||
|
@ -1711,14 +1708,14 @@ _ecore_con_svr_tcp_handler(void *data,
|
||||||
Ecore_Con_Event_Client_Add *e;
|
Ecore_Con_Event_Client_Add *e;
|
||||||
|
|
||||||
e = calloc(1, sizeof(Ecore_Con_Event_Client_Add));
|
e = calloc(1, sizeof(Ecore_Con_Event_Client_Add));
|
||||||
if (e)
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, ECORE_CALLBACK_RENEW);
|
||||||
{
|
|
||||||
cl->event_count++;
|
cl->event_count++;
|
||||||
_ecore_con_cl_timer_update(cl);
|
_ecore_con_cl_timer_update(cl);
|
||||||
e->client = cl;
|
e->client = cl;
|
||||||
ecore_event_add(ECORE_CON_EVENT_CLIENT_ADD, e,
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_ADD, e,
|
||||||
_ecore_con_event_client_add_free, NULL);
|
_ecore_con_event_client_add_free, NULL);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ECORE_CALLBACK_RENEW;
|
return ECORE_CALLBACK_RENEW;
|
||||||
|
@ -1733,20 +1730,14 @@ error:
|
||||||
static void
|
static void
|
||||||
_ecore_con_cl_read(Ecore_Con_Server *svr)
|
_ecore_con_cl_read(Ecore_Con_Server *svr)
|
||||||
{
|
{
|
||||||
unsigned char *inbuf = NULL;
|
int num = 0;
|
||||||
int inbuf_num = 0;
|
Eina_Bool lost_server = EINA_TRUE;
|
||||||
int tries;
|
unsigned char buf[READBUFSIZ];
|
||||||
|
|
||||||
/* only possible with non-ssl connections */
|
/* only possible with non-ssl connections */
|
||||||
if (svr->connecting && (svr_try_connect_plain(svr) != ECORE_CON_CONNECTED))
|
if (svr->connecting && (svr_try_connect_plain(svr) != ECORE_CON_CONNECTED))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (tries = 0; tries < 16; tries++)
|
|
||||||
{
|
|
||||||
int num = 0;
|
|
||||||
Eina_Bool lost_server = EINA_TRUE;
|
|
||||||
unsigned char buf[READBUFSIZ];
|
|
||||||
|
|
||||||
if (svr->handshaking)
|
if (svr->handshaking)
|
||||||
{
|
{
|
||||||
DBG("Continuing ssl handshake");
|
DBG("Continuing ssl handshake");
|
||||||
|
@ -1756,51 +1747,34 @@ _ecore_con_cl_read(Ecore_Con_Server *svr)
|
||||||
|
|
||||||
if (!(svr->type & ECORE_CON_SSL))
|
if (!(svr->type & ECORE_CON_SSL))
|
||||||
{
|
{
|
||||||
num = read(svr->fd, buf, READBUFSIZ);
|
num = read(svr->fd, buf, sizeof(buf));
|
||||||
if ((num < 0) && (errno == EAGAIN))
|
if ((num < 0) && (errno == EAGAIN))
|
||||||
lost_server = EINA_FALSE;
|
lost_server = EINA_FALSE;
|
||||||
}
|
}
|
||||||
else if (!(num = ecore_con_ssl_server_read(svr, buf, READBUFSIZ)))
|
else if (!(num = ecore_con_ssl_server_read(svr, buf, sizeof(buf))))
|
||||||
lost_server = EINA_FALSE;
|
lost_server = EINA_FALSE;
|
||||||
|
|
||||||
if (num < 1)
|
if (num < 1)
|
||||||
{
|
return;
|
||||||
if (inbuf && (!svr->delete_me))
|
|
||||||
|
if (!svr->delete_me)
|
||||||
{
|
{
|
||||||
Ecore_Con_Event_Server_Data *e;
|
Ecore_Con_Event_Server_Data *e;
|
||||||
|
|
||||||
e = malloc(sizeof(Ecore_Con_Event_Server_Data));
|
e = malloc(sizeof(Ecore_Con_Event_Server_Data));
|
||||||
if (e)
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
||||||
{
|
|
||||||
svr->event_count++;
|
svr->event_count++;
|
||||||
e->server = svr;
|
e->server = svr;
|
||||||
e->data = inbuf;
|
e->data = malloc(num);
|
||||||
e->size = inbuf_num;
|
memcpy(e->data, buf, num);
|
||||||
|
e->size = num;
|
||||||
ecore_event_add(ECORE_CON_EVENT_SERVER_DATA, e,
|
ecore_event_add(ECORE_CON_EVENT_SERVER_DATA, e,
|
||||||
_ecore_con_event_server_data_free, NULL);
|
_ecore_con_event_server_data_free, NULL);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (lost_server)
|
if (lost_server)
|
||||||
_ecore_con_server_kill(svr);
|
_ecore_con_server_kill(svr);
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
inbuf = realloc(inbuf, inbuf_num + num);
|
|
||||||
memcpy(inbuf + inbuf_num, buf, num);
|
|
||||||
inbuf_num += num;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* #if USE_OPENSSL */
|
|
||||||
/* if (svr->fd_handler) */
|
|
||||||
/* { */
|
|
||||||
/* if (svr->ssl && ssl_err == SSL_ERROR_WANT_READ) */
|
|
||||||
/* ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ); */
|
|
||||||
/* else if (svr->ssl && ssl_err == SSL_ERROR_WANT_WRITE) */
|
|
||||||
/* ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_WRITE); */
|
|
||||||
/* } */
|
|
||||||
/* #endif */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
|
@ -1826,7 +1800,7 @@ _ecore_con_cl_handler(void *data,
|
||||||
#ifdef ISCOMFITOR
|
#ifdef ISCOMFITOR
|
||||||
if (want_read)
|
if (want_read)
|
||||||
{
|
{
|
||||||
char buf[32768];
|
char buf[READBUFSIZ];
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
len = recv(svr->fd, buf, sizeof(buf), MSG_DONTWAIT | MSG_PEEK);
|
len = recv(svr->fd, buf, sizeof(buf), MSG_DONTWAIT | MSG_PEEK);
|
||||||
DBG("%zu bytes in buffer", len);
|
DBG("%zu bytes in buffer", len);
|
||||||
|
@ -1839,14 +1813,13 @@ _ecore_con_cl_handler(void *data,
|
||||||
Ecore_Con_Event_Server_Del *e;
|
Ecore_Con_Event_Server_Del *e;
|
||||||
|
|
||||||
e = calloc(1, sizeof(Ecore_Con_Event_Server_Del));
|
e = calloc(1, sizeof(Ecore_Con_Event_Server_Del));
|
||||||
if (e)
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, ECORE_CALLBACK_RENEW);
|
||||||
{
|
|
||||||
svr->event_count++;
|
svr->event_count++;
|
||||||
e->server = svr;
|
e->server = svr;
|
||||||
ecore_event_add(ECORE_CON_EVENT_SERVER_DEL, e,
|
ecore_event_add(ECORE_CON_EVENT_SERVER_DEL, e,
|
||||||
_ecore_con_event_server_del_free, NULL);
|
_ecore_con_event_server_del_free, NULL);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (!svr->ssl_state)
|
else if (!svr->ssl_state)
|
||||||
{
|
{
|
||||||
/* we got our server! */
|
/* we got our server! */
|
||||||
|
@ -1854,8 +1827,8 @@ _ecore_con_cl_handler(void *data,
|
||||||
|
|
||||||
svr->connecting = EINA_FALSE;
|
svr->connecting = EINA_FALSE;
|
||||||
e = calloc(1, sizeof(Ecore_Con_Event_Server_Add));
|
e = calloc(1, sizeof(Ecore_Con_Event_Server_Add));
|
||||||
if (e)
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, ECORE_CALLBACK_RENEW);
|
||||||
{
|
|
||||||
svr->event_count++;
|
svr->event_count++;
|
||||||
svr->start_time = ecore_time_get();
|
svr->start_time = ecore_time_get();
|
||||||
e->server = svr;
|
e->server = svr;
|
||||||
|
@ -1863,7 +1836,6 @@ _ecore_con_cl_handler(void *data,
|
||||||
_ecore_con_event_server_add_free, NULL);
|
_ecore_con_event_server_add_free, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (want_read)
|
else if (want_read)
|
||||||
_ecore_con_cl_read(svr);
|
_ecore_con_cl_read(svr);
|
||||||
else if (want_write) /* only possible with non-ssl connections */
|
else if (want_write) /* only possible with non-ssl connections */
|
||||||
|
@ -1881,56 +1853,53 @@ static Eina_Bool
|
||||||
_ecore_con_cl_udp_handler(void *data,
|
_ecore_con_cl_udp_handler(void *data,
|
||||||
Ecore_Fd_Handler *fd_handler)
|
Ecore_Fd_Handler *fd_handler)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
unsigned char buf[READBUFSIZ];
|
||||||
|
int num;
|
||||||
Ecore_Con_Server *svr;
|
Ecore_Con_Server *svr;
|
||||||
|
Eina_Bool want_read, want_write;
|
||||||
|
|
||||||
|
want_read = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ);
|
||||||
|
want_write = ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE);
|
||||||
|
|
||||||
svr = data;
|
svr = data;
|
||||||
if (svr->dead)
|
if (svr->dead || svr->delete_me || ((!want_read) && (!want_write)))
|
||||||
return ECORE_CALLBACK_RENEW;
|
return ECORE_CALLBACK_RENEW;
|
||||||
|
|
||||||
if (svr->delete_me)
|
if (want_write)
|
||||||
return ECORE_CALLBACK_RENEW;
|
|
||||||
|
|
||||||
if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
|
|
||||||
{
|
{
|
||||||
unsigned char buf[65536];
|
_ecore_con_server_flush(svr);
|
||||||
int num;
|
return ECORE_CALLBACK_RENEW;
|
||||||
|
}
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
num = read(svr->fd, buf, 65536);
|
num = read(svr->fd, buf, READBUFSIZ);
|
||||||
if (num > 0)
|
|
||||||
{
|
if ((errno == EIO) || (errno == EBADF) || (errno == EPIPE) || (errno == EINVAL) ||
|
||||||
if (!svr->delete_me)
|
(errno == ENOSPC) || (errno == ECONNREFUSED))
|
||||||
{
|
_ecore_con_server_kill(svr);
|
||||||
|
|
||||||
|
if ((num < 1) || (svr->delete_me))
|
||||||
|
return ECORE_CALLBACK_RENEW;
|
||||||
|
|
||||||
Ecore_Con_Event_Server_Data *e;
|
Ecore_Con_Event_Server_Data *e;
|
||||||
unsigned char *inbuf;
|
unsigned char *inbuf;
|
||||||
|
|
||||||
inbuf = malloc(num);
|
inbuf = malloc(num);
|
||||||
if(!inbuf)
|
if(!inbuf)
|
||||||
return 1;
|
return ECORE_CALLBACK_RENEW;
|
||||||
|
|
||||||
memcpy(inbuf, buf, num);
|
memcpy(inbuf, buf, num);
|
||||||
|
|
||||||
e = calloc(1, sizeof(Ecore_Con_Event_Server_Data));
|
e = calloc(1, sizeof(Ecore_Con_Event_Server_Data));
|
||||||
if (e)
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, ECORE_CALLBACK_RENEW);
|
||||||
{
|
|
||||||
svr->event_count++;
|
svr->event_count++;
|
||||||
e->server = svr;
|
e->server = svr;
|
||||||
e->data = inbuf;
|
e->data = inbuf;
|
||||||
e->size = num;
|
e->size = num;
|
||||||
ecore_event_add(ECORE_CON_EVENT_SERVER_DATA, e,
|
ecore_event_add(ECORE_CON_EVENT_SERVER_DATA, e,
|
||||||
_ecore_con_event_server_data_free,
|
_ecore_con_event_server_data_free, NULL);
|
||||||
NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ((errno == EIO) || (errno == EBADF) ||
|
|
||||||
(errno == EPIPE) || (errno == EINVAL) ||
|
|
||||||
(errno == ENOSPC) || (errno == ECONNREFUSED))
|
|
||||||
_ecore_con_server_kill(svr);
|
|
||||||
}
|
|
||||||
else if (ecore_main_fd_handler_active_get(fd_handler,
|
|
||||||
ECORE_FD_WRITE))
|
|
||||||
_ecore_con_server_flush(svr);
|
|
||||||
|
|
||||||
return ECORE_CALLBACK_RENEW;
|
return ECORE_CALLBACK_RENEW;
|
||||||
}
|
}
|
||||||
|
@ -1938,63 +1907,78 @@ _ecore_con_cl_udp_handler(void *data,
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
_ecore_con_svr_udp_handler(void *data,
|
_ecore_con_svr_udp_handler(void *data,
|
||||||
Ecore_Fd_Handler *fd_handler)
|
Ecore_Fd_Handler *fd_handler)
|
||||||
{
|
|
||||||
Ecore_Con_Server *svr;
|
|
||||||
Ecore_Con_Client *cl = NULL;
|
|
||||||
|
|
||||||
svr = data;
|
|
||||||
if (svr->dead)
|
|
||||||
return ECORE_CALLBACK_RENEW;
|
|
||||||
|
|
||||||
if (svr->delete_me)
|
|
||||||
return ECORE_CALLBACK_RENEW;
|
|
||||||
|
|
||||||
if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
|
|
||||||
{
|
{
|
||||||
unsigned char buf[READBUFSIZ];
|
unsigned char buf[READBUFSIZ];
|
||||||
unsigned char client_addr[256];
|
unsigned char client_addr[256];
|
||||||
unsigned int client_addr_len = sizeof(client_addr);
|
unsigned int client_addr_len = sizeof(client_addr);
|
||||||
int num;
|
int num;
|
||||||
|
Ecore_Con_Server *svr;
|
||||||
|
Ecore_Con_Client *cl = NULL;
|
||||||
|
|
||||||
|
svr = data;
|
||||||
|
|
||||||
|
if (svr->delete_me || svr->dead)
|
||||||
|
return ECORE_CALLBACK_RENEW;
|
||||||
|
|
||||||
|
if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_WRITE))
|
||||||
|
{
|
||||||
|
_ecore_con_client_flush(cl);
|
||||||
|
return ECORE_CALLBACK_RENEW;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
|
||||||
|
return ECORE_CALLBACK_RENEW;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
num = fcntl(svr->fd, F_SETFL, O_NONBLOCK);
|
num = fcntl(svr->fd, F_SETFL, O_NONBLOCK);
|
||||||
if (num >= 0)
|
if (num >= 0)
|
||||||
num =
|
num = recvfrom(svr->fd, buf, sizeof(buf), 0,
|
||||||
recvfrom(svr->fd, buf, sizeof(buf), 0,
|
|
||||||
(struct sockaddr *)&client_addr,
|
(struct sockaddr *)&client_addr,
|
||||||
&client_addr_len);
|
&client_addr_len);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
num =
|
num = recvfrom(svr->fd, buf, sizeof(buf), MSG_DONTWAIT,
|
||||||
recvfrom(svr->fd, buf, sizeof(buf), MSG_DONTWAIT,
|
|
||||||
(struct sockaddr *)&client_addr,
|
(struct sockaddr *)&client_addr,
|
||||||
&client_addr_len);
|
&client_addr_len);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (num > 0)
|
if ((errno == EIO) || (errno == EBADF) || (errno == EPIPE) ||
|
||||||
|
(errno == EINVAL) || (errno == ENOSPC) || (errno == ECONNREFUSED))
|
||||||
{
|
{
|
||||||
if (!svr->delete_me)
|
if (!svr->delete_me)
|
||||||
{
|
{
|
||||||
Ecore_Con_Event_Client_Data *e;
|
/* we lost our client! */
|
||||||
unsigned char *inbuf;
|
Ecore_Con_Event_Client_Del *e;
|
||||||
|
|
||||||
|
e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
|
||||||
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, ECORE_CALLBACK_RENEW);
|
||||||
|
|
||||||
|
svr->event_count++;
|
||||||
|
/* be explicit here */
|
||||||
|
e->client = NULL;
|
||||||
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
|
||||||
|
_ecore_con_event_client_del_free, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
svr->dead = EINA_TRUE;
|
||||||
|
svr->fd_handler = NULL;
|
||||||
|
return ECORE_CALLBACK_CANCEL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Create a new client for use in the client data event */
|
/* Create a new client for use in the client data event */
|
||||||
cl = calloc(1, sizeof(Ecore_Con_Client));
|
cl = calloc(1, sizeof(Ecore_Con_Client));
|
||||||
if(!cl)
|
EINA_SAFETY_ON_NULL_RETURN_VAL(cl, ECORE_CALLBACK_RENEW);
|
||||||
return ECORE_CALLBACK_RENEW;
|
|
||||||
|
|
||||||
cl->buf = NULL;
|
|
||||||
cl->fd = 0;
|
|
||||||
cl->fd_handler = NULL;
|
|
||||||
cl->host_server = svr;
|
cl->host_server = svr;
|
||||||
cl->client_addr = calloc(1, client_addr_len);
|
cl->client_addr = calloc(1, client_addr_len);
|
||||||
cl->client_addr_len = client_addr_len;
|
|
||||||
if(!cl->client_addr)
|
if(!cl->client_addr)
|
||||||
{
|
{
|
||||||
free(cl);
|
free(cl);
|
||||||
return ECORE_CALLBACK_RENEW;
|
return ECORE_CALLBACK_RENEW;
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
|
ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
|
||||||
|
@ -2004,96 +1988,57 @@ _ecore_con_svr_udp_handler(void *data,
|
||||||
cl->ip = _ecore_con_pretty_ip(cl->client_addr,
|
cl->ip = _ecore_con_pretty_ip(cl->client_addr,
|
||||||
cl->client_addr_len);
|
cl->client_addr_len);
|
||||||
|
|
||||||
inbuf = malloc(num);
|
{ /* indent to keep it all nicely separated */
|
||||||
if(!inbuf)
|
|
||||||
{
|
|
||||||
free(cl->client_addr);
|
|
||||||
free(cl);
|
|
||||||
return ECORE_CALLBACK_RENEW;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(inbuf, buf, num);
|
|
||||||
|
|
||||||
e = calloc(1, sizeof(Ecore_Con_Event_Client_Data));
|
|
||||||
if (e)
|
|
||||||
{
|
|
||||||
svr->event_count++;
|
|
||||||
_ecore_con_cl_timer_update(cl);
|
|
||||||
e->client = cl;
|
|
||||||
e->data = inbuf;
|
|
||||||
e->size = num;
|
|
||||||
ecore_event_add(ECORE_CON_EVENT_CLIENT_DATA, e,
|
|
||||||
_ecore_con_event_client_data_free,
|
|
||||||
NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!cl->delete_me)
|
|
||||||
{
|
|
||||||
Ecore_Con_Event_Client_Add *add;
|
Ecore_Con_Event_Client_Add *add;
|
||||||
|
|
||||||
add = calloc(1, sizeof(Ecore_Con_Event_Client_Add));
|
add = calloc(1, sizeof(Ecore_Con_Event_Client_Add));
|
||||||
if(add)
|
EINA_SAFETY_ON_NULL_RETURN_VAL(add, ECORE_CALLBACK_RENEW);
|
||||||
{
|
|
||||||
/*cl->event_count++;*/
|
/*cl->event_count++;*/
|
||||||
add->client = cl;
|
add->client = cl;
|
||||||
_ecore_con_cl_timer_update(cl);
|
_ecore_con_cl_timer_update(cl);
|
||||||
ecore_event_add(ECORE_CON_EVENT_CLIENT_ADD, add,
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_ADD, add,
|
||||||
_ecore_con_event_client_add_free, NULL);
|
_ecore_con_event_client_add_free, NULL);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ((errno == EIO) || (errno == EBADF) ||
|
|
||||||
(errno == EPIPE) || (errno == EINVAL) ||
|
|
||||||
(errno == ENOSPC) || (errno == ECONNREFUSED))
|
|
||||||
{
|
|
||||||
if (!svr->delete_me)
|
|
||||||
{
|
|
||||||
/* we lost our client! */
|
|
||||||
Ecore_Con_Event_Client_Del *e;
|
|
||||||
|
|
||||||
e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
|
|
||||||
if (e)
|
|
||||||
{
|
{
|
||||||
|
Ecore_Con_Event_Client_Data *e;
|
||||||
|
e = calloc(1, sizeof(Ecore_Con_Event_Client_Data));
|
||||||
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, ECORE_CALLBACK_RENEW);
|
||||||
|
|
||||||
svr->event_count++;
|
svr->event_count++;
|
||||||
/* be explicit here */
|
_ecore_con_cl_timer_update(cl);
|
||||||
e->client = NULL;
|
e->client = cl;
|
||||||
ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
|
e->data = malloc(num);
|
||||||
_ecore_con_event_client_del_free, NULL);
|
if(!e->data)
|
||||||
}
|
{
|
||||||
|
free(cl->client_addr);
|
||||||
|
free(cl);
|
||||||
|
return ECORE_CALLBACK_RENEW;
|
||||||
}
|
}
|
||||||
|
|
||||||
svr->dead = EINA_TRUE;
|
memcpy(e->data, buf, num);
|
||||||
if (svr->fd_handler)
|
e->size = num;
|
||||||
ecore_main_fd_handler_del(svr->fd_handler);
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_DATA, e,
|
||||||
|
_ecore_con_event_client_data_free, NULL);
|
||||||
svr->fd_handler = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (ecore_main_fd_handler_active_get(fd_handler,
|
|
||||||
ECORE_FD_WRITE))
|
|
||||||
_ecore_con_client_flush(cl);
|
|
||||||
|
|
||||||
return ECORE_CALLBACK_RENEW;
|
return ECORE_CALLBACK_RENEW;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_ecore_con_svr_cl_read(Ecore_Con_Client *cl)
|
_ecore_con_svr_cl_read(Ecore_Con_Client *cl)
|
||||||
{
|
|
||||||
unsigned char *inbuf = NULL;
|
|
||||||
int inbuf_num = 0;
|
|
||||||
int tries;
|
|
||||||
|
|
||||||
for (tries = 0; tries < 16; tries++)
|
|
||||||
{
|
{
|
||||||
int num = 0;
|
int num = 0;
|
||||||
Eina_Bool lost_client = EINA_TRUE;
|
Eina_Bool lost_client = EINA_TRUE;
|
||||||
unsigned char buf[READBUFSIZ];
|
unsigned char buf[READBUFSIZ];
|
||||||
|
|
||||||
errno = 0;
|
|
||||||
|
|
||||||
if (cl->handshaking)
|
if (cl->handshaking)
|
||||||
{
|
{
|
||||||
|
/* add an extra handshake attempt just before read, even though
|
||||||
|
* read also attempts to handshake, to try to finish sooner
|
||||||
|
*/
|
||||||
if (ecore_con_ssl_client_init(cl))
|
if (ecore_con_ssl_client_init(cl))
|
||||||
lost_client = EINA_FALSE;
|
lost_client = EINA_FALSE;
|
||||||
|
|
||||||
|
@ -2102,45 +2047,36 @@ _ecore_con_svr_cl_read(Ecore_Con_Client *cl)
|
||||||
|
|
||||||
if (!(cl->host_server->type & ECORE_CON_SSL))
|
if (!(cl->host_server->type & ECORE_CON_SSL))
|
||||||
{
|
{
|
||||||
if ((num = read(cl->fd, buf, READBUFSIZ)) <= 0)
|
errno = 0;
|
||||||
if ((num < 0) && (errno == EAGAIN))
|
num = read(cl->fd, buf, sizeof(buf));
|
||||||
|
if (errno == EAGAIN)
|
||||||
lost_client = EINA_FALSE;
|
lost_client = EINA_FALSE;
|
||||||
}
|
}
|
||||||
else if (!(num = ecore_con_ssl_client_read(cl, buf, READBUFSIZ)))
|
else if (!(num = ecore_con_ssl_client_read(cl, buf, sizeof(buf))))
|
||||||
lost_client = EINA_FALSE;
|
lost_client = EINA_FALSE;
|
||||||
|
|
||||||
if (num > 0)
|
if (num && (!cl->delete_me))
|
||||||
{
|
|
||||||
unsigned char *tmp;
|
|
||||||
if (!(tmp = realloc(inbuf, inbuf_num + num)))
|
|
||||||
{
|
|
||||||
/* FIXME: this should probably do something, but what? */
|
|
||||||
if (inbuf)
|
|
||||||
free(inbuf);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
inbuf = tmp;
|
|
||||||
memcpy(inbuf + inbuf_num, buf, num);
|
|
||||||
inbuf_num += num;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inbuf && (!cl->delete_me))
|
|
||||||
{
|
{
|
||||||
Ecore_Con_Event_Client_Data *e;
|
Ecore_Con_Event_Client_Data *e;
|
||||||
|
|
||||||
e = malloc(sizeof(Ecore_Con_Event_Client_Data));
|
e = malloc(sizeof(Ecore_Con_Event_Client_Data));
|
||||||
if (e)
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
||||||
{
|
|
||||||
cl->event_count++;
|
cl->event_count++;
|
||||||
_ecore_con_cl_timer_update(cl);
|
_ecore_con_cl_timer_update(cl);
|
||||||
e->client = cl;
|
e->client = cl;
|
||||||
e->data = inbuf;
|
e->data = malloc(num);
|
||||||
e->size = inbuf_num;
|
if (!e->data)
|
||||||
|
{
|
||||||
|
free(e);
|
||||||
|
ERR("alloc!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
memcpy(e->data, buf, num);
|
||||||
|
e->size = num;
|
||||||
ecore_event_add(ECORE_CON_EVENT_CLIENT_DATA, e,
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_DATA, e,
|
||||||
_ecore_con_event_client_data_free, NULL);
|
_ecore_con_event_client_data_free, NULL);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (lost_client && (!cl->delete_me))
|
if (lost_client && (!cl->delete_me))
|
||||||
{
|
{
|
||||||
|
@ -2148,15 +2084,14 @@ _ecore_con_svr_cl_read(Ecore_Con_Client *cl)
|
||||||
Ecore_Con_Event_Client_Del *e;
|
Ecore_Con_Event_Client_Del *e;
|
||||||
|
|
||||||
e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
|
e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
|
||||||
if (e)
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
||||||
{
|
|
||||||
cl->event_count++;
|
cl->event_count++;
|
||||||
_ecore_con_cl_timer_update(cl);
|
_ecore_con_cl_timer_update(cl);
|
||||||
e->client = cl;
|
e->client = cl;
|
||||||
ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
|
||||||
_ecore_con_event_client_del_free, NULL);
|
_ecore_con_event_client_del_free, NULL);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (lost_client)
|
if (lost_client)
|
||||||
{
|
{
|
||||||
|
@ -2166,9 +2101,6 @@ _ecore_con_svr_cl_read(Ecore_Con_Client *cl)
|
||||||
|
|
||||||
cl->fd_handler = NULL;
|
cl->fd_handler = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Eina_Bool
|
static Eina_Bool
|
||||||
|
@ -2195,29 +2127,27 @@ _ecore_con_svr_cl_handler(void *data,
|
||||||
|
|
||||||
cl->dead = EINA_TRUE;
|
cl->dead = EINA_TRUE;
|
||||||
e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
|
e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
|
||||||
if (e)
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, ECORE_CALLBACK_RENEW);
|
||||||
{
|
|
||||||
cl->event_count++;
|
cl->event_count++;
|
||||||
_ecore_con_cl_timer_update(cl);
|
_ecore_con_cl_timer_update(cl);
|
||||||
e->client = cl;
|
e->client = cl;
|
||||||
ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
|
||||||
_ecore_con_event_client_del_free, NULL);
|
_ecore_con_event_client_del_free, NULL);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (!cl->ssl_state)
|
else if (!cl->ssl_state)
|
||||||
{
|
{
|
||||||
Ecore_Con_Event_Client_Add *add;
|
Ecore_Con_Event_Client_Add *e;
|
||||||
|
|
||||||
add = calloc(1, sizeof(Ecore_Con_Event_Client_Add));
|
e = calloc(1, sizeof(Ecore_Con_Event_Client_Add));
|
||||||
if(add)
|
EINA_SAFETY_ON_NULL_RETURN_VAL(e, ECORE_CALLBACK_RENEW);
|
||||||
{
|
|
||||||
add->client = cl;
|
e->client = cl;
|
||||||
_ecore_con_cl_timer_update(cl);
|
_ecore_con_cl_timer_update(cl);
|
||||||
ecore_event_add(ECORE_CON_EVENT_CLIENT_ADD, add,
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_ADD, e,
|
||||||
_ecore_con_event_client_add_free, NULL);
|
_ecore_con_event_client_add_free, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
|
else if (ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ))
|
||||||
_ecore_con_svr_cl_read(cl);
|
_ecore_con_svr_cl_read(cl);
|
||||||
|
|
||||||
|
@ -2312,14 +2242,13 @@ _ecore_con_client_flush(Ecore_Con_Client *cl)
|
||||||
Ecore_Con_Event_Client_Del *e;
|
Ecore_Con_Event_Client_Del *e;
|
||||||
|
|
||||||
e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
|
e = calloc(1, sizeof(Ecore_Con_Event_Client_Del));
|
||||||
if (e)
|
EINA_SAFETY_ON_NULL_RETURN(e);
|
||||||
{
|
|
||||||
cl->event_count++;
|
cl->event_count++;
|
||||||
_ecore_con_cl_timer_update(cl);
|
_ecore_con_cl_timer_update(cl);
|
||||||
e->client = cl;
|
e->client = cl;
|
||||||
ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
|
ecore_event_add(ECORE_CON_EVENT_CLIENT_DEL, e,
|
||||||
_ecore_con_event_client_del_free, NULL);
|
_ecore_con_event_client_del_free, NULL);
|
||||||
}
|
|
||||||
|
|
||||||
cl->dead = EINA_TRUE;
|
cl->dead = EINA_TRUE;
|
||||||
if (cl->fd_handler)
|
if (cl->fd_handler)
|
||||||
|
|
Loading…
Reference in New Issue