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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
|
? build.log
? build.err
? .inslog2
? include/util_filter.h
? lib/apr/build.log
? lib/apr/build.err
? lib/apr/shmem/config.cache
? main/util_filter.c
Index: configure.in
===================================================================
RCS file: /home/cvs/apache-2.0/src/configure.in,v
retrieving revision 1.72
diff -u -d -b -w -u -r1.72 configure.in
--- configure.in 2000/07/01 14:08:21 1.72
+++ configure.in 2000/07/12 23:26:38
@@ -78,7 +78,7 @@
netdb.h \
pwd.h \
grp.h \
-strings.h
+strings.h \
)
AC_HEADER_SYS_WAIT
Index: ap/Makefile.in
===================================================================
RCS file: /home/cvs/apache-2.0/src/ap/Makefile.in,v
retrieving revision 1.4
diff -u -d -b -w -u -r1.4 Makefile.in
--- ap/Makefile.in 2000/06/12 20:41:13 1.4
+++ ap/Makefile.in 2000/07/12 23:26:38
@@ -1,5 +1,5 @@
LTLIBRARY_NAME = libap.la
-LTLIBRARY_SOURCES = ap_cache.c ap_base64.c ap_sha1.c ap_buf.c ap_hooks.c
+LTLIBRARY_SOURCES = ap_cache.c ap_base64.c ap_sha1.c ap_hooks.c
include $(top_srcdir)/build/ltlib.mk
Index: include/ap_iol.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/include/ap_iol.h,v
retrieving revision 1.19
diff -u -d -b -w -u -r1.19 ap_iol.h
--- include/ap_iol.h 2000/05/29 04:22:02 1.19
+++ include/ap_iol.h 2000/07/12 23:26:39
@@ -58,6 +58,7 @@
#define AP_IOL_H
#include "apr_general.h" /* For ap_s?size_t */
+#include "apr_network_io.h" /* For ap_hdtr_t */
#include "apr_errno.h" /* For ap_status_t and the APR_errnos */
typedef struct ap_iol ap_iol;
Index: include/buff.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/include/buff.h,v
retrieving revision 1.30
diff -u -d -b -w -u -r1.30 buff.h
--- include/buff.h 2000/06/29 14:34:24 1.30
+++ include/buff.h 2000/07/12 23:26:39
@@ -63,7 +63,7 @@
extern "C" {
#endif
-#ifdef HAVE_STDARG_H
+#ifdef APR_HAVE_STDARG_H
#include <stdarg.h>
#endif
#include "ap.h"
Index: include/http_protocol.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/include/http_protocol.h,v
retrieving revision 1.19
diff -u -d -b -w -u -r1.19 http_protocol.h
--- include/http_protocol.h 2000/07/11 03:48:17 1.19
+++ include/http_protocol.h 2000/07/12 23:26:39
@@ -89,8 +89,15 @@
API_EXPORT(void) ap_basic_http_header(request_rec *r);
/* Send the Status-Line and header fields for HTTP response */
+API_EXPORT(void) ap_send_http_header_real(request_rec *l);
-API_EXPORT(void) ap_send_http_header(request_rec *l);
+/* this is the old function that used to send headers to the network. We
+ * don't want handlers using it anymore, becuase the filter that actually
+ * writes to the network has to send the headers. I am defining it to be
+ * NULL, because everybody seems to want to not break existing modules.
+ * The new function ap_send_http_header_real() actually sends the data.
+ */
+#define ap_send_http_header(l) /* No-op*/
/* Send the response to special method requests */
Index: include/httpd.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/include/httpd.h,v
retrieving revision 1.64
diff -u -d -b -w -u -r1.64 httpd.h
--- include/httpd.h 2000/06/30 21:18:13 1.64
+++ include/httpd.h 2000/07/12 23:26:39
@@ -596,6 +596,11 @@
* pointer back to the main request.
*/
+ ap_array_header_t *filters; /* The array of filters to call */
+ int headers_sent; /* Have we sent the headers for this request
+ * yet.
+ */
+
/* Info about the request itself... we begin with stuff that only
* protocol.c should ever touch...
*/
Index: main/Makefile.in
===================================================================
RCS file: /home/cvs/apache-2.0/src/main/Makefile.in,v
retrieving revision 1.16
diff -u -d -b -w -u -r1.16 Makefile.in
--- main/Makefile.in 2000/07/01 14:14:15 1.16
+++ main/Makefile.in 2000/07/12 23:26:48
@@ -8,7 +8,7 @@
http_protocol.c http_request.c http_vhost.c util.c util_date.c \
util_script.c util_uri.c util_md5.c util_cfgtree.c util_ebcdic.c \
rfc1413.c http_connection.c iol_file.c iol_socket.c listen.c \
- mpm_common.c util_charset.c util_debug.c util_xml.c
+ mpm_common.c util_charset.c util_debug.c util_xml.c util_filter.c
include $(top_srcdir)/build/ltlib.mk
Index: main/http_core.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/main/http_core.c,v
retrieving revision 1.88
diff -u -d -b -w -u -r1.88 http_core.c
--- main/http_core.c 2000/07/11 03:48:18 1.88
+++ main/http_core.c 2000/07/12 23:26:48
@@ -71,6 +71,8 @@
#include "util_md5.h"
#include "apr_fnmatch.h"
#include "http_connection.h"
+#include "apr_buf.h"
+#include "util_filter.h"
#include "util_ebcdic.h"
#include "mpm.h"
#ifdef HAVE_NETDB_H
@@ -86,6 +88,10 @@
#include <strings.h>
#endif
+/* Make sure we don't write less than 4096 bytes at any one time.
+ */
+#define MIN_SIZE_TO_WRITE 4096
+
/* Allow Apache to use ap_mmap */
#ifdef USE_MMAP_FILES
#include "apr_mmap.h"
@@ -2872,6 +2878,51 @@
return OK;
}
+/* Default filter. This filter should almost always be used. It's only job
+ * is to send the headers if they haven't already been sent, and then send
+ * the actual data. To send the data, we create an iovec out of the bucket
+ * brigade and then call the iol's writev function. On platforms that don't
+ * have writev, we have the problem of creating a lot of potentially small
+ * packets that we are sending to the network.
+ *
+ * This can be solved later by making the buckets buffer everything into a
+ * single memory block that can be written using write (on those systems
+ * without writev only !)
+ */
+static int core_filter(request_rec *r, ap_filter_t *f, ap_bucket_brigade *b)
+{
+ ap_ssize_t bytes_sent;
+ ap_bucket_list *dptr;
+ int len = 0;
+
+ if (!r->headers_sent) {
+ ap_send_http_header_real(r);
+ r->headers_sent = 1;
+ }
+
+ /* At this point we need to discover if there was any data saved from
+ * the last call to core_filter.
+ */
+ b = ap_get_saved_data(r, f, &b);
+
+ /* It is very obvious that we need to make sure it makes sense to send data
+ * out at this point.
+ */
+ dptr = b->head;
+ while (dptr) {
+ len += ap_get_bucket_len(dptr->bucket);
+ dptr = dptr->next;
+ }
+ if (len < MIN_SIZE_TO_WRITE && b->tail->bucket->color != AP_BUCKET_eos) {
+ ap_save_data_to_filter(r, f, b);
+ return 0;
+ }
+ else {
+ ap_bucket_brigade_to_iol(&bytes_sent, b, r->connection->client->iol);
+ return bytes_sent;
+ }
+}
+
static const handler_rec core_handlers[] = {
{ "*/*", default_handler },
{ "default-handler", default_handler },
@@ -2894,6 +2945,11 @@
static unsigned short core_port(const request_rec *r)
{ return DEFAULT_HTTP_PORT; }
+static void core_register_filter(request_rec *r)
+{
+ ap_hook_filter(core_filter, r, NULL, NULL, AP_HOOK_TRANSPORT_LAST);
+}
+
static void register_hooks(void)
{
ap_hook_post_config(core_post_config,NULL,NULL,AP_HOOK_REALLY_FIRST);
@@ -2906,6 +2962,8 @@
/* FIXME: I suspect we can eliminate the need for these - Ben */
ap_hook_type_checker(do_nothing,NULL,NULL,AP_HOOK_REALLY_LAST);
ap_hook_access_checker(do_nothing,NULL,NULL,AP_HOOK_REALLY_LAST);
+
+ ap_hook_insert_filter(core_register_filter, NULL, NULL, AP_HOOK_MIDDLE);
}
API_VAR_EXPORT module core_module = {
Index: main/http_protocol.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/main/http_protocol.c,v
retrieving revision 1.95
diff -u -d -b -w -u -r1.95 http_protocol.c
--- main/http_protocol.c 2000/07/11 03:48:18 1.95
+++ main/http_protocol.c 2000/07/12 23:26:49
@@ -64,6 +64,8 @@
*/
#define CORE_PRIVATE
+#include "apr_buf.h"
+#include "util_filter.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
@@ -1720,7 +1722,7 @@
}
}
-API_EXPORT(void) ap_send_http_header(request_rec *r)
+API_EXPORT(void) ap_send_http_header_real(request_rec *r)
{
int i;
const long int zero = 0L;
@@ -2443,15 +2445,23 @@
size_t length)
{
size_t total_bytes_sent = 0;
- int n;
- ap_ssize_t w;
- char *addr;
+ ap_bucket_brigade *bb = NULL;
+ ap_bucket *b = NULL;
+ ap_filter_t *f;
+
+ /* if you are using the older API's, then Apache will initiate the
+ * filtering for you.
+ */
+ f = ap_init_filter(r->pool);
if (length == 0)
return 0;
-
length += offset;
+/* We can remove all of the MMAP_SEGMENT_SIZE stuff from Apache, because
+ * it is an optimization to be used for sending data. Since we are using
+ * bucket-brigades we need to move this optimization down to the bucket
+ * brigade stuff, but that can wait for a day or two.
while (!r->connection->aborted && offset < length) {
if (length - offset > MMAP_SEGMENT_SIZE) {
n = MMAP_SEGMENT_SIZE;
@@ -2467,76 +2477,142 @@
total_bytes_sent += w;
offset += w;
}
+ */
- SET_BYTES_SENT(r);
+ /* This is far too complex for a final API, but it is an okay
+ * start. To finish this off, we will need a very clean API
+ * that does all of this for us.
+ */
+ bb = ap_bucket_brigade_create(r->pool);
+ bb->head = bb->tail = ap_bucket_list_create();
+ ap_bucket_list_init(bb->head);
+ b = ap_bucket_new(AP_BUCKET_mmap);
+ ap_mmap_bucket_insert((ap_bucket_mmap *)b->data, mm);
+ bb->head->bucket = b;
+ total_bytes_sent = ap_pass_brigade(r, f, bb);
+
return total_bytes_sent;
}
#endif /* USE_MMAP_FILES */
API_EXPORT(int) ap_rputc(int c, request_rec *r)
{
+ ap_bucket_brigade *bb = NULL;
+ ap_bucket *b = NULL;
+ ap_ssize_t written;
+ ap_filter_t *f;
+
if (r->connection->aborted)
return EOF;
- if (ap_bputc(c, r->connection->client) < 0) {
- check_first_conn_error(r, "rputc", 0);
- return EOF;
- }
- SET_BYTES_SENT(r);
+ /* if you are using the older API's, then Apache will initiate the
+ * filtering for you.
+ */
+ f = ap_init_filter(r->pool);
+
+ /* This is far too complex for a final API, but it is an okay
+ * start. To finish this off, we will need a very clean API
+ * that does all of this for us.
+ */
+ bb = ap_bucket_brigade_create(r->pool);
+ bb->head = bb->tail = ap_bucket_list_create();
+ ap_bucket_list_init(bb->head);
+ b = ap_bucket_new(AP_BUCKET_rwmem);
+ ap_rwmem_write(b->data, &c, 1, &written);
+ bb->head->bucket = b;
+ ap_pass_brigade(r, f, bb);
+
return c;
}
API_EXPORT(int) ap_rputs(const char *str, request_rec *r)
{
- int rcode;
+ ap_bucket_brigade *bb = NULL;
+ ap_bucket *b = NULL;
+ ap_ssize_t written;
+ ap_filter_t *f;
if (r->connection->aborted)
return EOF;
- rcode = ap_bputs(str, r->connection->client);
- if (rcode < 0) {
- check_first_conn_error(r, "rputs", 0);
- return EOF;
- }
- SET_BYTES_SENT(r);
- return rcode;
+ /* if you are using the older API's, then Apache will initiate the
+ * filtering for you.
+ */
+ f = ap_init_filter(r->pool);
+
+ /* This is far too complex for a final API, but it is an okay
+ * start. To finish this off, we will need a very clean API
+ * that does all of this for us.
+ */
+ bb = ap_bucket_brigade_create(r->pool);
+ bb->head = bb->tail = ap_bucket_list_create();
+ ap_bucket_list_init(bb->head);
+ b = ap_bucket_new(AP_BUCKET_rwmem);
+ ap_rwmem_write(b->data, str, strlen(str), &written);
+ bb->head->bucket = b;
+ ap_pass_brigade(r, f, bb);
+
+ return written;
}
API_EXPORT(int) ap_rwrite(const void *buf, int nbyte, request_rec *r)
{
- ap_ssize_t n;
- ap_status_t rv;
+ ap_bucket_brigade *bb = NULL;
+ ap_bucket *b = NULL;
+ ap_ssize_t written;
+ ap_filter_t *f;
if (r->connection->aborted)
return EOF;
- /* ### should loop to avoid partial writes */
- rv = ap_bwrite(r->connection->client, buf, nbyte, &n);
- if (rv != APR_SUCCESS) {
- check_first_conn_error(r, "rwrite", rv);
- return EOF;
- }
- SET_BYTES_SENT(r);
- return n;
+ /* if you are using the older API's, then Apache will initiate the
+ * filtering for you.
+ */
+ f = ap_init_filter(r->pool);
+
+ /* This is far too complex for a final API, but it is an okay
+ * start. To finish this off, we will need a very clean API
+ * that does all of this for us.
+ */
+ bb = ap_bucket_brigade_create(r->pool);
+ bb->head = bb->tail = ap_bucket_list_create();
+ ap_bucket_list_init(bb->head);
+ b = ap_bucket_new(AP_BUCKET_rwmem);
+ ap_rwmem_write(b->data, buf, nbyte, &written);
+ bb->head->bucket = b;
+ ap_pass_brigade(r, f, bb);
+ return written;
}
API_EXPORT(int) ap_vrprintf(request_rec *r, const char *fmt, va_list va)
{
- int n;
+ ap_bucket_brigade *bb = NULL;
+ ap_ssize_t written;
+ ap_filter_t *f;
if (r->connection->aborted)
return EOF;
- n = ap_vbprintf(r->connection->client, fmt, va);
+ /* if you are using the older API's, then Apache will initiate the
+ * filtering for you.
+ */
+ f = ap_init_filter(r->pool);
- if (n < 0) {
- check_first_conn_error(r, "vrprintf", 0);
- return EOF;
- }
- SET_BYTES_SENT(r);
- return n;
+ /* This is far too complex for a final API, but it is an okay
+ * start. To finish this off, we will need a very clean API
+ * that does all of this for us.
+ */
+ bb = ap_bucket_brigade_create(r->pool);
+ bb->head = bb->tail = ap_bucket_list_create();
+ ap_bucket_list_init(bb->head);
+ written = ap_brigade_vprintf(bb, fmt, va);
+ ap_pass_brigade(r, f, bb);
+ return written;
}
+/* TODO: Make ap pa_bucket_vprintf that printfs directly into a
+ * bucket.
+ */
API_EXPORT_NONSTD(int) ap_rprintf(request_rec *r, const char *fmt, ...)
{
va_list va;
@@ -2546,46 +2622,62 @@
return EOF;
va_start(va, fmt);
- n = ap_vbprintf(r->connection->client, fmt, va);
+ n = ap_vrprintf(r, fmt, va);
va_end(va);
- if (n < 0) {
- check_first_conn_error(r, "rprintf", 0);
- return EOF;
- }
- SET_BYTES_SENT(r);
return n;
}
API_EXPORT_NONSTD(int) ap_rvputs(request_rec *r, ...)
{
+ ap_bucket_brigade *bb = NULL;
+ ap_ssize_t written;
+ ap_filter_t *f;
va_list va;
- int n;
if (r->connection->aborted)
return EOF;
+ /* if you are using the older API's, then Apache will initiate the
+ * filtering for you.
+ */
+ f = ap_init_filter(r->pool);
+
+ /* This is far too complex for a final API, but it is an okay
+ * start. To finish this off, we will need a very clean API
+ * that does all of this for us.
+ */
+ bb = ap_bucket_brigade_create(r->pool);
+ bb->head = bb->tail = ap_bucket_list_create();
+ ap_bucket_list_init(bb->head);
va_start(va, r);
- n = ap_vbputstrs(r->connection->client, va);
+ written = ap_brigade_vputstrs(bb, va);
va_end(va);
-
- if (n < 0) {
- check_first_conn_error(r, "rvputs", 0);
- return EOF;
- }
-
- SET_BYTES_SENT(r);
- return n;
+ ap_pass_brigade(r, f, bb);
+ return written;
}
API_EXPORT(int) ap_rflush(request_rec *r)
{
- ap_status_t rv;
+ ap_bucket_brigade *bb;
+ ap_bucket *b;
+ ap_filter_t *f;
- if ((rv = ap_bflush(r->connection->client)) != APR_SUCCESS) {
- check_first_conn_error(r, "rflush", rv);
- return EOF;
- }
+ /* if you are using the older API's, then Apache will initiate the
+ * filtering for you.
+ */
+ f = ap_init_filter(r->pool);
+
+ /* This is far too complex for a final API, but it is an okay
+ * start. To finish this off, we will need a very clean API
+ * that does all of this for us.
+ */
+ bb = ap_bucket_brigade_create(r->pool);
+ bb->head = bb->tail = ap_bucket_list_create();
+ ap_bucket_list_init(bb->head);
+ b = ap_bucket_new(AP_BUCKET_eos);
+ bb->head->bucket = b;
+ ap_pass_brigade(r, f, bb);
return 0;
}
Index: main/http_request.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/main/http_request.c,v
retrieving revision 1.35
diff -u -d -b -w -u -r1.35 http_request.c
--- main/http_request.c 2000/06/24 17:33:57 1.35
+++ main/http_request.c 2000/07/12 23:26:49
@@ -1263,6 +1263,12 @@
return;
}
+ /* We need to flush the data out at this point. We probably only want to
+ * do this on the main request, but this is fine for an initial patch.
+ * Once we look into this more, we won't flush sub-requests.
+ */
+ ap_rflush(r);
+
/* Take care of little things that need to happen when we're done */
ap_finalize_request_protocol(r);
}
Index: modules/mpm/config.m4
===================================================================
RCS file: /home/cvs/apache-2.0/src/modules/mpm/config.m4,v
retrieving revision 1.23
diff -u -d -b -w -u -r1.23 config.m4
--- modules/mpm/config.m4 2000/07/11 19:00:16 1.23
+++ modules/mpm/config.m4 2000/07/12 23:26:51
@@ -3,7 +3,6 @@
[ --with-mpm=MPM Choose the process model for Apache to use.
MPM={dexter,mpmt_beos,mpmt_pthread,prefork,spmt_os2}],[
APACHE_MPM=$withval
- mpm_explicit="yes"
],[
APACHE_MPM=mpmt_pthread
PLAT=`$ac_config_guess`
@@ -14,7 +13,6 @@
*os2_emx*)
APACHE_MPM=spmt_os2;;
esac
- mpm_explicit="no"
])
AC_MSG_RESULT($APACHE_MPM)
@@ -41,10 +39,11 @@
MPM_DIR=modules/mpm/$MPM_NAME
MPM_LIB=$MPM_DIR/lib${MPM_NAME}.la
-if test "$mpm_explicit" = "no"; then
if test "$MPM_NAME" = "prefork" ; then
MPM_NAME="prefork"
MPM_FAKE_NAME=prefork.c
+ ln -s mpmt.c modules/mpm/mpmt/prefork.c
+
EXTRA_CFLAGS="$EXTRA_CFLAGS -DPREFORK"
ac_cv_enable_threads="no"
@@ -78,7 +77,6 @@
MPM_DIR=modules/mpm/$MPM_NAME
MPM_LIB=$MPM_DIR/lib${MPM_NAME}.la
fi
-fi
APACHE_SUBST(MPM_NAME)
APACHE_SUBST(MPM_FAKE_NAME)
|