summaryrefslogtreecommitdiff
path: root/legacy/ecore
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2005-04-29 04:51:31 +0000
committerCarsten Haitzler <raster@rasterman.com>2005-04-29 04:51:31 +0000
commit4eb5ded2acc6f54365a880bb6f76cf6cb0efec3c (patch)
tree55003543bf32707f49f752190fed67bf1577f27d /legacy/ecore
parent07b258a472570108e50c45c4aaf02e006494eec3 (diff)
simons client limiter patch
SVN revision: 14467
Diffstat (limited to '')
-rw-r--r--legacy/ecore/AUTHORS1
-rw-r--r--legacy/ecore/src/lib/ecore_con/Ecore_Con.h1
-rw-r--r--legacy/ecore/src/lib/ecore_con/ecore_con.c77
-rw-r--r--legacy/ecore/src/lib/ecore_con/ecore_con_private.h4
4 files changed, 72 insertions, 11 deletions
diff --git a/legacy/ecore/AUTHORS b/legacy/ecore/AUTHORS
index 6830d30cc5..8b51c5062a 100644
--- a/legacy/ecore/AUTHORS
+++ b/legacy/ecore/AUTHORS
@@ -12,3 +12,4 @@ Nathan Ingersoll <rbdpngn@users.sourceforge.net>
12Andrew Elcock <andy@elcock.org> 12Andrew Elcock <andy@elcock.org>
13Kim Woelders <kim@woelders.dk> 13Kim Woelders <kim@woelders.dk>
14Sebastian Dransfeld <sebastid@tango.flipp.net> 14Sebastian Dransfeld <sebastid@tango.flipp.net>
15Simon Poole <simon.armlinux@themalago.net>
diff --git a/legacy/ecore/src/lib/ecore_con/Ecore_Con.h b/legacy/ecore/src/lib/ecore_con/Ecore_Con.h
index f5e4221fe8..59ee251eee 100644
--- a/legacy/ecore/src/lib/ecore_con/Ecore_Con.h
+++ b/legacy/ecore/src/lib/ecore_con/Ecore_Con.h
@@ -126,6 +126,7 @@ extern "C" {
126 EAPI void *ecore_con_server_data_get(Ecore_Con_Server *svr); 126 EAPI void *ecore_con_server_data_get(Ecore_Con_Server *svr);
127 EAPI int ecore_con_server_connected_get(Ecore_Con_Server *svr); 127 EAPI int ecore_con_server_connected_get(Ecore_Con_Server *svr);
128 EAPI int ecore_con_server_send(Ecore_Con_Server *svr, void *data, int size); 128 EAPI int ecore_con_server_send(Ecore_Con_Server *svr, void *data, int size);
129 EAPI void ecore_con_server_client_limit_set(Ecore_Con_Server *svr, int client_limit, char reject_excess_clients);
129 130
130 EAPI int ecore_con_client_send(Ecore_Con_Client *cl, void *data, int size); 131 EAPI int ecore_con_client_send(Ecore_Con_Client *cl, void *data, int size);
131 EAPI Ecore_Con_Server *ecore_con_client_server_get(Ecore_Con_Client *cl); 132 EAPI Ecore_Con_Server *ecore_con_client_server_get(Ecore_Con_Client *cl);
diff --git a/legacy/ecore/src/lib/ecore_con/ecore_con.c b/legacy/ecore/src/lib/ecore_con/ecore_con.c
index a0f3211aad..b394ae22a8 100644
--- a/legacy/ecore/src/lib/ecore_con/ecore_con.c
+++ b/legacy/ecore/src/lib/ecore_con/ecore_con.c
@@ -46,7 +46,7 @@ int ECORE_CON_EVENT_SERVER_DEL = 0;
46int ECORE_CON_EVENT_CLIENT_DATA = 0; 46int ECORE_CON_EVENT_CLIENT_DATA = 0;
47int ECORE_CON_EVENT_SERVER_DATA = 0; 47int ECORE_CON_EVENT_SERVER_DATA = 0;
48 48
49static Ecore_Con_Server *servers = NULL; 49static Ecore_List *servers = NULL;
50static int init_count = 0; 50static int init_count = 0;
51 51
52#define LENGTH_OF_SOCKADDR_UN(s) (strlen((s)->sun_path) + (size_t)(((struct sockaddr_un *)NULL)->sun_path)) 52#define LENGTH_OF_SOCKADDR_UN(s) (strlen((s)->sun_path) + (size_t)(((struct sockaddr_un *)NULL)->sun_path))
@@ -82,6 +82,8 @@ ecore_con_init(void)
82 SSL_load_error_strings(); 82 SSL_load_error_strings();
83#endif 83#endif
84 } 84 }
85 if (!servers)
86 servers = ecore_list_new();
85 return init_count; 87 return init_count;
86} 88}
87 89
@@ -98,7 +100,10 @@ ecore_con_shutdown(void)
98 { 100 {
99 init_count--; 101 init_count--;
100 if (init_count > 0) return init_count; 102 if (init_count > 0) return init_count;
101 while (servers) _ecore_con_server_free(servers); 103 while (!ecore_list_is_empty(servers))
104 _ecore_con_server_free(ecore_list_remove_first(servers));
105 ecore_list_destroy(servers);
106 servers = NULL;
102 } 107 }
103 return 0; 108 return 0;
104} 109}
@@ -309,7 +314,10 @@ ecore_con_server_add(Ecore_Con_Type compl_type,
309 svr->port = port; 314 svr->port = port;
310 svr->data = (void *)data; 315 svr->data = (void *)data;
311 svr->created = 1; 316 svr->created = 1;
312 servers = _ecore_list_append(servers, svr); 317 svr->reject_excess_clients = 0;
318 svr->client_limit = -1;
319 svr->clients = ecore_list_new();
320 ecore_list_append(servers, svr);
313 ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER); 321 ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER);
314 return svr; 322 return svr;
315 323
@@ -481,7 +489,10 @@ ecore_con_server_connect(Ecore_Con_Type compl_type,
481 svr->port = port; 489 svr->port = port;
482 svr->data = (void *)data; 490 svr->data = (void *)data;
483 svr->created = 0; 491 svr->created = 0;
484 servers = _ecore_list_append(servers, svr); 492 svr->reject_excess_clients = 0;
493 svr->client_limit = -1;
494 svr->clients = ecore_list_new();
495 ecore_list_append(servers, svr);
485 ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER); 496 ECORE_MAGIC_SET(svr, ECORE_MAGIC_CON_SERVER);
486 return svr; 497 return svr;
487 498
@@ -517,6 +528,7 @@ ecore_con_server_del(Ecore_Con_Server *svr)
517 } 528 }
518 data = svr->data; 529 data = svr->data;
519 _ecore_con_server_free(svr); 530 _ecore_con_server_free(svr);
531 if (ecore_list_goto(servers, svr)) ecore_list_remove(servers);
520 return data; 532 return data;
521} 533}
522 534
@@ -601,6 +613,41 @@ ecore_con_server_send(Ecore_Con_Server *svr, void *data, int size)
601} 613}
602 614
603/** 615/**
616 * Sets a limit on the number of clients that can be handled concurrently
617 * by the given server, and a policy on what to do if excess clients try to
618 * connect.
619 * Beware that if you set this once ecore is already running, you may
620 * already have pending CLIENT_ADD events in your event queue. Those
621 * clients have already connected and will not be affected by this call.
622 * Only clients subsequently trying to connect will be affected.
623 * @param svr The given server.
624 * @param client_limit The maximum number of clients to handle
625 * concurrently. -1 means unlimited (default). 0
626 * effectively disables the server.
627 * @param reject_excess_clients Set to 1 to automatically disconnect
628 * excess clients as soon as they connect if you are
629 * already handling client_limit clients. Set to 0
630 * (default) to just hold off on the "accept()"
631 * system call until the number of active clients
632 * drops. This causes the kernel to queue up to 4096
633 * connections (or your kernel's limit, whichever is
634 * lower).
635 * @ingroup Ecore_Con_Server_Group
636 */
637void
638ecore_con_server_client_limit_set(Ecore_Con_Server *svr, int client_limit, char reject_excess_clients)
639{
640 if (!ECORE_MAGIC_CHECK(svr, ECORE_MAGIC_CON_SERVER))
641 {
642 ECORE_MAGIC_FAIL(svr, ECORE_MAGIC_CON_SERVER,
643 "ecore_con_server_client_limit_set");
644 return;
645 }
646 svr->client_limit = client_limit;
647 svr->reject_excess_clients = reject_excess_clients;
648}
649
650/**
604 * @defgroup Ecore_Con_Client_Group Ecore Connection Client Functions 651 * @defgroup Ecore_Con_Client_Group Ecore Connection Client Functions
605 * 652 *
606 * Functions that operate on Ecore connection client objects. 653 * Functions that operate on Ecore connection client objects.
@@ -686,6 +733,7 @@ ecore_con_client_del(Ecore_Con_Client *cl)
686 } 733 }
687 data = cl->data; 734 data = cl->data;
688 _ecore_con_client_free(cl); 735 _ecore_con_client_free(cl);
736 if (ecore_list_goto(cl->server->clients, cl)) ecore_list_remove(cl->server->clients);
689 return data; 737 return data;
690} 738}
691 739
@@ -746,9 +794,9 @@ _ecore_con_server_free(Ecore_Con_Server *svr)
746 ECORE_MAGIC_SET(svr, ECORE_MAGIC_NONE); 794 ECORE_MAGIC_SET(svr, ECORE_MAGIC_NONE);
747 while ((svr->write_buf) && (!svr->dead)) _ecore_con_server_flush(svr); 795 while ((svr->write_buf) && (!svr->dead)) _ecore_con_server_flush(svr);
748 if (svr->write_buf) free(svr->write_buf); 796 if (svr->write_buf) free(svr->write_buf);
749 servers = _ecore_list_remove(servers, svr); 797 while (!ecore_list_is_empty(svr->clients))
750 while (svr->clients) 798 _ecore_con_client_free(ecore_list_remove_first(svr->clients));
751 _ecore_con_client_free((Ecore_Con_Client *)svr->clients); 799 ecore_list_destroy(svr->clients);
752 if ((svr->created) && (svr->path)) unlink(svr->path); 800 if ((svr->created) && (svr->path)) unlink(svr->path);
753 if (svr->fd >= 0) close(svr->fd); 801 if (svr->fd >= 0) close(svr->fd);
754#if USE_OPENSSL 802#if USE_OPENSSL
@@ -771,7 +819,6 @@ _ecore_con_client_free(Ecore_Con_Client *cl)
771 ECORE_MAGIC_SET(cl, ECORE_MAGIC_NONE); 819 ECORE_MAGIC_SET(cl, ECORE_MAGIC_NONE);
772 while ((cl->buf) && (!cl->dead)) _ecore_con_client_flush(cl); 820 while ((cl->buf) && (!cl->dead)) _ecore_con_client_flush(cl);
773 if (cl->buf) free(cl->buf); 821 if (cl->buf) free(cl->buf);
774 cl->server->clients = _ecore_list_remove(cl->server->clients, cl);
775 if (cl->fd >= 0) close(cl->fd); 822 if (cl->fd >= 0) close(cl->fd);
776 if (cl->fd_handler) ecore_main_fd_handler_del(cl->fd_handler); 823 if (cl->fd_handler) ecore_main_fd_handler_del(cl->fd_handler);
777 free(cl); 824 free(cl);
@@ -787,13 +834,23 @@ _ecore_con_svr_handler(void *data, Ecore_Fd_Handler *fd_handler __UNUSED__)
787 834
788 svr = data; 835 svr = data;
789 if (svr->dead) return 1; 836 if (svr->dead) return 1;
837 if ((svr->client_limit >= 0) && (!svr->reject_excess_clients))
838 {
839 if (ecore_list_nodes(svr->clients) >= svr->client_limit) return 1;
840 }
790 /* a new client */ 841 /* a new client */
791 size_in = sizeof(struct sockaddr_in); 842 size_in = sizeof(struct sockaddr_in);
792 new_fd = accept(svr->fd, (struct sockaddr *)&incoming, &size_in); 843 new_fd = accept(svr->fd, (struct sockaddr *)&incoming, &size_in);
793 if (new_fd >= 0) 844 if (new_fd >= 0)
794 { 845 {
795 Ecore_Con_Client *cl; 846 Ecore_Con_Client *cl;
796 847
848 if ((svr->client_limit >= 0) && (svr->reject_excess_clients))
849 {
850 close(new_fd);
851 return 1;
852 }
853
797 cl = calloc(1, sizeof(Ecore_Con_Client)); 854 cl = calloc(1, sizeof(Ecore_Con_Client));
798 if (!cl) 855 if (!cl)
799 { 856 {
@@ -809,7 +866,7 @@ _ecore_con_svr_handler(void *data, Ecore_Fd_Handler *fd_handler __UNUSED__)
809 _ecore_con_svr_cl_handler, 866 _ecore_con_svr_cl_handler,
810 cl, NULL, NULL); 867 cl, NULL, NULL);
811 ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT); 868 ECORE_MAGIC_SET(cl, ECORE_MAGIC_CON_CLIENT);
812 svr->clients = _ecore_list_append(svr->clients, cl); 869 ecore_list_append(svr->clients, cl);
813 { 870 {
814 Ecore_Con_Event_Client_Add *e; 871 Ecore_Con_Event_Client_Add *e;
815 872
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 40454c655b..7cc26e2425 100644
--- a/legacy/ecore/src/lib/ecore_con/ecore_con_private.h
+++ b/legacy/ecore/src/lib/ecore_con/ecore_con_private.h
@@ -48,13 +48,15 @@ struct _Ecore_Con_Server
48 char *path; 48 char *path;
49 void *data; 49 void *data;
50 Ecore_Fd_Handler *fd_handler; 50 Ecore_Fd_Handler *fd_handler;
51 Ecore_Con_Client *clients; 51 Ecore_List *clients;
52 int write_buf_size; 52 int write_buf_size;
53 int write_buf_offset; 53 int write_buf_offset;
54 unsigned char *write_buf; 54 unsigned char *write_buf;
55 char dead : 1; 55 char dead : 1;
56 char created : 1; 56 char created : 1;
57 char connecting : 1; 57 char connecting : 1;
58 char reject_excess_clients : 1;
59 int client_limit;
58 60
59#if USE_OPENSSL 61#if USE_OPENSSL
60 SSL_CTX *ssl_ctx; 62 SSL_CTX *ssl_ctx;