1 /** @file
2  *
3  *  A brief file description
4  *
5  *  @section license License
6  *
7  *  Licensed to the Apache Software Foundation (ASF) under one
8  *  or more contributor license agreements.  See the NOTICE file
9  *  distributed with this work for additional information
10  *  regarding copyright ownership.  The ASF licenses this file
11  *  to you under the Apache License, Version 2.0 (the
12  *  "License"); you may not use this file except in compliance
13  *  with the License.  You may obtain a copy of the License at
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
17  *  Unless required by applicable law or agreed to in writing, software
18  *  distributed under the License is distributed on an "AS IS" BASIS,
19  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  *  See the License for the specific language governing permissions and
21  *  limitations under the License.
22  */
23 
24 #include "Http3FrameCollector.h"
25 
26 #include "Http3DebugNames.h"
27 
28 Http3ErrorUPtr
on_write_ready(QUICStreamIO * stream_io,size_t & nwritten)29 Http3FrameCollector::on_write_ready(QUICStreamIO *stream_io, size_t &nwritten)
30 {
31   bool all_done = true;
32   uint8_t tmp[32768];
33   nwritten = 0;
34 
35   for (auto g : this->_generators) {
36     if (g->is_done()) {
37       continue;
38     }
39     size_t len           = 0;
40     Http3FrameUPtr frame = g->generate_frame(sizeof(tmp) - nwritten);
41     if (frame) {
42       frame->store(tmp + nwritten, &len);
43       nwritten += len;
44 
45       Debug("http3", "[TX] [%d] | %s size=%zu", stream_io->stream_id(), Http3DebugNames::frame_type(frame->type()), len);
46     }
47 
48     all_done &= g->is_done();
49   }
50 
51   if (nwritten) {
52     int64_t len = stream_io->write(tmp, nwritten);
53     ink_assert(len > 0 && (uint64_t)len == nwritten);
54   }
55 
56   if (all_done) {
57     stream_io->write_done();
58   }
59 
60   return Http3ErrorUPtr(new Http3NoError());
61 }
62 
63 void
add_generator(Http3FrameGenerator * generator)64 Http3FrameCollector::add_generator(Http3FrameGenerator *generator)
65 {
66   this->_generators.push_back(generator);
67 }
68