Skip to content
Newer
Older
100644 133 lines (106 sloc) 2.9 KB
0f8d506 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2790 5dc97367-9…
alobbs authored Jan 27, 2009
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /* Cherokee
4 *
5 * Authors:
6 * Alvaro Lopez Ortega <alvaro@alobbs.com>
7 *
920e20b @alobbs Happy new year!
alobbs authored Jan 14, 2011
8 * Copyright (C) 2001-2011 Alvaro Lopez Ortega
0f8d506 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2790 5dc97367-9…
alobbs authored Jan 27, 2009
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * 02110-1301, USA.
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
23 */
0f8d506 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2790 5dc97367-9…
alobbs authored Jan 27, 2009
24
25 #include "common-internal.h"
26 #include "limiter.h"
27 #include "connection-protected.h"
28 #include "bogotime.h"
29 #include "thread.h"
30
31 ret_t
32 cherokee_limiter_init (cherokee_limiter_t *limiter)
33 {
34 INIT_LIST_HEAD (&limiter->conns);
35 limiter->conns_num = 0;
36
37 return ret_ok;
38 }
39
40
41 ret_t
42 cherokee_limiter_mrproper (cherokee_limiter_t *limiter)
43 {
44 cherokee_list_t *i, *tmp;
45
46 list_for_each_safe (i, tmp, &limiter->conns) {
47 cherokee_connection_free (CONN(i));
48 }
49
50 return ret_ok;
51 }
52
53
54 ret_t
55 cherokee_limiter_add_conn (cherokee_limiter_t *limiter,
56 void *conn)
57 {
58 cherokee_list_t *i;
59 cherokee_list_t *prev;
60
61 /* Enlist the connection. Shorted insert by unblocking order
62 */
63 prev = &limiter->conns;
64 list_for_each (i, &limiter->conns) {
65 if (CONN(i)->limit_blocked_until > CONN(conn)->limit_blocked_until)
66 break;
67
68 prev = i;
69 }
70
71 limiter->conns_num++;
72 cherokee_list_add (LIST(conn), prev);
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
73
0f8d506 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2790 5dc97367-9…
alobbs authored Jan 27, 2009
74 return ret_ok;
75 }
76
77
30ae9d5 @alobbs cherokee_limiter_get_time_limit(): Fixes the function prototype.
alobbs authored Aug 19, 2009
78 cherokee_msec_t
0f8d506 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2790 5dc97367-9…
alobbs authored Jan 27, 2009
79 cherokee_limiter_get_time_limit (cherokee_limiter_t *limiter,
80 cherokee_msec_t fdwatch_msecs)
81 {
30ae9d5 @alobbs cherokee_limiter_get_time_limit(): Fixes the function prototype.
alobbs authored Aug 19, 2009
82 long long time_delta;
0f8d506 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2790 5dc97367-9…
alobbs authored Jan 27, 2009
83 cherokee_connection_t *conn;
84
1be579e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3163 5dc97367-9…
alobbs authored Apr 23, 2009
85 /* Shortcut
0f8d506 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2790 5dc97367-9…
alobbs authored Jan 27, 2009
86 */
1be579e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3163 5dc97367-9…
alobbs authored Apr 23, 2009
87 if ((fdwatch_msecs == 0) ||
88 (limiter->conns_num == 0))
89 {
0f8d506 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2790 5dc97367-9…
alobbs authored Jan 27, 2009
90 return fdwatch_msecs;
1be579e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3163 5dc97367-9…
alobbs authored Apr 23, 2009
91 }
0f8d506 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2790 5dc97367-9…
alobbs authored Jan 27, 2009
92
1be579e @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@3163 5dc97367-9…
alobbs authored Apr 23, 2009
93 /* Pick the first connection
94 */
0f8d506 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2790 5dc97367-9…
alobbs authored Jan 27, 2009
95 conn = CONN(limiter->conns.next);
96
97 /* Return the delta time of the first connection (the
98 * connection that will be enabled sooner)
99 */
100 time_delta = conn->limit_blocked_until - cherokee_bogonow_msec;
30ae9d5 @alobbs cherokee_limiter_get_time_limit(): Fixes the function prototype.
alobbs authored Aug 19, 2009
101 if (unlikely (time_delta <= 0)) {
0f8d506 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2790 5dc97367-9…
alobbs authored Jan 27, 2009
102 return 0;
30ae9d5 @alobbs cherokee_limiter_get_time_limit(): Fixes the function prototype.
alobbs authored Aug 19, 2009
103 }
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
104
30ae9d5 @alobbs cherokee_limiter_get_time_limit(): Fixes the function prototype.
alobbs authored Aug 19, 2009
105 /* Check as 'signed long long' */
106 return MIN(time_delta, (long long)fdwatch_msecs);
0f8d506 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2790 5dc97367-9…
alobbs authored Jan 27, 2009
107 }
108
109
110 ret_t
111 cherokee_limiter_reactive (cherokee_limiter_t *limiter,
112 void *thread)
113 {
114 cherokee_list_t *i, *tmp;
115
116 list_for_each_safe (i, tmp, &limiter->conns) {
117 /* Check whether the limit has expired
118 */
119 if (CONN(i)->limit_blocked_until > cherokee_bogonow_msec)
120 break;
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored Dec 13, 2009
121
0f8d506 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2790 5dc97367-9…
alobbs authored Jan 27, 2009
122 /* Re-active the connection
123 */
124 limiter->conns_num--;
125 cherokee_list_del(i);
126
127 CONN(i)->limit_blocked_until = 0;
128 cherokee_thread_inject_active_connection (thread, CONN(i));
129 }
130
131 return ret_ok;
132 }
Something went wrong with that request. Please try again.