summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--legacy/ecore/src/lib/ecore_con/ecore_con.c81
-rw-r--r--legacy/ecore/src/lib/ecore_con/ecore_con_private.h14
-rw-r--r--legacy/ecore/src/lib/ecore_con/ecore_con_ssl.c20
3 files changed, 42 insertions, 73 deletions
diff --git a/legacy/ecore/src/lib/ecore_con/ecore_con.c b/legacy/ecore/src/lib/ecore_con/ecore_con.c
index 0b2cf37725..7f46c5ddff 100644
--- a/legacy/ecore/src/lib/ecore_con/ecore_con.c
+++ b/legacy/ecore/src/lib/ecore_con/ecore_con.c
@@ -339,8 +339,8 @@ error:
339 if (svr->fd > 0) 339 if (svr->fd > 0)
340 close(svr->fd); 340 close(svr->fd);
341 341
342 if (svr->write_buf) 342 if (svr->buf)
343 free(svr->write_buf); 343 eina_binbuf_free(svr->buf);
344 344
345 if (svr->ip) 345 if (svr->ip)
346 eina_stringshare_del(svr->ip); 346 eina_stringshare_del(svr->ip);
@@ -607,25 +607,12 @@ ecore_con_server_send(Ecore_Con_Server *svr,
607 if (svr->fd_handler) 607 if (svr->fd_handler)
608 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE); 608 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ | ECORE_FD_WRITE);
609 609
610 if (svr->write_buf) 610 if (!svr->buf)
611 { 611 {
612 unsigned char *newbuf; 612 svr->buf = eina_binbuf_new();
613 613 EINA_SAFETY_ON_NULL_RETURN_VAL(svr->buf, 0);
614 newbuf = realloc(svr->write_buf, svr->write_buf_size + size);
615 EINA_SAFETY_ON_NULL_RETURN_VAL(newbuf, 0);
616
617 svr->write_buf = newbuf;
618 memcpy(svr->write_buf + svr->write_buf_size, data, size);
619 svr->write_buf_size += size;
620 }
621 else
622 {
623 svr->write_buf = malloc(size);
624 EINA_SAFETY_ON_NULL_RETURN_VAL(svr->write_buf, 0);
625
626 svr->write_buf_size = size;
627 memcpy(svr->write_buf, data, size);
628 } 614 }
615 eina_binbuf_append_length(svr->buf, data, size);
629 616
630 return size; 617 return size;
631} 618}
@@ -722,26 +709,12 @@ ecore_con_client_send(Ecore_Con_Client *cl,
722 if (cl->host_server && ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP)) 709 if (cl->host_server && ((cl->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP))
723 sendto(cl->host_server->fd, data, size, 0, (struct sockaddr *)cl->client_addr, 710 sendto(cl->host_server->fd, data, size, 0, (struct sockaddr *)cl->client_addr,
724 cl->client_addr_len); 711 cl->client_addr_len);
725 else if (cl->buf) 712 else if (!cl->buf)
726 { 713 {
727 unsigned char *newbuf; 714 cl->buf = eina_binbuf_new();
728
729 newbuf = realloc(cl->buf, cl->buf_size + size);
730 EINA_SAFETY_ON_NULL_RETURN_VAL(newbuf, 0);
731
732 cl->buf = newbuf;
733
734 memcpy(cl->buf + cl->buf_size, data, size);
735 cl->buf_size += size;
736 }
737 else
738 {
739 cl->buf = malloc(size);
740 EINA_SAFETY_ON_NULL_RETURN_VAL(cl->buf, 0); 715 EINA_SAFETY_ON_NULL_RETURN_VAL(cl->buf, 0);
741
742 cl->buf_size = size;
743 memcpy(cl->buf, data, size);
744 } 716 }
717 eina_binbuf_append_length(cl->buf, data, size);
745 718
746 return size; 719 return size;
747} 720}
@@ -1097,7 +1070,7 @@ _ecore_con_server_free(Ecore_Con_Server *svr)
1097 ecore_con_info_data_clear(svr->infos->data); 1070 ecore_con_info_data_clear(svr->infos->data);
1098 svr->infos = eina_list_remove_list(svr->infos, svr->infos); 1071 svr->infos = eina_list_remove_list(svr->infos, svr->infos);
1099 } 1072 }
1100 if ((!svr->write_buf) && svr->delete_me && (!svr->dead) && (svr->event_count < 1)) 1073 if ((!svr->buf) && svr->delete_me && (!svr->dead) && (svr->event_count < 1))
1101 { 1074 {
1102 /* this is a catch-all for cases when a server is not properly killed. */ 1075 /* this is a catch-all for cases when a server is not properly killed. */
1103 svr->dead = EINA_TRUE; 1076 svr->dead = EINA_TRUE;
@@ -1109,7 +1082,7 @@ _ecore_con_server_free(Ecore_Con_Server *svr)
1109 return; 1082 return;
1110 ECORE_MAGIC_SET(svr, ECORE_MAGIC_NONE); 1083 ECORE_MAGIC_SET(svr, ECORE_MAGIC_NONE);
1111 t_start = ecore_time_get(); 1084 t_start = ecore_time_get();
1112 while ((svr->write_buf) && (!svr->dead)) 1085 while (svr->buf && (!svr->dead))
1113 { 1086 {
1114 _ecore_con_server_flush(svr); 1087 _ecore_con_server_flush(svr);
1115 t = ecore_time_get(); 1088 t = ecore_time_get();
@@ -1127,8 +1100,8 @@ _ecore_con_server_free(Ecore_Con_Server *svr)
1127 ecore_con_local_win32_server_del(svr); 1100 ecore_con_local_win32_server_del(svr);
1128#endif 1101#endif
1129 1102
1130 if (svr->write_buf) 1103 if (svr->buf)
1131 free(svr->write_buf); 1104 eina_binbuf_free(svr->buf);
1132 1105
1133 EINA_LIST_FREE(svr->clients, cl) 1106 EINA_LIST_FREE(svr->clients, cl)
1134 _ecore_con_client_free(cl); 1107 _ecore_con_client_free(cl);
@@ -1713,7 +1686,7 @@ svr_try_connect_plain(Ecore_Con_Server *svr)
1713 ecore_con_event_server_add(svr); 1686 ecore_con_event_server_add(svr);
1714 } 1687 }
1715 1688
1716 if (svr->fd_handler && (!svr->write_buf)) 1689 if (svr->fd_handler && (!svr->buf))
1717 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ); 1690 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
1718 1691
1719 if (!svr->dead) 1692 if (!svr->dead)
@@ -2161,13 +2134,13 @@ _ecore_con_server_flush(Ecore_Con_Server *svr)
2161 return; 2134 return;
2162#endif 2135#endif
2163 2136
2164 if (!svr->write_buf && svr->fd_handler) 2137 if ((!svr->buf) && svr->fd_handler)
2165 { 2138 {
2166 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ); 2139 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
2167 return; 2140 return;
2168 } 2141 }
2169 2142
2170 num = svr->write_buf_size - svr->write_buf_offset; 2143 num = eina_binbuf_length_get(svr->buf) - svr->write_buf_offset;
2171 2144
2172 /* check whether we need to write anything at all. 2145 /* check whether we need to write anything at all.
2173 * we must not write zero bytes with SSL_write() since it 2146 * we must not write zero bytes with SSL_write() since it
@@ -2188,9 +2161,9 @@ _ecore_con_server_flush(Ecore_Con_Server *svr)
2188 } 2161 }
2189 2162
2190 if (!(svr->type & ECORE_CON_SSL)) 2163 if (!(svr->type & ECORE_CON_SSL))
2191 count = write(svr->fd, svr->write_buf + svr->write_buf_offset, num); 2164 count = write(svr->fd, eina_binbuf_string_get(svr->buf) + svr->write_buf_offset, num);
2192 else 2165 else
2193 count = ecore_con_ssl_server_write(svr, svr->write_buf + svr->write_buf_offset, num); 2166 count = ecore_con_ssl_server_write(svr, eina_binbuf_string_get(svr->buf) + svr->write_buf_offset, num);
2194 2167
2195 if (count < 0) 2168 if (count < 0)
2196 { 2169 {
@@ -2203,12 +2176,11 @@ _ecore_con_server_flush(Ecore_Con_Server *svr)
2203 } 2176 }
2204 2177
2205 svr->write_buf_offset += count; 2178 svr->write_buf_offset += count;
2206 if (svr->write_buf_offset >= svr->write_buf_size) 2179 if (svr->write_buf_offset >= eina_binbuf_length_get(svr->buf))
2207 { 2180 {
2208 svr->write_buf_size = 0;
2209 svr->write_buf_offset = 0; 2181 svr->write_buf_offset = 0;
2210 free(svr->write_buf); 2182 eina_binbuf_free(svr->buf);
2211 svr->write_buf = NULL; 2183 svr->buf = NULL;
2212 if (svr->fd_handler) 2184 if (svr->fd_handler)
2213 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ); 2185 ecore_main_fd_handler_active_set(svr->fd_handler, ECORE_FD_READ);
2214 } 2186 }
@@ -2242,12 +2214,12 @@ _ecore_con_client_flush(Ecore_Con_Client *cl)
2242 2214
2243 if (!count) 2215 if (!count)
2244 { 2216 {
2245 num = cl->buf_size - cl->buf_offset; 2217 num = eina_binbuf_length_get(cl->buf) - cl->buf_offset;
2246 if (num <= 0) return; 2218 if (num <= 0) return;
2247 if (!(cl->host_server->type & ECORE_CON_SSL) || (!cl->upgrade)) 2219 if (!(cl->host_server->type & ECORE_CON_SSL) || (!cl->upgrade))
2248 count = write(cl->fd, cl->buf + cl->buf_offset, num); 2220 count = write(cl->fd, eina_binbuf_string_get(cl->buf) + cl->buf_offset, num);
2249 else 2221 else
2250 count = ecore_con_ssl_client_write(cl, cl->buf + cl->buf_offset, num); 2222 count = ecore_con_ssl_client_write(cl, eina_binbuf_string_get(cl->buf) + cl->buf_offset, num);
2251 } 2223 }
2252 2224
2253 if (count < 0) 2225 if (count < 0)
@@ -2268,11 +2240,10 @@ _ecore_con_client_flush(Ecore_Con_Client *cl)
2268 } 2240 }
2269 2241
2270 cl->buf_offset += count; 2242 cl->buf_offset += count;
2271 if (cl->buf_offset >= cl->buf_size) 2243 if (cl->buf_offset >= eina_binbuf_length_get(cl->buf))
2272 { 2244 {
2273 cl->buf_size = 0;
2274 cl->buf_offset = 0; 2245 cl->buf_offset = 0;
2275 free(cl->buf); 2246 eina_binbuf_free(cl->buf);
2276 cl->buf = NULL; 2247 cl->buf = NULL;
2277 if (cl->fd_handler) 2248 if (cl->fd_handler)
2278 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ); 2249 ecore_main_fd_handler_active_set(cl->fd_handler, ECORE_FD_READ);
diff --git a/legacy/ecore/src/lib/ecore_con/ecore_con_private.h b/legacy/ecore/src/lib/ecore_con/ecore_con_private.h
index e74b995c25..67a4b89cd3 100644
--- a/legacy/ecore/src/lib/ecore_con/ecore_con_private.h
+++ b/legacy/ecore/src/lib/ecore_con/ecore_con_private.h
@@ -89,9 +89,8 @@ struct _Ecore_Con_Client
89 Ecore_Con_Server *host_server; 89 Ecore_Con_Server *host_server;
90 void *data; 90 void *data;
91 Ecore_Fd_Handler *fd_handler; 91 Ecore_Fd_Handler *fd_handler;
92 int buf_size; 92 unsigned int buf_offset;
93 int buf_offset; 93 Eina_Binbuf *buf;
94 unsigned char *buf;
95 const char *ip; 94 const char *ip;
96 int event_count; 95 int event_count;
97 struct sockaddr *client_addr; 96 struct sockaddr *client_addr;
@@ -125,9 +124,8 @@ struct _Ecore_Con_Server
125 Ecore_Fd_Handler *fd_handler; 124 Ecore_Fd_Handler *fd_handler;
126 Eina_List *clients; 125 Eina_List *clients;
127 unsigned int client_count; 126 unsigned int client_count;
128 int write_buf_size; 127 Eina_Binbuf *buf;
129 int write_buf_offset; 128 unsigned int write_buf_offset;
130 unsigned char *write_buf;
131 Eina_List *infos; 129 Eina_List *infos;
132 int event_count; 130 int event_count;
133 int client_limit; 131 int client_limit;
@@ -283,7 +281,7 @@ int ecore_con_ssl_server_read(Ecore_Con_Server *svr,
283 unsigned char *buf, 281 unsigned char *buf,
284 int size); 282 int size);
285int ecore_con_ssl_server_write(Ecore_Con_Server *svr, 283int ecore_con_ssl_server_write(Ecore_Con_Server *svr,
286 unsigned char *buf, 284 const unsigned char *buf,
287 int size); 285 int size);
288Ecore_Con_Ssl_Error ecore_con_ssl_client_init(Ecore_Con_Client *svr); 286Ecore_Con_Ssl_Error ecore_con_ssl_client_init(Ecore_Con_Client *svr);
289Ecore_Con_Ssl_Error ecore_con_ssl_client_shutdown(Ecore_Con_Client *svr); 287Ecore_Con_Ssl_Error ecore_con_ssl_client_shutdown(Ecore_Con_Client *svr);
@@ -291,7 +289,7 @@ int ecore_con_ssl_client_read(Ecore_Con_Client *svr,
291 unsigned char *buf, 289 unsigned char *buf,
292 int size); 290 int size);
293int ecore_con_ssl_client_write(Ecore_Con_Client *svr, 291int ecore_con_ssl_client_write(Ecore_Con_Client *svr,
294 unsigned char *buf, 292 const unsigned char *buf,
295 int size); 293 int size);
296 294
297int ecore_con_info_get(Ecore_Con_Server *svr, 295int ecore_con_info_get(Ecore_Con_Server *svr,
diff --git a/legacy/ecore/src/lib/ecore_con/ecore_con_ssl.c b/legacy/ecore/src/lib/ecore_con/ecore_con_ssl.c
index 09dba2ab33..4e83813e63 100644
--- a/legacy/ecore/src/lib/ecore_con/ecore_con_ssl.c
+++ b/legacy/ecore/src/lib/ecore_con/ecore_con_ssl.c
@@ -188,14 +188,14 @@ static Ecore_Con_Ssl_Error SSL_SUFFIX(_ecore_con_ssl_server_prepare) (Ecore_Con_
188static Ecore_Con_Ssl_Error SSL_SUFFIX(_ecore_con_ssl_server_init) (Ecore_Con_Server * svr); 188static Ecore_Con_Ssl_Error SSL_SUFFIX(_ecore_con_ssl_server_init) (Ecore_Con_Server * svr);
189static Ecore_Con_Ssl_Error SSL_SUFFIX(_ecore_con_ssl_server_shutdown) (Ecore_Con_Server *svr); 189static Ecore_Con_Ssl_Error SSL_SUFFIX(_ecore_con_ssl_server_shutdown) (Ecore_Con_Server *svr);
190static int SSL_SUFFIX(_ecore_con_ssl_server_read) (Ecore_Con_Server *svr, unsigned char *buf, int size); 190static int SSL_SUFFIX(_ecore_con_ssl_server_read) (Ecore_Con_Server *svr, unsigned char *buf, int size);
191static int SSL_SUFFIX(_ecore_con_ssl_server_write) (Ecore_Con_Server *svr, unsigned char *buf, int size); 191static int SSL_SUFFIX(_ecore_con_ssl_server_write) (Ecore_Con_Server *svr, const unsigned char *buf, int size);
192 192
193static Ecore_Con_Ssl_Error SSL_SUFFIX(_ecore_con_ssl_client_init) (Ecore_Con_Client * cl); 193static Ecore_Con_Ssl_Error SSL_SUFFIX(_ecore_con_ssl_client_init) (Ecore_Con_Client * cl);
194static Ecore_Con_Ssl_Error SSL_SUFFIX(_ecore_con_ssl_client_shutdown) (Ecore_Con_Client *cl); 194static Ecore_Con_Ssl_Error SSL_SUFFIX(_ecore_con_ssl_client_shutdown) (Ecore_Con_Client *cl);
195static int SSL_SUFFIX(_ecore_con_ssl_client_read) (Ecore_Con_Client * cl, 195static int SSL_SUFFIX(_ecore_con_ssl_client_read) (Ecore_Con_Client * cl,
196 unsigned char *buf, int size); 196 unsigned char *buf, int size);
197static int SSL_SUFFIX(_ecore_con_ssl_client_write) (Ecore_Con_Client * cl, 197static int SSL_SUFFIX(_ecore_con_ssl_client_write) (Ecore_Con_Client * cl,
198 unsigned char *buf, int size); 198 const unsigned char *buf, int size);
199 199
200/* 200/*
201 * General SSL API 201 * General SSL API
@@ -260,7 +260,7 @@ ecore_con_ssl_server_read(Ecore_Con_Server *svr,
260 260
261int 261int
262ecore_con_ssl_server_write(Ecore_Con_Server *svr, 262ecore_con_ssl_server_write(Ecore_Con_Server *svr,
263 unsigned char *buf, 263 const unsigned char *buf,
264 int size) 264 int size)
265{ 265{
266 return SSL_SUFFIX(_ecore_con_ssl_server_write) (svr, buf, size); 266 return SSL_SUFFIX(_ecore_con_ssl_server_write) (svr, buf, size);
@@ -292,7 +292,7 @@ ecore_con_ssl_client_read(Ecore_Con_Client *cl,
292 292
293int 293int
294ecore_con_ssl_client_write(Ecore_Con_Client *cl, 294ecore_con_ssl_client_write(Ecore_Con_Client *cl,
295 unsigned char *buf, 295 const unsigned char *buf,
296 int size) 296 int size)
297{ 297{
298 return SSL_SUFFIX(_ecore_con_ssl_client_write) (cl, buf, size); 298 return SSL_SUFFIX(_ecore_con_ssl_client_write) (cl, buf, size);
@@ -884,7 +884,7 @@ _ecore_con_ssl_server_read_gnutls(Ecore_Con_Server *svr,
884 884
885static int 885static int
886_ecore_con_ssl_server_write_gnutls(Ecore_Con_Server *svr, 886_ecore_con_ssl_server_write_gnutls(Ecore_Con_Server *svr,
887 unsigned char *buf, 887 const unsigned char *buf,
888 int size) 888 int size)
889{ 889{
890 int num; 890 int num;
@@ -1109,7 +1109,7 @@ _ecore_con_ssl_client_read_gnutls(Ecore_Con_Client *cl,
1109 1109
1110static int 1110static int
1111_ecore_con_ssl_client_write_gnutls(Ecore_Con_Client *cl, 1111_ecore_con_ssl_client_write_gnutls(Ecore_Con_Client *cl,
1112 unsigned char *buf, 1112 const unsigned char *buf,
1113 int size) 1113 int size)
1114{ 1114{
1115 int num; 1115 int num;
@@ -1475,7 +1475,7 @@ _ecore_con_ssl_server_read_openssl(Ecore_Con_Server *svr,
1475 1475
1476static int 1476static int
1477_ecore_con_ssl_server_write_openssl(Ecore_Con_Server *svr, 1477_ecore_con_ssl_server_write_openssl(Ecore_Con_Server *svr,
1478 unsigned char *buf, 1478 const unsigned char *buf,
1479 int size) 1479 int size)
1480{ 1480{
1481 int num; 1481 int num;
@@ -1628,7 +1628,7 @@ _ecore_con_ssl_client_read_openssl(Ecore_Con_Client *cl,
1628 1628
1629static int 1629static int
1630_ecore_con_ssl_client_write_openssl(Ecore_Con_Client *cl, 1630_ecore_con_ssl_client_write_openssl(Ecore_Con_Client *cl,
1631 unsigned char *buf, 1631 const unsigned char *buf,
1632 int size) 1632 int size)
1633{ 1633{
1634 int num; 1634 int num;
@@ -1736,7 +1736,7 @@ _ecore_con_ssl_server_read_none(Ecore_Con_Server *svr __UNUSED__,
1736 1736
1737static int 1737static int
1738_ecore_con_ssl_server_write_none(Ecore_Con_Server *svr __UNUSED__, 1738_ecore_con_ssl_server_write_none(Ecore_Con_Server *svr __UNUSED__,
1739 unsigned char *buf __UNUSED__, 1739 const unsigned char *buf __UNUSED__,
1740 int size __UNUSED__) 1740 int size __UNUSED__)
1741{ 1741{
1742 return -1; 1742 return -1;
@@ -1770,7 +1770,7 @@ _ecore_con_ssl_client_read_none(Ecore_Con_Client *cl __UNUSED__,
1770 1770
1771static int 1771static int
1772_ecore_con_ssl_client_write_none(Ecore_Con_Client *cl __UNUSED__, 1772_ecore_con_ssl_client_write_none(Ecore_Con_Client *cl __UNUSED__,
1773 unsigned char *buf __UNUSED__, 1773 const unsigned char *buf __UNUSED__,
1774 int size __UNUSED__) 1774 int size __UNUSED__)
1775{ 1775{
1776 return -1; 1776 return -1;