-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
Copy pathlibevent.patch
193 lines (175 loc) · 5.71 KB
/
libevent.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 676727f1..833fbf70 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -200,7 +200,7 @@ endif()
if (("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") OR (${CLANG}))
set(GNUC 1)
endif()
-if (("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") OR (${CLANG}))
+if (("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") OR ("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC"))
set(MSVC 1)
endif()
diff --git a/buffer.c b/buffer.c
index 3524b350..e5d97458 100644
--- a/buffer.c
+++ b/buffer.c
@@ -2204,9 +2204,9 @@ evbuffer_expand(struct evbuffer *buf, size_t datlen)
#define IOV_LEN_TYPE unsigned long
#endif
#endif
-#define NUM_READ_IOVEC 4
+#define NUM_READ_IOVEC 8
-#define EVBUFFER_MAX_READ 4096
+#define EVBUFFER_MAX_READ (128 * 1024)
/** Helper function to figure out which space to use for reading data into
an evbuffer. Internal use only.
diff --git a/bufferevent_async.c b/bufferevent_async.c
index 40c7c5e8..c1624878 100644
--- a/bufferevent_async.c
+++ b/bufferevent_async.c
@@ -275,7 +275,7 @@ bev_async_consider_reading(struct bufferevent_async *beva)
}
at_most = read_high - cur_size;
} else {
- at_most = 16384; /* FIXME totally magic. */
+ at_most = 128 * 1024; /* FIXME totally magic. */
}
/* XXXX This over-commits. */
diff --git a/bufferevent_ratelim.c b/bufferevent_ratelim.c
index 25874968..9bc2b577 100644
--- a/bufferevent_ratelim.c
+++ b/bufferevent_ratelim.c
@@ -179,7 +179,7 @@ ev_token_bucket_cfg_free(struct ev_token_bucket_cfg *cfg)
}
/* Default values for max_single_read & max_single_write variables. */
-#define MAX_SINGLE_READ_DEFAULT 16384
+#define MAX_SINGLE_READ_DEFAULT (128 * 1024)
#define MAX_SINGLE_WRITE_DEFAULT 16384
#define LOCK_GROUP(g) EVLOCK_LOCK((g)->lock, 0)
diff --git a/http-internal.h b/http-internal.h
index feaf436d..9f9b5ab5 100644
--- a/http-internal.h
+++ b/http-internal.h
@@ -167,6 +167,8 @@ struct evhttp {
void *gencbarg;
struct bufferevent* (*bevcb)(struct event_base *, void *);
void *bevcbarg;
+ int (*newreqcb)(struct evhttp_request *req, void *);
+ void *newreqcbarg;
struct event_base *base;
};
diff --git a/http.c b/http.c
index 04f089bc..53951cba 100644
--- a/http.c
+++ b/http.c
@@ -3975,6 +3975,14 @@ evhttp_set_bevcb(struct evhttp *http,
http->bevcbarg = cbarg;
}
+void
+evhttp_set_newreqcb(struct evhttp *http,
+ int (*cb)(struct evhttp_request *, void *), void *cbarg)
+{
+ http->newreqcb = cb;
+ http->newreqcbarg = cbarg;
+}
+
/*
* Request related functions
*/
@@ -4036,6 +4044,8 @@ evhttp_request_free(struct evhttp_request *req)
req->flags |= EVHTTP_REQ_NEEDS_FREE;
return;
}
+ if (req->on_free_cb)
+ (*req->on_free_cb)(req, req->on_free_cb_arg);
if (req->remote_host != NULL)
mm_free(req->remote_host);
@@ -4116,6 +4126,15 @@ evhttp_request_set_on_complete_cb(struct evhttp_request *req,
req->on_complete_cb_arg = cb_arg;
}
+void
+evhttp_request_set_on_free_cb(struct evhttp_request *req,
+ void (*cb)(struct evhttp_request *, void *), void *cb_arg)
+{
+ req->on_free_cb = cb;
+ req->on_free_cb_arg = cb_arg;
+}
+
+
/*
* Allows for inspection of the request URI
*/
@@ -4307,10 +4326,15 @@ evhttp_associate_new_request_with_connection(struct evhttp_connection *evcon)
*/
req->userdone = 1;
- TAILQ_INSERT_TAIL(&evcon->requests, req, next);
-
req->kind = EVHTTP_REQUEST;
+ if (http->newreqcb && http->newreqcb(req, http->newreqcbarg) == -1) {
+ evhttp_request_free(req);
+ return (-1);
+ }
+
+ TAILQ_INSERT_TAIL(&evcon->requests, req, next);
+
evhttp_start_read_(evcon);
diff --git a/include/event2/http.h b/include/event2/http.h
index 2a41303e..e80bab9a 100644
--- a/include/event2/http.h
+++ b/include/event2/http.h
@@ -298,6 +298,20 @@ EVENT2_EXPORT_SYMBOL
void evhttp_set_bevcb(struct evhttp *http,
struct bufferevent *(*cb)(struct event_base *, void *), void *arg);
+/**
+ Set a callback which allows the user to note or throttle incoming requests.
+ The requests are not populated with HTTP level information. They
+ are just associated to a connection.
+ If the callback returns -1, the associated connection is terminated
+ and the request is closed.
+ @param http the evhttp server object for which to set the callback
+ @param cb the callback to invoke for incoming connections
+ @param arg an context argument for the callback
+ */
+EVENT2_EXPORT_SYMBOL
+void evhttp_set_newreqcb(struct evhttp *http,
+ int (*cb)(struct evhttp_request*, void *), void *arg);
+
/**
Adds a virtual host to the http server.
@@ -624,6 +638,20 @@ EVENT2_EXPORT_SYMBOL
void evhttp_request_set_on_complete_cb(struct evhttp_request *req,
void (*cb)(struct evhttp_request *, void *), void *cb_arg);
+/**
+ * Set a callback to be called on request free.
+ *
+ * The callback function will be called just before the evhttp_request object
+ * is destroyed.
+ *
+ * @param req a request object
+ * @param cb callback function that will be called before request free
+ * @param cb_arg an additional context argument for the callback
+ */
+EVENT2_EXPORT_SYMBOL
+void evhttp_request_set_on_free_cb(struct evhttp_request *req,
+ void (*cb)(struct evhttp_request *, void *), void *cb_arg);
+
/** Frees the request object and removes associated events. */
EVENT2_EXPORT_SYMBOL
void evhttp_request_free(struct evhttp_request *req);
diff --git a/include/event2/http_struct.h b/include/event2/http_struct.h
index 4bf5b1ff..0762cabd 100644
--- a/include/event2/http_struct.h
+++ b/include/event2/http_struct.h
@@ -142,6 +142,12 @@ struct {
*/
void (*on_complete_cb)(struct evhttp_request *, void *);
void *on_complete_cb_arg;
+
+ /*
+ * Free callback - called just before the request is freed.
+ */
+ void (*on_free_cb)(struct evhttp_request *, void *);
+ void *on_free_cb_arg;
};
#ifdef __cplusplus