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 #pragma once
25 
26 #include <map>
27 #include <queue>
28 
29 #include "QUICTypes.h"
30 #include "QUICFrame.h"
31 #include "QUICTransferProgressProvider.h"
32 
33 class QUICIncomingFrameBuffer
34 {
35 public:
36   ~QUICIncomingFrameBuffer();
37   virtual const QUICFrame *pop()                                 = 0;
38   virtual QUICConnectionErrorUPtr insert(const QUICFrame *frame) = 0;
39   virtual void clear();
40   virtual bool empty();
41 
42 protected:
43   QUICOffset _recv_offset = 0;
44 
45   std::queue<const QUICFrame *> _recv_buffer;
46   std::map<QUICOffset, const QUICFrame *> _out_of_order_queue;
47 };
48 
49 class QUICIncomingStreamFrameBuffer : public QUICIncomingFrameBuffer, public QUICTransferProgressProvider
50 {
51 public:
52   using super = QUICIncomingFrameBuffer; ///< Parent type.
53 
QUICIncomingStreamFrameBuffer()54   QUICIncomingStreamFrameBuffer() {}
55   ~QUICIncomingStreamFrameBuffer();
56 
57   const QUICFrame *pop() override;
58   QUICConnectionErrorUPtr insert(const QUICFrame *frame) override;
59   void clear() override;
60 
61   // QUICTransferProgressProvider
62   bool is_transfer_goal_set() const override;
63   uint64_t transfer_progress() const override;
64   uint64_t transfer_goal() const override;
65   bool is_cancelled() const override;
66 
67 private:
68   QUICConnectionErrorUPtr _check_and_set_fin_flag(QUICOffset offset, size_t len = 0, bool fin_flag = false);
69 
70   QUICOffset _max_offset = 0;
71   QUICOffset _fin_offset = UINT64_MAX;
72 };
73 
74 class QUICIncomingCryptoFrameBuffer : public QUICIncomingFrameBuffer
75 {
76 public:
77   using super = QUICIncomingFrameBuffer; ///< Parent type.
78 
QUICIncomingCryptoFrameBuffer()79   QUICIncomingCryptoFrameBuffer() {}
80   ~QUICIncomingCryptoFrameBuffer();
81 
82   const QUICFrame *pop() override;
83   QUICConnectionErrorUPtr insert(const QUICFrame *frame) override;
84 
85 private:
86 };
87