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 "Http3Frame.h"
25 #include "Http3DataFramer.h"
26 #include "Http3Transaction.h"
27 
Http3DataFramer(Http3Transaction * transaction,VIO * source)28 Http3DataFramer::Http3DataFramer(Http3Transaction *transaction, VIO *source) : _transaction(transaction), _source_vio(source) {}
29 
30 Http3FrameUPtr
generate_frame(uint16_t max_size)31 Http3DataFramer::generate_frame(uint16_t max_size)
32 {
33   if (!this->_transaction->is_response_header_sent()) {
34     return Http3FrameFactory::create_null_frame();
35   }
36 
37   Http3FrameUPtr frame   = Http3FrameFactory::create_null_frame();
38   IOBufferReader *reader = this->_source_vio->get_reader();
39 
40   if (max_size <= Http3Frame::MAX_FRAM_HEADER_OVERHEAD) {
41     return frame;
42   }
43 
44   size_t payload_len = max_size - Http3Frame::MAX_FRAM_HEADER_OVERHEAD;
45   if (!reader->is_read_avail_more_than(payload_len)) {
46     payload_len = reader->read_avail();
47   }
48 
49   if (payload_len) {
50     frame = Http3FrameFactory::create_data_frame(reader, payload_len);
51     this->_source_vio->ndone += payload_len;
52   }
53 
54   return frame;
55 }
56 
57 bool
is_done() const58 Http3DataFramer::is_done() const
59 {
60   return this->_source_vio->ntodo() == 0;
61 }
62