Apache HTTPD
h2_session.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <assert.h>
18#include <stddef.h>
19#include <apr_thread_cond.h>
20#include <apr_atomic.h>
21#include <apr_base64.h>
22#include <apr_strings.h>
23
24#include <ap_mpm.h>
25
26#include <httpd.h>
27#include <http_core.h>
28#include <http_config.h>
29#include <http_log.h>
30#include <http_protocol.h>
31#include <scoreboard.h>
32
33#include <mpm_common.h>
34
35#if APR_HAVE_UNISTD_H
36#include <unistd.h> /* for getpid() */
37#endif
38
39#include "h2_private.h"
40#include "h2.h"
41#include "h2_bucket_beam.h"
42#include "h2_bucket_eos.h"
43#include "h2_config.h"
44#include "h2_conn_ctx.h"
45#include "h2_protocol.h"
46#include "h2_mplx.h"
47#include "h2_push.h"
48#include "h2_request.h"
49#include "h2_headers.h"
50#include "h2_stream.h"
51#include "h2_c2.h"
52#include "h2_session.h"
53#include "h2_util.h"
54#include "h2_version.h"
55#include "h2_workers.h"
56
57
58static void transit(h2_session *session, const char *action,
60
61static void on_stream_state_enter(void *ctx, h2_stream *stream);
62static void on_stream_state_event(void *ctx, h2_stream *stream, h2_stream_event_t ev);
63static void on_stream_event(void *ctx, h2_stream *stream, h2_stream_event_t ev);
64
66{
67 if (rv == APR_SUCCESS) {
68 return NGHTTP2_NO_ERROR;
69 }
70 else if (APR_STATUS_IS_EAGAIN(rv)) {
72 }
73 else if (APR_STATUS_IS_EOF(rv)) {
74 return NGHTTP2_ERR_EOF;
75 }
76 return NGHTTP2_ERR_PROTO;
77}
78
79static h2_stream *get_stream(h2_session *session, int stream_id)
80{
81 return nghttp2_session_get_stream_user_data(session->ngh2, stream_id);
82}
83
85 int err, const char *msg)
86{
87 h2_session_dispatch_event(session, ev, err, msg);
88}
89
90static int rst_unprocessed_stream(h2_stream *stream, void *ctx)
91{
93 && (H2_STREAM_CLIENT_INITIATED(stream->id)?
94 (!stream->session->local.accepting
95 && stream->id > stream->session->local.accepted_max)
96 :
97 (!stream->session->remote.accepting
98 && stream->id > stream->session->remote.accepted_max))
99 );
100 if (unprocessed) {
102 return 0;
103 }
104 return 1;
105}
106
108{
110}
111
112static h2_stream *h2_session_open_stream(h2_session *session, int stream_id,
113 int initiated_on)
114{
115 h2_stream * stream;
117
118 apr_pool_create(&stream_pool, session->pool);
119 apr_pool_tag(stream_pool, "h2_stream");
120
121 stream = h2_stream_create(stream_id, stream_pool, session,
122 session->monitor, initiated_on);
123 if (stream) {
124 nghttp2_session_set_stream_user_data(session->ngh2, stream_id, stream);
125 }
126 return stream;
127}
128
136static int spri_cmp(int sid1, nghttp2_stream *s1,
137 int sid2, nghttp2_stream *s2, h2_session *session)
138{
140
143
144 if (p1 == p2) {
145 int32_t w1, w2;
146
149 return w2 - w1;
150 }
151 else if (!p1) {
152 /* stream 1 closer to root */
153 return -1;
154 }
155 else if (!p2) {
156 /* stream 2 closer to root */
157 return 1;
158 }
159 return spri_cmp(sid1, p1, sid2, p2, session);
160}
161
162static int stream_pri_cmp(int sid1, int sid2, void *ctx)
163{
164 h2_session *session = ctx;
166
169
170 if (s1 == s2) {
171 return 0;
172 }
173 else if (!s1) {
174 return 1;
175 }
176 else if (!s2) {
177 return -1;
178 }
179 return spri_cmp(sid1, s1, sid2, s2, session);
180}
181
182/*
183 * Callback when nghttp2 wants to send bytes back to the client.
184 */
186 const uint8_t *data, size_t length,
187 int flags, void *userp)
188{
189 h2_session *session = (h2_session *)userp;
190 apr_status_t rv;
191 (void)ngh2;
192 (void)flags;
193
194 if (h2_c1_io_needs_flush(&session->io)) {
196 }
197
198 rv = h2_c1_io_add_data(&session->io, (const char *)data, length);
199 if (APR_SUCCESS == rv) {
200 return length;
201 }
202 else if (APR_STATUS_IS_EAGAIN(rv)) {
204 }
205 else {
206 ap_log_cerror(APLOG_MARK, APLOG_DEBUG, rv, session->c1,
207 APLOGNO(03062) "h2_session: send error");
209 }
210}
211
213 const nghttp2_frame *frame,
214 int error, void *userp)
215{
216 h2_session *session = (h2_session *)userp;
217 (void)ngh2;
218
219 if (APLOGcdebug(session->c1)) {
220 char buffer[256];
221
222 h2_util_frame_print(frame, buffer, sizeof(buffer)/sizeof(buffer[0]));
224 H2_SSSN_LOG(APLOGNO(03063), session,
225 "recv invalid FRAME[%s], frames=%ld/%ld (r/s)"),
226 buffer, (long)session->frames_received,
227 (long)session->frames_sent);
228 }
229 return 0;
230}
231
233 int32_t stream_id,
234 const uint8_t *data, size_t len, void *userp)
235{
236 h2_session *session = (h2_session *)userp;
238 h2_stream * stream;
239 int rv = 0;
240
241 stream = get_stream(session, stream_id);
242 if (stream) {
244 H2_SSSN_STRM_MSG(session, stream_id, "write %ld bytes of DATA"),
245 (long)len);
247 }
248 else {
249 ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c1, APLOGNO(03064)
250 H2_SSSN_STRM_MSG(session, stream_id,
251 "on_data_chunk for unknown stream"));
253 }
254
255 if (status != APR_SUCCESS) {
256 /* count this as consumed explicitly as no one will read it */
257 nghttp2_session_consume(session->ngh2, stream_id, len);
258 }
259 return rv;
260}
261
262static int on_stream_close_cb(nghttp2_session *ngh2, int32_t stream_id,
263 uint32_t error_code, void *userp)
264{
265 h2_session *session = (h2_session *)userp;
266 h2_stream *stream;
267
268 (void)ngh2;
269 stream = get_stream(session, stream_id);
270 if (stream) {
271 if (error_code) {
273 H2_STRM_LOG(APLOGNO(03065), stream,
274 "closing with err=%d %s"),
275 (int)error_code, h2_protocol_err_description(error_code));
276 h2_stream_rst(stream, error_code);
277 }
278 }
279 return 0;
280}
281
283 const nghttp2_frame *frame, void *userp)
284{
285 h2_session *session = (h2_session *)userp;
286 h2_stream *s = NULL;
287
288 /* We may see HEADERs at the start of a stream or after all DATA
289 * streams to carry trailers. */
290 (void)ngh2;
291 s = get_stream(session, frame->hd.stream_id);
292 if (s) {
293 /* nop */
294 }
295 else if (session->local.accepting) {
296 s = h2_session_open_stream(userp, frame->hd.stream_id, 0);
297 }
299}
300
302 const uint8_t *name, size_t namelen,
303 const uint8_t *value, size_t valuelen,
305 void *userp)
306{
307 h2_session *session = (h2_session *)userp;
308 h2_stream * stream;
310
311 (void)flags;
312 stream = get_stream(session, frame->hd.stream_id);
313 if (!stream) {
314 ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c1, APLOGNO(02920)
315 H2_SSSN_STRM_MSG(session, frame->hd.stream_id,
316 "on_header unknown stream"));
318 }
319
320 status = h2_stream_add_header(stream, (const char *)name, namelen,
321 (const char *)value, valuelen);
322 if (status != APR_SUCCESS &&
323 (!stream->rtmp ||
325 /* We accept a certain amount of failures in order to reply
326 * with an informative HTTP error response like 413. But if the
327 * client is too wrong, we fail the request a RESET of the stream */
328 stream->request_headers_failed > 100)) {
330 }
331 return 0;
332}
333
340 const nghttp2_frame *frame,
341 void *userp)
342{
343 h2_session *session = (h2_session *)userp;
344 h2_stream *stream;
346
347 stream = frame->hd.stream_id? get_stream(session, frame->hd.stream_id) : NULL;
348 if (APLOGcdebug(session->c1)) {
349 char buffer[256];
350
351 h2_util_frame_print(frame, buffer, sizeof(buffer)/sizeof(buffer[0]));
352 if (stream) {
354 H2_STRM_LOG(APLOGNO(10302), stream,
355 "recv FRAME[%s], frames=%ld/%ld (r/s)"),
356 buffer, (long)session->frames_received,
357 (long)session->frames_sent);
358 }
359 else {
361 H2_SSSN_LOG(APLOGNO(03066), session,
362 "recv FRAME[%s], frames=%ld/%ld (r/s)"),
363 buffer, (long)session->frames_received,
364 (long)session->frames_sent);
365 }
366 }
367
368 ++session->frames_received;
369 switch (frame->hd.type) {
370 case NGHTTP2_HEADERS:
371 /* This can be HEADERS for a new stream, defining the request,
372 * or HEADER may come after DATA at the end of a stream as in
373 * trailers */
374 if (stream) {
375 rv = h2_stream_recv_frame(stream, NGHTTP2_HEADERS, frame->hd.flags,
376 frame->hd.length + H2_FRAME_HDR_LEN);
377 }
378 break;
379 case NGHTTP2_DATA:
380 if (stream) {
382 H2_STRM_LOG(APLOGNO(02923), stream,
383 "DATA, len=%ld, flags=%d"),
384 (long)frame->hd.length, frame->hd.flags);
385 rv = h2_stream_recv_frame(stream, NGHTTP2_DATA, frame->hd.flags,
386 frame->hd.length + H2_FRAME_HDR_LEN);
387 }
388 break;
389 case NGHTTP2_PRIORITY:
390 session->reprioritize = 1;
392 H2_SSSN_STRM_MSG(session, frame->hd.stream_id, "PRIORITY frame "
393 " weight=%d, dependsOn=%d, exclusive=%d"),
394 frame->priority.pri_spec.weight,
395 frame->priority.pri_spec.stream_id,
396 frame->priority.pri_spec.exclusive);
397 break;
400 H2_SSSN_STRM_MSG(session, frame->hd.stream_id,
401 "WINDOW_UPDATE incr=%d"),
402 frame->window_update.window_size_increment);
403 break;
405 ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c1, APLOGNO(03067)
406 H2_SSSN_STRM_MSG(session, frame->hd.stream_id,
407 "RST_STREAM by client, error=%d"),
408 (int)frame->rst_stream.error_code);
409 if (stream) {
410 rv = h2_stream_recv_frame(stream, NGHTTP2_RST_STREAM, frame->hd.flags,
411 frame->hd.length + H2_FRAME_HDR_LEN);
412 }
413 if (stream && stream->initiated_on) {
414 /* A stream reset on a request we sent it. Normal, when the
415 * client does not want it. */
416 ++session->pushes_reset;
417 }
418 else {
419 /* A stream reset on a request it sent us. Could happen in a browser
420 * when the user navigates away or cancels loading - maybe. */
421 h2_mplx_c1_client_rst(session->mplx, frame->hd.stream_id,
422 stream);
423 }
424 ++session->streams_reset;
425 break;
426 case NGHTTP2_GOAWAY:
427 if (frame->goaway.error_code == 0
428 && frame->goaway.last_stream_id == ((1u << 31) - 1)) {
429 /* shutdown notice. Should not come from a client... */
430 session->remote.accepting = 0;
431 }
432 else {
433 session->remote.accepted_max = frame->goaway.last_stream_id;
435 frame->goaway.error_code, NULL);
436 }
437 break;
438 case NGHTTP2_SETTINGS:
440 H2_SSSN_MSG(session, "SETTINGS, len=%ld"), (long)frame->hd.length);
441 break;
442 default:
443 if (APLOGctrace2(session->c1)) {
444 char buffer[256];
445
447 sizeof(buffer)/sizeof(buffer[0]));
449 H2_SSSN_MSG(session, "on_frame_rcv %s"), buffer);
450 }
451 break;
452 }
453
454 if (session->state == H2_SESSION_ST_IDLE) {
455 /* We received a frame, but session is in state IDLE. That means the frame
456 * did not really progress any of the (possibly) open streams. It was a meta
457 * frame, e.g. SETTINGS/WINDOW_UPDATE/unknown/etc.
458 * Remember: IDLE means we cannot send because either there are no streams open or
459 * all open streams are blocked on exhausted WINDOWs for outgoing data.
460 * The more frames we receive that do not change this, the less interested we
461 * become in serving this connection. This is expressed in increasing "idle_delays".
462 * Eventually, the connection will timeout and we'll close it. */
463 session->idle_frames = H2MIN(session->idle_frames + 1, session->frames_received);
465 H2_SSSN_MSG(session, "session has %ld idle frames"),
466 (long)session->idle_frames);
467 if (session->idle_frames > 10) {
468 apr_size_t busy_frames = H2MAX(session->frames_received - session->idle_frames, 1);
469 int idle_ratio = (int)(session->idle_frames / busy_frames);
470 if (idle_ratio > 100) {
472 }
473 else if (idle_ratio > 10) {
474 session->idle_delay = apr_time_from_msec(10);
475 }
476 else if (idle_ratio > 1) {
477 session->idle_delay = apr_time_from_msec(1);
478 }
479 else {
480 session->idle_delay = 0;
481 }
482 }
483 }
484
485 if (APR_SUCCESS != rv) return NGHTTP2_ERR_PROTO;
486 return 0;
487}
488
490
493 const uint8_t *framehd,
494 size_t length,
496 void *userp)
497{
499 h2_session *session = (h2_session *)userp;
500 int stream_id = (int)frame->hd.stream_id;
501 unsigned char padlen;
502 int eos;
503 h2_stream *stream;
504 apr_bucket *b;
506
507 (void)ngh2;
508 (void)source;
509 ap_assert(frame->data.padlen <= (H2_MAX_PADLEN+1));
510 padlen = (unsigned char)frame->data.padlen;
511
512 stream = get_stream(session, stream_id);
513 if (!stream) {
515 APLOGNO(02924)
516 H2_SSSN_STRM_MSG(session, stream_id, "send_data, stream not found"));
518 }
519
521 H2_STRM_MSG(stream, "send_data_cb for %ld bytes"),
522 (long)length);
523
524 status = h2_c1_io_add_data(&session->io, (const char *)framehd, H2_FRAME_HDR_LEN);
525 if (padlen && status == APR_SUCCESS) {
526 --padlen;
527 status = h2_c1_io_add_data(&session->io, (const char *)&padlen, 1);
528 }
529
530 if (status != APR_SUCCESS) {
532 H2_STRM_MSG(stream, "writing frame header"));
534 }
535
536 status = h2_stream_read_to(stream, session->bbtmp, &len, &eos);
537 if (status != APR_SUCCESS) {
539 H2_STRM_MSG(stream, "send_data_cb, reading stream"));
540 apr_brigade_cleanup(session->bbtmp);
542 }
543 else if (len != (apr_off_t)length) {
545 H2_STRM_MSG(stream, "send_data_cb, wanted %ld bytes, "
546 "got %ld from stream"), (long)length, (long)len);
547 apr_brigade_cleanup(session->bbtmp);
549 }
550
551 if (padlen) {
553 session->c1->bucket_alloc);
555 }
556
557 status = h2_c1_io_append(&session->io, session->bbtmp);
558 apr_brigade_cleanup(session->bbtmp);
559
560 if (status == APR_SUCCESS) {
561 stream->out_data_frames++;
562 stream->out_data_octets += length;
564 H2_STRM_MSG(stream, "sent data length=%ld, total=%ld"),
565 (long)length, (long)stream->out_data_octets);
566 return 0;
567 }
568 else {
570 H2_STRM_LOG(APLOGNO(02925), stream, "failed send_data_cb"));
572 }
573}
574
576 const nghttp2_frame *frame,
577 void *user_data)
578{
579 h2_session *session = user_data;
580 h2_stream *stream;
581 int stream_id = frame->hd.stream_id;
582
583 ++session->frames_sent;
584 switch (frame->hd.type) {
586 /* PUSH_PROMISE we report on the promised stream */
587 stream_id = frame->push_promise.promised_stream_id;
588 break;
589 default:
590 break;
591 }
592
593 stream = get_stream(session, stream_id);
594 if (APLOGcdebug(session->c1)) {
595 char buffer[256];
596
597 h2_util_frame_print(frame, buffer, sizeof(buffer)/sizeof(buffer[0]));
598 if (stream) {
600 H2_STRM_LOG(APLOGNO(10303), stream,
601 "sent FRAME[%s], frames=%ld/%ld (r/s)"),
602 buffer, (long)session->frames_received,
603 (long)session->frames_sent);
604 }
605 else {
607 H2_SSSN_LOG(APLOGNO(03068), session,
608 "sent FRAME[%s], frames=%ld/%ld (r/s)"),
609 buffer, (long)session->frames_received,
610 (long)session->frames_sent);
611 }
612 }
613
614 if (stream) {
615 h2_stream_send_frame(stream, frame->hd.type, frame->hd.flags,
616 frame->hd.length + H2_FRAME_HDR_LEN);
617 }
618 return 0;
619}
620
621#ifdef H2_NG2_INVALID_HEADER_CB
623 const nghttp2_frame *frame,
624 const uint8_t *name, size_t namelen,
625 const uint8_t *value, size_t valuelen,
626 uint8_t flags, void *user_data)
627{
628 h2_session *session = user_data;
629 h2_stream *stream;
630
631 ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, session->c1, APLOGNO(03456)
632 H2_SSSN_STRM_MSG(session, frame->hd.stream_id,
633 "invalid header '%.*s: %.*s'"),
634 (int)namelen, name, (int)valuelen, value);
635 stream = get_stream(session, frame->hd.stream_id);
636 if (stream) {
638 }
639 return 0;
640}
641#endif
642
644 const nghttp2_frame *frame,
645 size_t max_payloadlen, void *user_data)
646{
647 h2_session *session = user_data;
648 size_t frame_len = frame->hd.length + H2_FRAME_HDR_LEN; /* the total length without padding */
649 size_t padded_len = frame_len;
650
651 /* Determine # of padding bytes to append to frame. Unless session->padding_always
652 * the number my be capped by the ui.write_size that currently applies.
653 */
654 if (session->padding_max) {
655 int n = ap_random_pick(0, session->padding_max);
657 }
658
659 if (padded_len != frame_len) {
660 if (!session->padding_always && session->io.write_size
661 && (padded_len > session->io.write_size)
662 && (frame_len <= session->io.write_size)) {
663 padded_len = session->io.write_size;
664 }
666 "select padding from [%d, %d]: %d (frame length: 0x%04x, write size: %d)",
668 (int)(padded_len - frame_len), (int)padded_len, (int)session->io.write_size);
670 }
671 return frame->hd.length;
672}
673
674#define NGH2_SET_CALLBACK(callbacks, name, fn)\
675nghttp2_session_callbacks_set_##name##_callback(callbacks, fn)
676
702
703static void update_child_status(h2_session *session, int status,
704 const char *msg, const h2_stream *stream)
705{
706 /* Assume that we also change code/msg when something really happened and
707 * avoid updating the scoreboard in between */
708 if (session->last_status_code != status
709 || session->last_status_msg != msg) {
710 char sbuffer[1024];
711 sbuffer[0] = '\0';
712 if (stream) {
714 ": stream %d, %s %s",
715 stream->id,
716 stream->request? stream->request->method : "",
717 stream->request? stream->request->path : "");
718 }
719 apr_snprintf(session->status, sizeof(session->status),
720 "[%d/%d] %s%s",
721 (int)(session->remote.emitted_count + session->pushes_submitted),
722 (int)session->streams_done,
723 msg? msg : "-", sbuffer);
725 session->c1, session->s);
726 ap_update_child_status_descr(session->c1->sbh, status, session->status);
727 }
728}
729
731{
733
734 ap_assert(session);
735 if (!session->local.accepting) {
736 return APR_SUCCESS;
737 }
738
740 session->local.accepting = 0;
741 status = nghttp2_session_send(session->ngh2);
742 if (status == APR_SUCCESS) {
743 status = h2_c1_io_assure_flushed(&session->io);
744 }
746 H2_SSSN_LOG(APLOGNO(03457), session, "sent shutdown notice"));
747 return status;
748}
749
751 const char *msg, int force_close)
752{
754
755 ap_assert(session);
756 if (session->local.shutdown) {
757 return APR_SUCCESS;
758 }
759
760 if (error && !msg) {
762 msg = "remote close";
763 }
764 }
765
766 if (error || force_close) {
767 /* not a graceful shutdown, we want to leave...
768 * Do not start further streams that are waiting to be scheduled.
769 * Find out the max stream id that we habe been processed or
770 * are still actively working on.
771 * Remove all streams greater than this number without submitting
772 * a RST_STREAM frame, since that should be clear from the GOAWAY
773 * we send. */
774 session->local.accepted_max = h2_mplx_c1_shutdown(session->mplx);
775 session->local.error = error;
776 session->local.error_msg = msg;
777 }
778 else {
779 /* graceful shutdown. we will continue processing all streams
780 * we have, but no longer accept new ones. Report the max stream
781 * we have received and discard all new ones. */
782 }
783
784 session->local.accepting = 0;
785 session->local.shutdown = 1;
786 if (!session->c1->aborted) {
788 session->local.accepted_max,
789 error, (uint8_t*)msg, msg? strlen(msg):0);
790 status = nghttp2_session_send(session->ngh2);
791 if (status == APR_SUCCESS) {
792 status = h2_c1_io_assure_flushed(&session->io);
793 }
795 H2_SSSN_LOG(APLOGNO(03069), session,
796 "sent GOAWAY, err=%d, msg=%s"), error, msg? msg : "");
797 }
799 return status;
800}
801
802static apr_status_t session_cleanup(h2_session *session, const char *trigger)
803{
804 conn_rec *c = session->c1;
806 H2_SSSN_MSG(session, "pool_cleanup"));
807
808 if (session->state != H2_SESSION_ST_DONE
809 && session->state != H2_SESSION_ST_INIT) {
810 /* Not good. The connection is being torn down and we have
811 * not sent a goaway. This is considered a protocol error and
812 * the client has to assume that any streams "in flight" may have
813 * been processed and are not safe to retry.
814 * As clients with idle connection may only learn about a closed
815 * connection when sending the next request, this has the effect
816 * that at least this one request will fail.
817 */
819 H2_SSSN_LOG(APLOGNO(03199), session,
820 "connection disappeared without proper "
821 "goodbye, clients will be confused, should not happen"));
822 }
823
824 if (!h2_iq_empty(session->ready_to_process)) {
825 int sid;
827 H2_SSSN_LOG(APLOGNO(10485), session,
828 "cleanup, resetting %d streams in ready-to-process"),
829 h2_iq_count(session->ready_to_process));
830 while ((sid = h2_iq_shift(session->ready_to_process)) > 0) {
831 h2_mplx_c1_client_rst(session->mplx, sid, get_stream(session, sid));
832 }
833 }
834
836 h2_mplx_c1_destroy(session->mplx);
837 session->mplx = NULL;
838
839 ap_assert(session->ngh2);
840 nghttp2_session_del(session->ngh2);
841 session->ngh2 = NULL;
843
844 return APR_SUCCESS;
845}
846
848{
849 conn_rec *c = data;
851 h2_session *session = conn_ctx? conn_ctx->session : NULL;
852
853 if (session) {
854 int mpm_state = 0;
855 int level;
856
859 /* if the session is still there, now is the last chance
860 * to perform cleanup. Normally, cleanup should have happened
861 * earlier in the connection pre_close.
862 * However, when the server is stopping, it may shutdown connections
863 * without running the pre_close hooks. Do not want about that. */
864 ap_log_cerror(APLOG_MARK, level, 0, c,
865 H2_SSSN_LOG(APLOGNO(10020), session,
866 "session cleanup triggered by pool cleanup. "
867 "this should have happened earlier already."));
868 return session_cleanup(session, "pool cleanup");
869 }
870 return APR_SUCCESS;
871}
872
873static /* atomic */ apr_uint32_t next_id;
874
877{
878 nghttp2_session_callbacks *callbacks = NULL;
879 nghttp2_option *options = NULL;
880 uint32_t n;
881 int thread_num;
883 h2_session *session;
884 h2_stream *stream0;
886 int rv;
887
888 *psession = NULL;
889 apr_pool_create(&pool, c->pool);
890 apr_pool_tag(pool, "h2_session");
891 session = apr_pcalloc(pool, sizeof(h2_session));
892 if (!session) {
893 return APR_ENOMEM;
894 }
895
896 *psession = session;
897 /* c->id does not give a unique id for the lifetime of the session.
898 * mpms like event change c->id when re-activating a keepalive
899 * connection based on the child_num+thread_num of the worker
900 * processing it.
901 * We'd like to have an id that remains constant and unique bc
902 * h2 streams can live through keepalive periods. While double id
903 * will not lead to processing failures, it will confuse log analysis.
904 */
905#if AP_MODULE_MAGIC_AT_LEAST(20211221, 8)
906 ap_sb_get_child_thread(c->sbh, &session->child_num, &thread_num);
907#else
908 (void)thread_num;
909 session->child_num = (int)getpid();
910#endif
911 session->id = apr_atomic_inc32(&next_id);
912 session->c1 = c;
913 session->r = r;
914 session->s = s;
915 session->pool = pool;
916 session->workers = workers;
917
918 session->state = H2_SESSION_ST_INIT;
919 session->local.accepting = 1;
920 session->remote.accepting = 1;
921
925
926 session->out_c1_blocked = h2_iq_create(session->pool, (int)session->max_stream_count);
927 session->ready_to_process = h2_iq_create(session->pool, (int)session->max_stream_count);
928
929 session->monitor = apr_pcalloc(pool, sizeof(h2_stream_monitor));
930 session->monitor->ctx = session;
933 session->monitor->on_event = on_stream_event;
934
935 stream0 = h2_stream_create(0, session->pool, session, NULL, 0);
936 stream0->c2 = session->c1; /* stream0's connection is the main connection */
937 session->mplx = h2_mplx_c1_create(session->child_num, session->id,
938 stream0, s, session->pool, workers);
939 if (!session->mplx) {
941 return APR_ENOTIMPL;
942 }
943
944 h2_c1_io_init(&session->io, session);
946 if (session->padding_max) {
947 session->padding_max = (0x01 << session->padding_max) - 1;
948 }
950 session->bbtmp = apr_brigade_create(session->pool, c->bucket_alloc);
951
952 status = init_callbacks(c, &callbacks);
953 if (status != APR_SUCCESS) {
955 "nghttp2: error in init_callbacks");
957 return status;
958 }
959
960 rv = nghttp2_option_new(&options);
961 if (rv != 0) {
963 APLOGNO(02928) "nghttp2_option_new: %s",
964 nghttp2_strerror(rv));
966 return status;
967 }
969 /* We need to handle window updates ourself, otherwise we
970 * get flooded by nghttp2. */
972#ifdef H2_NG2_NO_CLOSED_STREAMS
973 /* We do not want nghttp2 to keep information about closed streams as
974 * that accumulates memory on long connections. This makes PRIORITY
975 * setting in relation to older streams non-working. */
977#endif
978#ifdef H2_NG2_RFC9113_STRICTNESS
979 /* nghttp2 v1.50.0 introduces the strictness checks on leading/trailing
980 * whitespace of RFC 9113 for fields. But, by default, it RST streams
981 * carrying such. We do not want that. We want to strip the ws and
982 * handle them, just like the HTTP/1.1 parser does. */
984#endif
985 rv = nghttp2_session_server_new2(&session->ngh2, callbacks,
986 session, options);
988 nghttp2_option_del(options);
989
990 if (rv != 0) {
992 APLOGNO(02929) "nghttp2_session_server_new: %s",
993 nghttp2_strerror(rv));
995 return APR_ENOMEM;
996 }
997
999 session->push_diary = h2_push_diary_create(session->pool, n);
1000
1001 if (APLOGcdebug(c)) {
1003 H2_SSSN_LOG(APLOGNO(03200), session,
1004 "created, max_streams=%d, stream_mem=%d, "
1005 "workers_limit=%d, workers_max=%d, "
1006 "push_diary(type=%d,N=%d), "
1007 "max_data_frame_len=%d"),
1008 (int)session->max_stream_count,
1009 (int)session->max_stream_mem,
1010 session->mplx->processing_limit,
1011 session->mplx->processing_max,
1012 session->push_diary->dtype,
1013 (int)session->push_diary->N,
1014 (int)session->max_data_frame_len);
1015 }
1016
1018
1019 return APR_SUCCESS;
1020}
1021
1023{
1026 size_t slen;
1027 int win_size;
1028
1029 ap_assert(session);
1030 /* Start the conversation by submitting our SETTINGS frame */
1031 *rv = 0;
1032 if (session->r) {
1033 const char *s, *cs;
1035 h2_stream * stream;
1036
1037 /* 'h2c' mode: we should have a 'HTTP2-Settings' header with
1038 * base64 encoded client settings. */
1039 s = apr_table_get(session->r->headers_in, "HTTP2-Settings");
1040 if (!s) {
1042 APLOGNO(02931)
1043 "HTTP2-Settings header missing in request");
1044 return APR_EINVAL;
1045 }
1046 cs = NULL;
1047 dlen = h2_util_base64url_decode(&cs, s, session->pool);
1048
1049 if (APLOGrdebug(session->r)) {
1050 char buffer[128];
1051 h2_util_hex_dump(buffer, 128, (char*)cs, dlen);
1052 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, session->r, APLOGNO(03070)
1053 "upgrading h2c session with HTTP2-Settings: %s -> %s (%d)",
1054 s, buffer, (int)dlen);
1055 }
1056
1057 *rv = nghttp2_session_upgrade(session->ngh2, (uint8_t*)cs, dlen, NULL);
1058 if (*rv != 0) {
1061 APLOGNO(02932) "nghttp2_session_upgrade: %s",
1062 nghttp2_strerror(*rv));
1063 return status;
1064 }
1065
1066 /* Now we need to auto-open stream 1 for the request we got. */
1067 stream = h2_session_open_stream(session, 1, 0);
1068 if (!stream) {
1071 APLOGNO(02933) "open stream 1: %s",
1072 nghttp2_strerror(*rv));
1073 return status;
1074 }
1075
1076 status = h2_stream_set_request_rec(stream, session->r, 1);
1077 if (status != APR_SUCCESS) {
1078 return status;
1079 }
1080 }
1081
1082 slen = 0;
1084 settings[slen].value = (uint32_t)session->max_stream_count;
1085 ++slen;
1089 settings[slen].value = win_size;
1090 ++slen;
1091 }
1092#if H2_USE_WEBSOCKETS
1093 if (h2_config_sgeti(session->s, H2_CONF_WEBSOCKETS)) {
1095 settings[slen].value = 1;
1096 ++slen;
1097 }
1098#endif
1099
1101 H2_SSSN_LOG(APLOGNO(03201), session,
1102 "start, INITIAL_WINDOW_SIZE=%ld, MAX_CONCURRENT_STREAMS=%d"),
1103 (long)win_size, (int)session->max_stream_count);
1105 settings, slen);
1106 if (*rv != 0) {
1109 H2_SSSN_LOG(APLOGNO(02935), session,
1110 "nghttp2_submit_settings: %s"), nghttp2_strerror(*rv));
1111 }
1112 else {
1113 /* use maximum possible value for connection window size. We are only
1114 * interested in per stream flow control. which have the initial window
1115 * size configured above.
1116 * Therefore, for our use, the connection window can only get in the
1117 * way. Example: if we allow 100 streams with a 32KB window each, we
1118 * buffer up to 3.2 MB of data. Unless we do separate connection window
1119 * interim updates, any smaller connection window will lead to blocking
1120 * in DATA flow.
1121 */
1124 if (*rv != 0) {
1127 H2_SSSN_LOG(APLOGNO(02970), session,
1128 "nghttp2_submit_window_update: %s"),
1129 nghttp2_strerror(*rv));
1130 }
1131 }
1132
1133 return status;
1134}
1135
1137 h2_push *push)
1138{
1139 h2_stream *stream;
1140 h2_ngheader *ngh;
1142 int nid = 0;
1143
1144 status = h2_req_create_ngheader(&ngh, is->pool, push->req);
1145 if (status == APR_SUCCESS) {
1147 ngh->nv, ngh->nvlen, NULL);
1148 }
1149 if (status != APR_SUCCESS || nid <= 0) {
1151 H2_STRM_LOG(APLOGNO(03075), is,
1152 "submitting push promise fail: %s"), nghttp2_strerror(nid));
1153 return NULL;
1154 }
1156
1158 H2_STRM_LOG(APLOGNO(03076), is, "SERVER_PUSH %d for %s %s on %d"),
1159 nid, push->req->method, push->req->path, is->id);
1160
1161 stream = h2_session_open_stream(session, nid, is->id);
1162 if (!stream) {
1164 H2_STRM_LOG(APLOGNO(03077), is,
1165 "failed to create stream obj %d"), nid);
1166 /* kill the push_promise */
1169 return NULL;
1170 }
1171
1172 h2_session_set_prio(session, stream, push->priority);
1173 h2_stream_set_request(stream, push->req);
1174 return stream;
1175}
1176
1177static int valid_weight(float f)
1178{
1179 int w = (int)f;
1182}
1183
1185 const h2_priority *prio)
1186{
1189
1190 if (prio == NULL) {
1191 /* we treat this as a NOP */
1192 return APR_SUCCESS;
1193 }
1195 if (!s) {
1197 H2_STRM_MSG(stream, "lookup of nghttp2_stream failed"));
1198 return APR_EINVAL;
1199 }
1200
1202 if (s_parent) {
1204 int id_parent, id_grandpa, w_parent, w;
1205 int rv = 0;
1206 const char *ptype = "AFTER";
1207 h2_dependency dep = prio->dependency;
1208
1211 if (s_grandpa) {
1213 }
1214 else {
1215 /* parent of parent does not exist,
1216 * only possible if parent == root */
1218 }
1219
1220 switch (dep) {
1222 /* PUSHed stream is to be interleaved with initiating stream.
1223 * It is made a sibling of the initiating stream and gets a
1224 * proportional weight [1, MAX_WEIGHT] of the initiaing
1225 * stream weight.
1226 */
1227 ptype = "INTERLEAVED";
1229 w = valid_weight(w_parent * ((float)prio->weight / NGHTTP2_MAX_WEIGHT));
1231 break;
1232
1234 /* PUSHed stream os to be sent BEFORE the initiating stream.
1235 * It gets the same weight as the initiating stream, replaces
1236 * that stream in the dependency tree and has the initiating
1237 * stream as child.
1238 */
1239 ptype = "BEFORE";
1244 if (rv < 0) {
1247 "PUSH BEFORE, weight=%d, depends=%d, returned=%d"),
1248 ps.weight, ps.stream_id, rv);
1249 return APR_EGENERAL;
1250 }
1252 break;
1253
1254 case H2_DEPENDANT_AFTER:
1255 /* The PUSHed stream is to be sent after the initiating stream.
1256 * Give if the specified weight and let it depend on the intiating
1257 * stream.
1258 */
1259 /* fall through, it's the default */
1260 default:
1262 break;
1263 }
1264
1265
1268 H2_STRM_LOG(APLOGNO(03203), stream,
1269 "PUSH %s, weight=%d, depends=%d, returned=%d"),
1270 ptype, ps.weight, ps.stream_id, rv);
1271 status = (rv < 0)? APR_EGENERAL : APR_SUCCESS;
1272 }
1273
1274 return status;
1275}
1276
1278{
1279 /* iff we can and they can and want */
1280 return (session->remote.accepting /* remote GOAWAY received */
1284}
1285
1291
1293{
1294 int ngrv, pending = 0;
1296
1300 "nghttp2_session_send: %d", (int)ngrv);
1301 pending = 1;
1302 if (ngrv != 0 && ngrv != NGHTTP2_ERR_WOULDBLOCK) {
1303 if (nghttp2_is_fatal(ngrv)) {
1306 rv = APR_EGENERAL;
1307 goto cleanup;
1308 }
1309 }
1313 if (rv != APR_SUCCESS)
1314 goto cleanup;
1315 pending = 0;
1316 }
1317 }
1318 if (pending) {
1319 rv = h2_c1_io_pass(&session->io);
1320 }
1321cleanup:
1322 if (rv != APR_SUCCESS) {
1324 }
1325 return rv;
1326}
1327
1331static void on_stream_input(void *ctx, h2_stream *stream)
1332{
1334
1335 ap_assert(stream);
1337 H2_STRM_MSG(stream, "on_input change"));
1339 if (stream->id == 0) {
1340 /* input on primary connection available? read */
1342 }
1343 else {
1345 }
1346}
1347
1351static void on_stream_output(void *ctx, h2_stream *stream)
1352{
1354
1355 ap_assert(stream);
1357 H2_STRM_MSG(stream, "on_output change"));
1358 if (stream->id != 0) {
1361 }
1362}
1363
1364
1365static const char *StateNames[] = {
1366 "INIT", /* H2_SESSION_ST_INIT */
1367 "DONE", /* H2_SESSION_ST_DONE */
1368 "IDLE", /* H2_SESSION_ST_IDLE */
1369 "BUSY", /* H2_SESSION_ST_BUSY */
1370 "WAIT", /* H2_SESSION_ST_WAIT */
1371 "CLEANUP", /* H2_SESSION_ST_CLEANUP */
1372};
1373
1375{
1376 if (state >= (sizeof(StateNames)/sizeof(StateNames[0]))) {
1377 return "unknown";
1378 }
1379 return StateNames[state];
1380}
1381
1382static void transit(h2_session *session, const char *action, h2_session_state nstate)
1383{
1384 int ostate;
1385
1386 if (session->state != nstate) {
1387 ostate = session->state;
1388
1390 H2_SSSN_LOG(APLOGNO(03078), session,
1391 "transit [%s] -- %s --> [%s]"),
1392 h2_session_state_str(ostate), action,
1394
1395 switch (session->state) {
1396 case H2_SESSION_ST_IDLE:
1398 /* on fresh connections, with async mpm, do not return
1399 * to mpm for a second. This gives the first request a better
1400 * chance to arrive (und connection leaving IDLE state).
1401 * If we return to mpm right away, this connection has the
1402 * same chance of being cleaned up by the mpm as connections
1403 * that already served requests - not fair. */
1405 H2_SSSN_LOG("", session, "enter idle"));
1406 }
1407 else {
1408 /* normal keepalive setup */
1410 H2_SSSN_LOG("", session, "enter keepalive"));
1411 }
1412 session->state = nstate;
1413 break;
1414 case H2_SESSION_ST_DONE:
1415 break;
1416 default:
1417 /* nop */
1418 session->state = nstate;
1419 break;
1420 }
1421 }
1422}
1423
1424static void h2_session_ev_init(h2_session *session, int arg, const char *msg)
1425{
1426 switch (session->state) {
1427 case H2_SESSION_ST_INIT:
1429 break;
1430 default:
1431 /* nop */
1432 break;
1433 }
1434}
1435
1436static void h2_session_ev_input_pending(h2_session *session, int arg, const char *msg)
1437{
1438 switch (session->state) {
1439 case H2_SESSION_ST_INIT:
1440 case H2_SESSION_ST_IDLE:
1441 case H2_SESSION_ST_WAIT:
1442 transit(session, "input read", H2_SESSION_ST_BUSY);
1443 break;
1444 default:
1445 break;
1446 }
1447}
1448
1449static void h2_session_ev_input_exhausted(h2_session *session, int arg, const char *msg)
1450{
1451 switch (session->state) {
1452 case H2_SESSION_ST_BUSY:
1454 if (session->open_streams == 0) {
1455 transit(session, "input exhausted, no streams", H2_SESSION_ST_IDLE);
1456 }
1457 else {
1458 transit(session, "input exhausted", H2_SESSION_ST_WAIT);
1459 }
1460 }
1461 break;
1462 case H2_SESSION_ST_WAIT:
1463 if (session->open_streams == 0) {
1464 transit(session, "input exhausted, no streams", H2_SESSION_ST_IDLE);
1465 }
1466 break;
1467 default:
1468 break;
1469 }
1470}
1471
1472static void h2_session_ev_local_goaway(h2_session *session, int arg, const char *msg)
1473{
1475 transit(session, "local goaway", H2_SESSION_ST_DONE);
1476}
1477
1478static void h2_session_ev_remote_goaway(h2_session *session, int arg, const char *msg)
1479{
1480 if (!session->remote.shutdown) {
1483 session->remote.shutdown = 1;
1485 transit(session, "remote goaway", H2_SESSION_ST_DONE);
1486 }
1487}
1488
1489static void h2_session_ev_conn_error(h2_session *session, int arg, const char *msg)
1490{
1491 switch (session->state) {
1492 case H2_SESSION_ST_INIT:
1493 case H2_SESSION_ST_DONE:
1494 /* just leave */
1495 transit(session, "conn error", H2_SESSION_ST_DONE);
1496 break;
1497
1498 default:
1500 H2_SSSN_LOG(APLOGNO(03401), session,
1501 "conn error -> shutdown"));
1503 break;
1504 }
1505}
1506
1507static void h2_session_ev_proto_error(h2_session *session, int arg, const char *msg)
1508{
1509 if (!session->local.shutdown) {
1511 H2_SSSN_LOG(APLOGNO(03402), session,
1512 "proto error -> shutdown"));
1514 }
1515}
1516
1517static void h2_session_ev_conn_timeout(h2_session *session, int arg, const char *msg)
1518{
1520 if (!session->local.shutdown) {
1522 }
1523}
1524
1525static void h2_session_ev_ngh2_done(h2_session *session, int arg, const char *msg)
1526{
1527 switch (session->state) {
1528 case H2_SESSION_ST_DONE:
1529 /* nop */
1530 break;
1531 default:
1532 transit(session, "nghttp2 done", H2_SESSION_ST_DONE);
1533 break;
1534 }
1535}
1536
1537static void h2_session_ev_mpm_stopping(h2_session *session, int arg, const char *msg)
1538{
1539 switch (session->state) {
1540 case H2_SESSION_ST_DONE:
1541 /* nop */
1542 break;
1543 default:
1545#if !AP_MODULE_MAGIC_AT_LEAST(20120211, 110)
1547#endif
1548 break;
1549 }
1550}
1551
1552static void h2_session_ev_pre_close(h2_session *session, int arg, const char *msg)
1553{
1555}
1556
1558{
1560 H2_SSSN_LOG(APLOGNO(10304), session, "no more streams"));
1561 switch (session->state) {
1562 case H2_SESSION_ST_BUSY:
1563 case H2_SESSION_ST_WAIT:
1565 if (session->local.accepting) {
1566 /* We wait for new frames on c1 only. */
1567 transit(session, "all streams done", H2_SESSION_ST_IDLE);
1568 }
1569 else {
1570 /* We are no longer accepting new streams.
1571 * Time to leave. */
1572 h2_session_shutdown(session, 0, "done", 0);
1573 transit(session, "c1 done after goaway", H2_SESSION_ST_DONE);
1574 }
1575 }
1576 else {
1577 transit(session, "no more streams", H2_SESSION_ST_WAIT);
1578 }
1579 break;
1580 default:
1581 /* nop */
1582 break;
1583 }
1584}
1585
1587{
1588 /* nop */
1589}
1590
1592{
1593 if (H2_STREAM_CLIENT_INITIATED(stream->id)) {
1595 if (stream->id > session->remote.emitted_max) {
1596 session->remote.emitted_max = stream->id;
1597 session->local.accepted_max = stream->id;
1598 }
1599 }
1600 else {
1601 if (stream->id > session->local.emitted_max) {
1603 session->remote.emitted_max = stream->id;
1604 }
1605 }
1606 /* Stream state OPEN means we have received all request headers
1607 * and can start processing the stream. */
1609 update_child_status(session, SERVER_BUSY_READ, "schedule", stream);
1610}
1611
1613{
1614 apr_bucket *b;
1615
1616 if (H2_STREAM_CLIENT_INITIATED(stream->id)
1617 && (stream->id > session->local.completed_max)) {
1618 session->local.completed_max = stream->id;
1619 }
1620 /* The stream might have data in the buffers of the main connection.
1621 * We can only free the allocated resources once all had been written.
1622 * Send a special buckets on the connection that gets destroyed when
1623 * all preceding data has been handled. On its destruction, it is safe
1624 * to purge all resources of the stream. */
1626 H2_STRM_MSG(stream, "adding h2_eos to c1 out"));
1631}
1632
1633static void on_stream_state_enter(void *ctx, h2_stream *stream)
1634{
1636
1638 H2_STRM_MSG(stream, "entered state"));
1639 switch (stream->state) {
1640 case H2_SS_IDLE: /* stream was created */
1641 ev_stream_created(session, stream);
1642 break;
1643 case H2_SS_OPEN: /* stream has request headers */
1644 case H2_SS_RSVD_L:
1645 ev_stream_open(session, stream);
1646 break;
1647 case H2_SS_CLOSED_L: /* stream output was closed, but remote end is not */
1648 /* If the stream is still being processed, it could still be reading
1649 * its input (theoretically, http request hangling does not normally).
1650 * But when processing is done, we need to cancel the stream as no
1651 * one is consuming the input any longer.
1652 * This happens, for example, on a large POST when the response
1653 * is ready early due to the POST being denied. */
1654 if (!h2_mplx_c1_stream_is_running(session->mplx, stream)) {
1656 H2_STRM_LOG(APLOGNO(10305), stream, "remote close missing"));
1658 stream->id, H2_ERR_NO_ERROR);
1659 }
1660 break;
1661 case H2_SS_CLOSED_R: /* stream input was closed */
1662 break;
1663 case H2_SS_CLOSED: /* stream in+out were closed */
1664 ev_stream_closed(session, stream);
1665 break;
1666 case H2_SS_CLEANUP:
1671 break;
1672 default:
1673 break;
1674 }
1675}
1676
1678{
1680 switch (ev) {
1683 break;
1686 break;
1687 default:
1688 /* NOP */
1689 break;
1690 }
1691}
1692
1693static void on_stream_state_event(void *ctx, h2_stream *stream,
1695{
1697 switch (ev) {
1698 case H2_SEV_CANCELLED:
1701 stream->id, stream->rst_error);
1702 }
1703 break;
1704 default:
1705 /* NOP */
1706 break;
1707 }
1708}
1709
1711 apr_status_t arg, const char *msg)
1712{
1713 switch (ev) {
1714 case H2_SESSION_EV_INIT:
1716 break;
1719 break;
1722 break;
1725 break;
1728 break;
1731 break;
1734 break;
1737 break;
1740 break;
1743 break;
1746 break;
1749 break;
1750 default:
1752 H2_SSSN_MSG(session, "unknown event %d"), ev);
1753 break;
1754 }
1755}
1756
1758 int sid;
1759
1760 while ((sid = h2_iq_shift(session->out_c1_blocked)) > 0) {
1762 }
1763}
1764
1766{
1768 conn_rec *c = session->c1;
1769 int rv, mpm_state, trace = APLOGctrace3(c);
1770
1771 if (trace) {
1773 H2_SSSN_MSG(session, "process start, async=%d"), async);
1774 }
1775
1781 }
1782 else {
1786 H2_SSSN_LOG(APLOGNO(03079), session,
1787 "started on %s:%d"),
1789 c->local_addr->port);
1790 if (status != APR_SUCCESS) {
1793 }
1794 else {
1796 }
1797 }
1798 }
1799
1800 while (session->state != H2_SESSION_ST_DONE) {
1801
1802 /* PR65731: we may get a new connection to process while the
1803 * MPM already is stopping. For example due to having reached
1804 * MaxRequestsPerChild limit.
1805 * Since this is supposed to handle things gracefully, we need to:
1806 * a) fully initialize the session before GOAWAYing
1807 * b) give the client the chance to submit at least one request
1808 */
1809 if (session->state != H2_SESSION_ST_INIT /* no longer intializing */
1810 && session->local.accepted_max > 0 /* have gotten at least one stream */
1811 && session->local.accepting /* have not already locally shut down */
1813 if (mpm_state == AP_MPMQ_STOPPING) {
1815 }
1816 }
1817
1818 session->status[0] = '\0';
1819
1822 }
1825 }
1826
1831 transit(session, "scheduled stream", H2_SESSION_ST_BUSY);
1832 }
1833
1834 if (session->input_flushed) {
1835 transit(session, "forwarded input", H2_SESSION_ST_BUSY);
1837 }
1838
1841 transit(session, "unblocked output", H2_SESSION_ST_BUSY);
1842 }
1843
1844 if (session->reprioritize) {
1846 session->reprioritize = 0;
1847 }
1848
1851 }
1852
1854 if (APR_SUCCESS != status) {
1856 }
1857
1858 switch (session->state) {
1859 case H2_SESSION_ST_INIT:
1860 ap_assert(0);
1862 break;
1863
1864 case H2_SESSION_ST_IDLE:
1868 /* Give any new incoming request a short grace period to
1869 * arrive while we are still hot and return to the mpm
1870 * connection handling when nothing really happened. */
1873 if (async) {
1875 H2_SSSN_LOG(APLOGNO(10306), session,
1876 "returning to mpm c1 monitoring"));
1877 goto leaving;
1878 }
1879 else {
1880 /* Not an async mpm, we must continue waiting
1881 * for client data to arrive until the configured
1882 * server Timeout/KeepAliveTimeout happens */
1885 session->s->timeout;
1887 H2_SSSN_MSG(session, "polling timeout=%d"),
1888 (int)apr_time_sec(timeout));
1893 if (session->open_streams == 0) {
1896 break;
1897 }
1898 }
1899 else if (APR_SUCCESS != status) {
1902 break;
1903 }
1904 }
1905 }
1906 }
1907 else {
1908 transit(session, "c1 io pending", H2_SESSION_ST_BUSY);
1909 }
1910 break;
1911
1912 case H2_SESSION_ST_BUSY:
1913 /* IO happening in and out. Make sure we react to c2 events
1914 * inbetween send and receive. */
1919 break;
1920 }
1922 break;
1923
1924 case H2_SESSION_ST_WAIT:
1926 if (APR_SUCCESS != status) {
1928 break;
1929 }
1930 if (session->open_streams == 0) {
1932 0, "streams really done");
1934 break;
1935 }
1936 }
1937 /* No IO happening and input is exhausted. Make sure we have
1938 * flushed any possibly pending output and then wait with
1939 * the c1 connection timeout for sth to happen in our c1/c2 sockets/pipes */
1941 H2_SSSN_MSG(session, "polling timeout=%d, open_streams=%d"),
1946 /* If we timeout without streams open, no new request from client
1947 * arrived.
1948 * If we timeout without nghttp2 wanting to write something, but
1949 * all open streams have something to send, it means we are
1950 * blocked on HTTP/2 flow control and the client did not send
1951 * WINDOW_UPDATEs to us. */
1952 if (session->open_streams == 0 ||
1956 break;
1957 }
1958 }
1959 else if (APR_SUCCESS != status) {
1961 break;
1962 }
1963 break;
1964
1965 case H2_SESSION_ST_DONE:
1967 break;
1968
1969 default:
1971 H2_SSSN_LOG(APLOGNO(03080), session,
1972 "unknown state"));
1974 break;
1975 }
1976 }
1977
1978leaving:
1979 if (trace) {
1981 H2_SSSN_MSG(session, "process returns"));
1982 }
1984
1986 if (session->local.error) {
1987 char buffer[128];
1988 const char *msg;
1989 if (session->local.error_msg) {
1990 msg = session->local.error_msg;
1991 }
1992 else {
1993 msg = apr_strerror(session->local.error, buffer, sizeof(buffer));
1994 }
1996 }
1997 else {
1999 }
2000 }
2001 else if (APR_STATUS_IS_EOF(status)
2006 }
2007
2009}
2010
2012{
2014
2016 H2_SSSN_MSG(session, "pre_close"));
2018 (session->state == H2_SESSION_ST_IDLE)? "timeout" : NULL);
2019 status = session_cleanup(session, "pre_close");
2020 if (status == APR_SUCCESS) {
2021 /* no one should hold a reference to this session any longer and
2022 * the h2_conn_ctx_twas removed from the connection.
2023 * Take the pool (and thus all subpools etc. down now, instead of
2024 * during cleanup of main connection pool. */
2026 }
2027 return status;
2028}
Apache Multi-Processing Module library.
int n
Definition ap_regex.h:278
const char apr_size_t len
Definition ap_regex.h:187
#define send
APR Atomic Operations.
APR-UTIL Base64 Encoding.
APR Strings library.
APR Condition Variable Routines.
apr_uint32_t apr_atomic_inc32(volatile apr_uint32_t *mem)
Definition atomic.c:51
const char server_rec server_rec ** ps
request_rec * r
#define APLOGNO(n)
Definition http_log.h:117
#define APLOGrdebug(r)
Definition http_log.h:245
#define APLOGctrace2(c)
Definition http_log.h:258
#define APLOGcdebug(c)
Definition http_log.h:256
#define ap_log_rerror
Definition http_log.h:454
#define APLOG_ERR
Definition http_log.h:67
#define APLOG_TRACE3
Definition http_log.h:74
#define ap_log_cerror
Definition http_log.h:498
#define APLOG_MARK
Definition http_log.h:283
#define APLOG_WARNING
Definition http_log.h:68
#define APLOG_TRACE2
Definition http_log.h:73
#define APLOGctrace3(c)
Definition http_log.h:259
#define APLOG_TRACE1
Definition http_log.h:72
#define APLOG_DEBUG
Definition http_log.h:71
void const char * arg
Definition http_vhost.h:63
#define APR_EGENERAL
Definition apr_errno.h:313
#define APR_EOF
Definition apr_errno.h:461
#define APR_ENOMEM
Definition apr_errno.h:683
#define APR_ENOTIMPL
Definition apr_errno.h:476
#define APR_NOTFOUND
Definition apr_errno.h:463
#define APR_EINVAL
Definition apr_errno.h:711
#define APR_STATUS_IS_ECONNABORTED(s)
Definition apr_errno.h:1304
#define APR_STATUS_IS_ECONNRESET(s)
Definition apr_errno.h:1308
#define APR_STATUS_IS_TIMEUP(s)
Definition apr_errno.h:534
#define APR_STATUS_IS_EAGAIN(s)
Definition apr_errno.h:1272
#define APR_STATUS_IS_EPIPE(s)
Definition apr_errno.h:1319
#define APR_STATUS_IS_EOF(s)
Definition apr_errno.h:567
apr_file_t * f
#define APR_BRIGADE_INSERT_TAIL(b, e)
apr_brigade_flush void * ctx
int apr_off_t * length
apr_pool_t const char apr_dbd_t const char ** error
Definition apr_dbd.h:143
const char apr_ssize_t int flags
Definition apr_encode.h:168
const char apr_ssize_t slen
Definition apr_encode.h:168
#define ap_assert(exp)
Definition httpd.h:2271
apr_uint32_t ap_random_pick(apr_uint32_t min, apr_uint32_t max)
Definition core.c:5485
apr_size_t size
const char int apr_pool_t * pool
Definition apr_cstr.h:84
const char * value
Definition apr_env.h:51
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
void * data
void const char apr_status_t(* cleanup)(void *))
char * buffer
apr_vformatter_buff_t * c
Definition apr_lib.h:175
apr_sockaddr_t apr_sockaddr_t apr_sockaddr_t * source
apr_pool_t * b
Definition apr_pools.h:529
#define apr_pool_create(newpool, parent)
Definition apr_pools.h:322
#define apr_pcalloc(p, size)
Definition apr_pools.h:465
const char * s
Definition apr_strings.h:95
apr_int32_t apr_int32_t apr_int32_t err
int int status
#define apr_time_from_msec(msec)
Definition apr_time.h:75
apr_int64_t apr_time_t
Definition apr_time.h:45
#define apr_time_sec(time)
Definition apr_time.h:63
apr_status_t ap_mpm_query(int query_code, int *result)
Definition mpm_common.c:421
#define AP_MPMQ_MPM_STATE
Definition ap_mpm.h:174
#define AP_MPMQ_STOPPING
Definition ap_mpm.h:142
@ H2_SS_RSVD_L
Definition h2.h:144
@ H2_SS_CLOSED
Definition h2.h:148
@ H2_SS_CLOSED_R
Definition h2.h:146
@ H2_SS_CLOSED_L
Definition h2.h:147
@ H2_SS_IDLE
Definition h2.h:142
@ H2_SS_OPEN
Definition h2.h:145
@ H2_SS_CLEANUP
Definition h2.h:149
#define H2_ERR_NO_ERROR
Definition h2.h:58
#define H2MAX(x, y)
Definition h2.h:100
h2_dependency
Definition h2.h:103
@ H2_DEPENDANT_AFTER
Definition h2.h:104
@ H2_DEPENDANT_INTERLEAVED
Definition h2.h:105
@ H2_DEPENDANT_BEFORE
Definition h2.h:106
#define H2_INITIAL_WINDOW_SIZE
Definition h2.h:94
h2_stream_event_t
Definition h2.h:153
@ H2_SEV_IN_DATA_PENDING
Definition h2.h:159
@ H2_SEV_OUT_C1_BLOCK
Definition h2.h:160
@ H2_SEV_CANCELLED
Definition h2.h:156
#define H2_MAX_PADLEN
Definition h2.h:92
#define H2_STREAM_CLIENT_INITIATED(id)
Definition h2.h:96
#define H2_FRAME_HDR_LEN
Definition h2.h:86
#define H2MIN(x, y)
Definition h2.h:101
h2_session_state
Definition h2.h:121
@ H2_SESSION_ST_INIT
Definition h2.h:122
@ H2_SESSION_ST_IDLE
Definition h2.h:124
@ H2_SESSION_ST_CLEANUP
Definition h2.h:127
@ H2_SESSION_ST_DONE
Definition h2.h:123
@ H2_SESSION_ST_WAIT
Definition h2.h:126
@ H2_SESSION_ST_BUSY
Definition h2.h:125
#define H2_HTTP_STATUS_UNSET
Definition h2.h:190
apr_bucket * h2_bucket_eos_create(apr_bucket_alloc_t *list, h2_stream *stream)
static struct h2_workers * workers
Definition h2_c1.c:48
int h2_c1_io_pending(h2_c1_io *io)
Definition h2_c1_io.c:334
apr_status_t h2_c1_io_pass(h2_c1_io *io)
Definition h2_c1_io.c:339
apr_status_t h2_c1_io_append(h2_c1_io *io, apr_bucket_brigade *bb)
Definition h2_c1_io.c:392
apr_status_t h2_c1_io_add_data(h2_c1_io *io, const char *data, size_t length)
Definition h2_c1_io.c:361
apr_status_t h2_c1_io_init(h2_c1_io *io, h2_session *session)
Definition h2_c1_io.c:141
apr_status_t h2_c1_io_assure_flushed(h2_c1_io *io)
Definition h2_c1_io.c:349
apr_status_t h2_c1_read(h2_session *session)
Definition h2_c1_io.c:518
int h2_c1_io_needs_flush(h2_c1_io *io)
Definition h2_c1_io.c:329
int h2_config_sgeti(server_rec *s, h2_config_var_t var)
Definition h2_config.c:506
@ H2_CONF_PADDING_ALWAYS
Definition h2_config.h:43
@ H2_CONF_PUSH
Definition h2_config.h:38
@ H2_CONF_MAX_DATA_FRAME_LEN
Definition h2_config.h:46
@ H2_CONF_WEBSOCKETS
Definition h2_config.h:48
@ H2_CONF_WIN_SIZE
Definition h2_config.h:28
@ H2_CONF_STREAM_MAX_MEM
Definition h2_config.h:32
@ H2_CONF_MAX_STREAMS
Definition h2_config.h:27
@ H2_CONF_PUSH_DIARY_SIZE
Definition h2_config.h:39
@ H2_CONF_PADDING_BITS
Definition h2_config.h:42
void h2_conn_ctx_detach(conn_rec *c)
Definition h2_conn_ctx.c:37
#define h2_conn_ctx_get(c)
Definition h2_conn_ctx.h:78
int h2_mplx_c1_stream_is_running(h2_mplx *m, h2_stream *stream)
Definition h2_mplx.c:118
apr_status_t h2_mplx_c1_stream_cleanup(h2_mplx *m, h2_stream *stream, unsigned int *pstream_count)
Definition h2_mplx.c:549
apr_status_t h2_mplx_c1_client_rst(h2_mplx *m, int stream_id, h2_stream *stream)
Definition h2_mplx.c:1122
apr_status_t h2_mplx_c1_reprioritize(h2_mplx *m, h2_stream_pri_cmp_fn *cmp, h2_session *session)
Definition h2_mplx.c:643
void h2_mplx_c1_going_keepalive(h2_mplx *m)
Definition h2_mplx.c:605
int h2_mplx_c1_shutdown(h2_mplx *m)
Definition h2_mplx.c:358
void h2_mplx_c1_destroy(h2_mplx *m)
Definition h2_mplx.c:471
h2_mplx * h2_mplx_c1_create(int child_num, apr_uint32_t id, h2_stream *stream0, server_rec *s, apr_pool_t *parent, h2_workers *workers)
Definition h2_mplx.c:258
int h2_mplx_c1_all_streams_want_send_data(h2_mplx *m)
Definition h2_mplx.c:411
apr_status_t h2_mplx_c1_poll(h2_mplx *m, apr_interval_time_t timeout, stream_ev_callback *on_stream_input, stream_ev_callback *on_stream_output, void *on_ctx)
Definition h2_mplx.c:614
apr_status_t h2_mplx_c1_streams_do(h2_mplx *m, h2_mplx_stream_cb *cb, void *ctx)
Definition h2_mplx.c:383
void h2_mplx_c1_process(h2_mplx *m, h2_iqueue *ready_to_process, h2_stream_get_fn *get_stream, h2_stream_pri_cmp_fn *stream_pri_cmp, h2_session *session, unsigned int *pstream_count)
Definition h2_mplx.c:711
int h2_protocol_is_acceptable_c1(conn_rec *c, request_rec *r, int require_all)
const char * h2_protocol_err_description(unsigned int h2_error)
Definition h2_protocol.c:78
static int on_stream_close(nghttp2_session *ngh2, int32_t stream_id, uint32_t error_code, void *user_data)
static int on_header(nghttp2_session *ngh2, const nghttp2_frame *frame, const uint8_t *namearg, size_t nlen, const uint8_t *valuearg, size_t vlen, uint8_t flags, void *user_data)
static int on_frame_recv(nghttp2_session *ngh2, const nghttp2_frame *frame, void *user_data)
h2_push_diary * h2_push_diary_create(apr_pool_t *p, int N)
Definition h2_push.c:585
static void on_stream_event(void *ctx, h2_stream *stream, h2_stream_event_t ev)
static void h2_session_ev_ngh2_done(h2_session *session, int arg, const char *msg)
static void cleanup_unprocessed_streams(h2_session *session)
Definition h2_session.c:107
static apr_status_t init_callbacks(conn_rec *c, nghttp2_session_callbacks **pcb)
Definition h2_session.c:677
static int on_frame_send_cb(nghttp2_session *ngh2, const nghttp2_frame *frame, void *user_data)
Definition h2_session.c:575
static void on_stream_output(void *ctx, h2_stream *stream)
int h2_session_push_enabled(h2_session *session)
static apr_status_t h2_session_shutdown_notice(h2_session *session)
Definition h2_session.c:730
static void unblock_c1_out(h2_session *session)
static void on_stream_input(void *ctx, h2_stream *stream)
static apr_uint32_t next_id
Definition h2_session.c:873
static void on_stream_state_event(void *ctx, h2_stream *stream, h2_stream_event_t ev)
static void h2_session_ev_input_exhausted(h2_session *session, int arg, const char *msg)
static apr_status_t session_pool_cleanup(void *data)
Definition h2_session.c:847
void h2_session_event(h2_session *session, h2_session_event_t ev, int err, const char *msg)
Definition h2_session.c:84
static void h2_session_ev_remote_goaway(h2_session *session, int arg, const char *msg)
apr_status_t h2_session_pre_close(h2_session *session, int async)
static apr_status_t h2_session_send(h2_session *session)
static void h2_session_ev_no_more_streams(h2_session *session)
static h2_stream * h2_session_open_stream(h2_session *session, int stream_id, int initiated_on)
Definition h2_session.c:112
static apr_status_t session_cleanup(h2_session *session, const char *trigger)
Definition h2_session.c:802
const char * h2_session_state_str(h2_session_state state)
static int on_send_data_cb(nghttp2_session *ngh2, nghttp2_frame *frame, const uint8_t *framehd, size_t length, nghttp2_data_source *source, void *userp)
Definition h2_session.c:491
static int h2_session_want_send(h2_session *session)
static int on_stream_close_cb(nghttp2_session *ngh2, int32_t stream_id, uint32_t error_code, void *userp)
Definition h2_session.c:262
apr_status_t h2_session_set_prio(h2_session *session, h2_stream *stream, const h2_priority *prio)
static int rst_unprocessed_stream(h2_stream *stream, void *ctx)
Definition h2_session.c:90
static void h2_session_ev_local_goaway(h2_session *session, int arg, const char *msg)
static int on_frame_recv_cb(nghttp2_session *ng2s, const nghttp2_frame *frame, void *userp)
Definition h2_session.c:339
apr_status_t h2_session_process(h2_session *session, int async)
static void update_child_status(h2_session *session, int status, const char *msg, const h2_stream *stream)
Definition h2_session.c:703
static void ev_stream_closed(h2_session *session, h2_stream *stream)
static void h2_session_ev_conn_error(h2_session *session, int arg, const char *msg)
static void h2_session_ev_pre_close(h2_session *session, int arg, const char *msg)
static void transit(h2_session *session, const char *action, h2_session_state nstate)
static int stream_pri_cmp(int sid1, int sid2, void *ctx)
Definition h2_session.c:162
static int h2_session_status_from_apr_status(apr_status_t rv)
Definition h2_session.c:65
static int on_data_chunk_recv_cb(nghttp2_session *ngh2, uint8_t flags, int32_t stream_id, const uint8_t *data, size_t len, void *userp)
Definition h2_session.c:232
static void ev_stream_created(h2_session *session, h2_stream *stream)
static int on_begin_headers_cb(nghttp2_session *ngh2, const nghttp2_frame *frame, void *userp)
Definition h2_session.c:282
apr_status_t h2_session_create(h2_session **psession, conn_rec *c, request_rec *r, server_rec *s, h2_workers *workers)
Definition h2_session.c:875
static const char * StateNames[]
static void h2_session_ev_init(h2_session *session, int arg, const char *msg)
void h2_session_dispatch_event(h2_session *session, h2_session_event_t ev, apr_status_t arg, const char *msg)
static void h2_session_ev_proto_error(h2_session *session, int arg, const char *msg)
static apr_status_t h2_session_shutdown(h2_session *session, int error, const char *msg, int force_close)
Definition h2_session.c:750
static ssize_t select_padding_cb(nghttp2_session *ngh2, const nghttp2_frame *frame, size_t max_payloadlen, void *user_data)
Definition h2_session.c:643
static void on_stream_state_enter(void *ctx, h2_stream *stream)
static void ev_stream_open(h2_session *session, h2_stream *stream)
static h2_stream * get_stream(h2_session *session, int stream_id)
Definition h2_session.c:79
static apr_status_t h2_session_start(h2_session *session, int *rv)
static int spri_cmp(int sid1, nghttp2_stream *s1, int sid2, nghttp2_stream *s2, h2_session *session)
Definition h2_session.c:136
static int valid_weight(float f)
static void h2_session_ev_conn_timeout(h2_session *session, int arg, const char *msg)
static void h2_session_ev_mpm_stopping(h2_session *session, int arg, const char *msg)
static ssize_t send_cb(nghttp2_session *ngh2, const uint8_t *data, size_t length, int flags, void *userp)
Definition h2_session.c:185
static int on_invalid_frame_recv_cb(nghttp2_session *ngh2, const nghttp2_frame *frame, int error, void *userp)
Definition h2_session.c:212
#define NGH2_SET_CALLBACK(callbacks, name, fn)
Definition h2_session.c:674
struct h2_stream * h2_session_push(h2_session *session, h2_stream *is, h2_push *push)
static void h2_session_ev_input_pending(h2_session *session, int arg, const char *msg)
static char immortal_zeros[256]
Definition h2_session.c:489
static int on_header_cb(nghttp2_session *ngh2, const nghttp2_frame *frame, const uint8_t *name, size_t namelen, const uint8_t *value, size_t valuelen, uint8_t flags, void *userp)
Definition h2_session.c:301
#define H2_SSSN_LOG(aplogno, s, msg)
Definition h2_session.h:201
h2_session_event_t
Definition h2_session.h:49
@ H2_SESSION_EV_PRE_CLOSE
Definition h2_session.h:60
@ H2_SESSION_EV_NGH2_DONE
Definition h2_session.h:58
@ H2_SESSION_EV_INIT
Definition h2_session.h:50
@ H2_SESSION_EV_PROTO_ERROR
Definition h2_session.h:56
@ H2_SESSION_EV_INPUT_EXHAUSTED
Definition h2_session.h:52
@ H2_SESSION_EV_INPUT_PENDING
Definition h2_session.h:51
@ H2_SESSION_EV_MPM_STOPPING
Definition h2_session.h:59
@ H2_SESSION_EV_CONN_TIMEOUT
Definition h2_session.h:57
@ H2_SESSION_EV_LOCAL_GOAWAY
Definition h2_session.h:53
@ H2_SESSION_EV_CONN_ERROR
Definition h2_session.h:55
@ H2_SESSION_EV_NO_MORE_STREAMS
Definition h2_session.h:61
@ H2_SESSION_EV_REMOTE_GOAWAY
Definition h2_session.h:54
#define H2_SSSN_MSG(s, msg)
Definition h2_session.h:196
#define H2_SSSN_STRM_MSG(s, stream_id, msg)
Definition h2_session.h:203
apr_status_t h2_stream_add_header(h2_stream *stream, const char *name, size_t nlen, const char *value, size_t vlen)
Definition h2_stream.c:730
apr_status_t h2_stream_set_request_rec(h2_stream *stream, request_rec *r, int eos)
Definition h2_stream.c:650
void h2_stream_set_request(h2_stream *stream, const h2_request *r)
Definition h2_stream.c:676
h2_stream * h2_stream_create(int id, apr_pool_t *pool, h2_session *session, h2_stream_monitor *monitor, int initiated_on)
Definition h2_stream.c:582
apr_status_t h2_stream_recv_DATA(h2_stream *stream, uint8_t flags, const uint8_t *data, size_t len)
Definition h2_stream.c:529
apr_status_t h2_stream_send_frame(h2_stream *stream, int ftype, int flags, size_t frame_len)
Definition h2_stream.c:425
void h2_stream_on_output_change(h2_stream *stream)
Definition h2_stream.c:1763
void h2_stream_rst(h2_stream *stream, int error_code)
Definition h2_stream.c:638
int h2_stream_is_at_or_past(const h2_stream *stream, h2_stream_state_t state)
Definition h2_stream.c:1282
void h2_stream_on_input_change(h2_stream *stream)
Definition h2_stream.c:1817
static int on_frame_send(h2_stream_state_t state, int frame_type)
Definition h2_stream.c:157
apr_status_t h2_stream_read_to(h2_stream *stream, apr_bucket_brigade *bb, apr_off_t *plen, int *peos)
Definition h2_stream.c:1112
apr_status_t h2_stream_recv_frame(h2_stream *stream, int ftype, int flags, size_t frame_len)
Definition h2_stream.c:475
#define H2_STRM_MSG(s, msg)
Definition h2_stream.h:338
#define H2_STRM_LOG(aplogno, s, msg)
Definition h2_stream.h:342
size_t h2_util_hex_dump(char *buffer, size_t maxlen, const char *data, size_t datalen)
Definition h2_util.c:64
h2_iqueue * h2_iq_create(apr_pool_t *pool, int capacity)
Definition h2_util.c:334
int h2_iq_empty(h2_iqueue *q)
Definition h2_util.c:343
int h2_iq_append(h2_iqueue *q, int sid)
Definition h2_util.c:375
int h2_util_frame_print(const nghttp2_frame *frame, char *buffer, size_t maxlen)
Definition h2_util.c:1769
apr_status_t h2_req_create_ngheader(h2_ngheader **ph, apr_pool_t *p, const struct h2_request *req)
Definition h2_util.c:1566
apr_size_t h2_util_base64url_decode(const char **decoded, const char *encoded, apr_pool_t *pool)
Definition h2_util.c:133
int h2_iq_shift(h2_iqueue *q)
Definition h2_util.c:433
int h2_iq_count(h2_iqueue *q)
Definition h2_util.c:348
Apache Configuration.
CORE HTTP Daemon.
Apache Logging library.
HTTP protocol handling.
HTTP Daemon routines.
static const char * trace
static apr_status_t send_data(proxy_conn_rec *conn, struct iovec *vec, int nvec, apr_size_t *len)
return NULL
Definition mod_so.c:359
Multi-Processing Modules functions.
static int mpm_state
Apache scoreboard library.
#define SERVER_CLOSING
Definition scoreboard.h:64
#define SERVER_BUSY_WRITE
Definition scoreboard.h:60
#define SERVER_BUSY_READ
Definition scoreboard.h:59
int ap_update_child_status_from_server(ap_sb_handle_t *sbh, int status, conn_rec *c, server_rec *s)
Definition scoreboard.c:613
int ap_update_child_status_descr(ap_sb_handle_t *sbh, int status, const char *descr)
Definition scoreboard.c:623
char * name
int nid
Structure to store things which are per connection.
Definition httpd.h:1152
struct apr_bucket_alloc_t * bucket_alloc
Definition httpd.h:1201
unsigned aborted
Definition httpd.h:1219
void * sbh
Definition httpd.h:1199
long id
Definition httpd.h:1187
apr_size_t write_size
Definition h2_c1_io.h:38
apr_uint32_t processing_limit
Definition h2_mplx.h:82
apr_uint32_t processing_max
Definition h2_mplx.h:83
nghttp2_nv * nv
Definition h2_util.h:380
apr_size_t nvlen
Definition h2_util.h:381
h2_push_digest_type dtype
Definition h2_push.h:89
const char * method
Definition h2.h:170
int http_status
Definition h2.h:179
const char * path
Definition h2.h:173
unsigned int shutdown
Definition h2.h:138
unsigned int accepting
Definition h2.h:137
int emitted_max
Definition h2.h:134
const char * error_msg
Definition h2.h:136
int completed_max
Definition h2.h:132
int emitted_count
Definition h2.h:133
int accepted_max
Definition h2.h:131
apr_bucket_brigade * bbtmp
Definition h2_session.h:111
unsigned int pushes_submitted
Definition h2_session.h:98
struct h2_workers * workers
Definition h2_session.h:73
struct h2_push_diary * push_diary
Definition h2_session.h:89
apr_uint32_t id
Definition h2_session.h:66
unsigned int reprioritize
Definition h2_session.h:85
struct h2_iqueue * out_c1_blocked
Definition h2_session.h:118
apr_size_t idle_frames
Definition h2_session.h:108
unsigned int padding_max
Definition h2_session.h:76
apr_size_t frames_received
Definition h2_session.h:101
h2_c1_io io
Definition h2_session.h:75
unsigned int streams_done
Definition h2_session.h:94
int child_num
Definition h2_session.h:65
apr_size_t frames_sent
Definition h2_session.h:102
apr_size_t max_data_frame_len
Definition h2_session.h:106
apr_size_t max_stream_count
Definition h2_session.h:104
struct h2_mplx * mplx
Definition h2_session.h:72
h2_session_props remote
Definition h2_session.h:83
unsigned int pushes_promised
Definition h2_session.h:97
int last_status_code
Definition h2_session.h:114
conn_rec * c1
Definition h2_session.h:67
unsigned int open_streams
Definition h2_session.h:92
struct h2_stream_monitor * monitor
Definition h2_session.h:91
char status[64]
Definition h2_session.h:113
const char * last_status_msg
Definition h2_session.h:115
struct h2_iqueue * ready_to_process
Definition h2_session.h:119
request_rec * r
Definition h2_session.h:68
h2_session_state state
Definition h2_session.h:80
apr_size_t max_stream_mem
Definition h2_session.h:105
h2_session_props local
Definition h2_session.h:82
int input_flushed
Definition h2_session.h:117
unsigned int pushes_reset
Definition h2_session.h:99
apr_interval_time_t idle_delay
Definition h2_session.h:109
server_rec * s
Definition h2_session.h:70
struct nghttp2_session * ngh2
Definition h2_session.h:78
int padding_always
Definition h2_session.h:77
unsigned int streams_reset
Definition h2_session.h:96
apr_pool_t * pool
Definition h2_session.h:71
h2_stream_state_cb * on_state_enter
Definition h2_stream.h:57
h2_stream_event_cb * on_state_event
Definition h2_stream.h:60
h2_stream_event_cb * on_event
Definition h2_stream.h:62
conn_rec * c2
Definition h2_stream.h:118
struct h2_request * rtmp
Definition h2_stream.h:91
int rst_error
Definition h2_stream.h:110
int request_headers_failed
Definition h2_stream.h:94
h2_stream_state_t state
Definition h2_stream.h:86
apr_off_t out_data_octets
Definition h2_stream.h:124
int initiated_on
Definition h2_stream.h:83
apr_off_t out_data_frames
Definition h2_stream.h:123
const struct h2_request * request
Definition h2_stream.h:90
struct h2_session * session
Definition h2_stream.h:85
A structure that represents the current request.
Definition httpd.h:845
apr_table_t * headers_in
Definition httpd.h:976
A structure to store information for each virtual server.
Definition httpd.h:1322
apr_interval_time_t timeout
Definition httpd.h:1372
apr_interval_time_t keep_alive_timeout
Definition httpd.h:1374
char * server_hostname
Definition httpd.h:1365
IN ULONG IN INT timeout
typedef int(WSAAPI *apr_winapi_fpt_WSAPoll)(IN OUT LPWSAPOLLFD fdArray